I am trying to make a LED blink 10 times when I press a button then stop until I press the button again. Could someone assist me with how to write this in code?
I am currently using the loop() procedure with the delay function from the beginners page.
Working from the cookbook on page 38 there is a method called: void blink 2
And then the count function.
// blink an LED the number of times given in the count parameter
void blink2(int count)
{
while(count > 0 ) // repeat until count is no longer greater than zero
{
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
count = count -1; // decrement count
}
}
I am getting errors on this piece of simple code, so I think my guess is the count function isn't compatible with Arduino 1 right ?
core.a(main.cpp.o): In function `main':
\Arduino1\arduino-1.0\hardware\arduino\cores\arduino/main.cpp:11: undefined reference to `setup'
\Arduino1\arduino-1.0\hardware\arduino\cores\arduino/main.cpp:14: undefined reference to `loop
Is there somewhere a list where I can find compatible problems with Arduino 1.0 ? (can't seem to find it on the website)
techdutchy:
I am getting errors on this piece of simple code, so I think my guess is the count function isn't compatible with Arduino 1 right ?
That would be a completely wrong guess.
Is that the entire code you are trying to compile? If not, please post the entire thing. If so, the compiler is quite obviously telling you that there is no void setup() or void loop() ...
I am still getting an error on the following code:
void setup() {
pinMode(13, OUTPUT);
}
void blink2 (int count)
{
while (count > 0)
{
void loop ()
{
digitalWrite(13, HIGH); // set the LED on
delay(13); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(13); // wait for a second
count= count -1;
}
}
The following code compiles however the loop does not stop at 10
void setup(){
pinMode(13,OUTPUT);
}
void loop()
{
for (int x = 0; x < 10; x++) {
digitalWrite(13, HIGH); // set the LED on
delay(13); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(13); // wa
}
}
mobman:
The following code compiles however the loop does not stop at 10
void setup(){
pinMode(13,OUTPUT);
}
void loop()
{
for (int x = 0; x < 10; x++) {
digitalWrite(13, HIGH); // set the LED on
delay(13); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(13); // wa
}
}
Remember that the loop() function is called again and again. Your own for loop will end after ten times, but then it will start over at the beginning again. Setup only runs once, so you can put the loop in there.
void setup() {
pinMode(13, OUTPUT);
}
void loop()
// blink an LED the number of times given in the count parameter
{
void blink2(int count)
while(count > 0 ) // repeat until count is no longer greater than zero
{
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
count = count -1; // decrement count
}
}
I smuggled in a set up() and a loopvoid () Like you can see in the copied code, but then it is whining about:
sketch_jan03f.cpp: In function 'void loop()':
sketch_jan03f:15: error: expected initializer before 'while'
I don't know what initializer is can't find a single thing about it in the reference guide.
Placed a million brackets on a billion places, swapped the void blink, placed it everywhere I could, before setup, in the setup in the place of void loop, sigh nothing works.
The code of lloyddean works, so thank you for that very much!
But I still have restless sleeps over why the frigging code from the Arduino cookbook doesn't work. (page 38)
And thx to the succes of mobman, I never felt so dumb before
Great job mobman btw,
And in other cases I get a count is not declared yet, which make perfect sense if you ask me. But how to declare it ?
Maybe I should just give it a rest. This piece of code.
One of the things to note is that the Arduino starts by running your code in 'setup'. Once 'setup' is done 'loop' runs thru whatever code is present until it runs out of code and then exits and then is called again over and over and over and ...
I am sorry to interrupt gentlements... when I program a code, what ever is in C++, Arduino, Processing, Java, Java ME, Pascal, C, BASIC, Assembly... I always do a "standard" of coding ( structures wise ) for each of the language that I am learning. In that way, it is less confusing.
Libraries to include
my variables
void setup()
{
// my setup code
}
void loop()
{
// my main program who is looping, looping, looping...
}
void my function_one()
{
// my function one
}
void function_two()
{
// my function two
}
// the rest of the functions goes under this line