Hey there,
i just started playing around with an arduino uno. I gathered some programming experience in school und university and i felt quite good programming the first "real" project.
I tried to translate my name into morse-code and a flashing led, but something went wrong.
void blink_dot(){
digitalWrite(led, HIGH);
delay(500); // Led turns on 500ms
digitalWrite(led, LOW);
delay(500);
}
These functions do work, but i tried to cut down on code and did something like this:
void d_Morse(){
blink_strichstrich; // evaluating a pointer to the function code and then ignore it
blink_dot; // evaluating a pointer to the function code and ignoring it
// perhaps you meant to call the functions?
blink_strichstrich () ;
blink_dot () ;
}
First, try to write your code so the words per minute can be changed easily. If you want to change the code speed, change the DOTDELAY value and everything else gets changed automatically since all timings are based on that value...simply change and recompile.
Second, writing a function for each letter is the hard way to do it. For a much easier way to do it, look at post #6:
blutt:
Thanks at MarkT! I thought i oversaw something stupid.. now it works Thanks!
@econjack Thanks aswell to you for your answer, but it's a task for university and it only wants us to spell our own name
But i try to use ur input aswell to improve my code further
You did not do anything stupid, the Arduino IDE concept of NOT requiring function prototypes for sake of "not confusing beginners " strike again!
The hidden function prototype was declared wrong - it does no matter how wrong , so the compiler had no means to check your incorrect syntax - missing ( ) after the function name und before ;
If you declare function by yourself - void MySignature(void); the compiler will flag your incorrect usage / syntax as error.
This is one of the good reasons function prototypes concept was adopted and one should NOT relay on Arduino IDE to write the functions prototypes for you.
julyjim:
You did not do anything stupid, the Arduino IDE concept of NOT requiring function prototypes for sake of "not confusing beginners " strike again!
The hidden function prototype was declared wrong - it does no matter how wrong , so the compiler had no means to check your incorrect syntax - missing ( ) after the function name und before ;
If you declare function by yourself - void MySignature(void); the compiler will flag your incorrect usage / syntax as error.
Hmm, I tried the below in both the Arduino IDE and VS2012/C++. Both seem to be very happy when compiling.
sterretje:
Hmm, I tried the below in both the Arduino IDE and VS2012/C++. Both seem to be very happy when compiling.
void doSomething()
{
}
void setup()
{
doSomething;
}
void loop()
{
}
There is nothing syntactically wrong with that code, so it will not give a compile error. It simply won't do what the OP wanted - the function is NOT called. a bare function name resolves to a pointer to the function, but nothing is done with that pointer, so that line of code is simply optimized away.
There is also nothing syntactically wrong with this code, it just doesn't do anything useful:
julyjim:
You did not do anything stupid, the Arduino IDE concept of NOT requiring function prototypes for sake of "not confusing beginners " strike again!
The hidden function prototype was declared wrong - it does no matter how wrong , so the compiler had no means to check your incorrect syntax - missing ( ) after the function name und before ;
If you declare function by yourself - void MySignature(void); the compiler will flag your incorrect usage / syntax as error.
This is one of the good reasons function prototypes concept was adopted and one should NOT relay on Arduino IDE to write the functions prototypes for you.
Jim .... ..
How does that quote go?
Something about speaking out, and removing any doubt?