vel[1] // and this call the name f the function on the array in this case vel_2
i found this 6 months ago but i can t find it again T.T how the hell i can convert "vel[1]" to "vel_2" i remember is like "this.vel[1]" but i get an error
flash5.cpp: In function 'void loop()':
flash5:26: error: invalid use of 'this' in non-member function
you need to make an array of pointers to functions, rather than an array of function names (after all, function names are never seen by the actual cpu)
mmm i understand what u are saying, but i do this in a easy way like "this is a function" i whant to convert/declare this string is the nam of a function, i can do it like you say, but that is unpractical and i do this, because i whant to do something like this
void loop(){
digitalWrite(ledPin[0], LOW);
digitalWrite(ledPin[1], LOW);
(Something that convert the next value of the array into function name).vel[Phase]();
}
where Phase is a number betewn 0 and 5, and it change if i pres a buttom
if i put in the sketch "vel_1" (this is the name of the function) all work great but how i can convert the value of the array (that is a string) in to fuction? xD
this is a comand or something in action scrip is this.[string] or something like that and in C i something similar that is what i whant xD
fenix8k:
mmm i understand what u are saying, but i do this in a easy way like "this is a function" i whant to convert/declare this string is the nam of a function, i can do it like you say, but that is unpractical and i do this, because i whant to do something like this
The microcontroller has no idea was val_1 is, so if you want to make a link between val_1() and "val_1", you need to use a function pointer.
i kanw The microcontroller has no idea was vel_1 (vel_1 is the actual name of a fucntion :p) is, but i whant to tell him that the next chars are the name of a function, like This is the name of a function.(chars)
i do whant i saying 6 months ago but i can t remember the exact way to do it, and arduino is saying me that i mystake something when i put in the sketch "this.vel[0]" someone can put a link or something of how to use "this." i can t fin it in google T.T
OP is there a section in the International part of the forum that can help?
It's fairly clear English is not your first language, and there may be a better way of posing the question.
When the compiler gets done with your code, the name vel_1 of the function vel_1() no longer exists. If you want to receive a string over the serial port, and call the function at the address that corresponds to the name, you have to do something like this:
char funName[80];
int index;
// populate funName from serial data
if(strcmp(funName, "vel_1") == 0)
{
vel_1();
}
else if(strcmp(funName, "vel_2") == 0)
{
vel_2();
}
fenix8k:
i found this 6 months ago but i can t find it again T.T how the hell i can convert "vel[1]" to "vel_2" i remember is like "this.vel[1]" but i get an error
There are some scripting languages that look similar to 'C' which support this, but 'C' doesn't. The only solution would involve writing your own look-up table or hard-coded string comparisons to decide which function to call based on the content of a variable.
It might help if you could describe what your sketch is supposed to do - there may well be ways to do it that can avoid your need for an array of function pointers entirely.
wildbill:
It might help if you could describe what your sketch is supposed to do - there may well be ways to do it that can avoid your need for an array of function pointers entirely.
Hi, the purpose of my sketch is with 3 buttons control the Blink speed of a led, second buttom change the current led to blink and the last buttom turn of and of the leds without stoping the blink function
i make the sketch and it works great but i have very litle space to code and i whant to make the code as small as possible.
i think another solution to calls functions in the whay i whant
i can use
if (state == 0) {
function_1();
}
if (statae == 1) {
function_2();
}
Ths for help me
sorry for my spelling i m at work and my keyboard work pretty bad xD and English is not my native language