Lookup Table creation on Mbed Studio

Hi

Could you please advise as to how I write a lookup table for the below code ;

#include “mbed.h”

AnalogIn Wind_vane(PA_1);
float Vane_ain,Vane_angle;
Ticker Vane_Interrupt;

float Wind_vane= {0.0, 33000}, {22.5, 6570}, {45.0, 8200}, {67.5, 891},
{90.0, 1000}, {112.5, 688}, {135.0, 2200}, {157.5, 1410},
{180.0, 3900}, {202.5, 3140}, {225.0, 16000}, {247.5, 14120},
{270.0, 120000}, {292.5, 42120}, {315.0, 64900}, {337.5, 21880} ;

void Vane_Interrupt_handler()
{
Vane_ain=Wind_vane;
float old_Vane_ain=0;
if(Vane_ain!=old_Vane_ain );
{Vane_angle}

int main ()
{
old_Vane_ain=0;
Vane_Interrupt.attach(&Vane_Interrupt_handler,2.0);

while(1) { 
 		ThisThread::sleep_for(500ms);
	printf("Wind Direction is %4.2f\n",Vane_angle);
    }

}

Regards

Hello,

Your example code does not make sense. You can not have two objects with same name - Wind_vane.
You probably want to use 2D array - Multidimensional Arrays in C / C++ - GeeksforGeeks

float sWind_vane[][2]= {{0.0, 33000}, {22.5, 6570}, {45.0, 8200}, {67.5, 891},
{90.0, 1000}, {112.5, 688}, {135.0, 2200}, {157.5, 1410},
{180.0, 3900}, {202.5, 3140}, {225.0, 16000}, {247.5, 14120},
{270.0, 120000}, {292.5, 42120}, {315.0, 64900}, {337.5, 21880}};

Or you can use Map container from STD library as lookup table - map - C++ Reference (cplusplus.com)

I don’t mean it badly, but how I wrote in another topic you do not understand basics. This does not have nothing together with the Mbed or the Mbed Studio and so on. You need a simple C++ tutorial like this one for example - C++ Tutorial, it will be easier for you.

BR, Jan

1 Like