Offline
Newbie
Karma: 0
Posts: 5
|
 |
« on: March 03, 2013, 03:48:49 pm » |
There is someone who knows where is the mistake. This is an arduino windows, the blink program modifyed to make only 100 bilnks. Thanks you very much. Gives an Blink 19 error: expected unqualified-id before 'while'
int led = 13; int i = 0; // the setup routine runs once when you press reset: void setup() { // initialize the digital pin as an output. pinMode(led, OUTPUT); }
// the loop routine runs over and over again forever: void while(i<100) { digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(led, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second if (i>9) break; i++; }
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #1 on: March 03, 2013, 03:50:27 pm » |
while is not a function, so should not be qualified with void, but you do need a function called "loop()"
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 5
|
 |
« Reply #2 on: March 03, 2013, 03:52:13 pm » |
but I tryed with while without void and it does the same error.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #3 on: March 03, 2013, 03:54:13 pm » |
That's because you didn't have a "void loop()" in front.. You can't have executable code that is not inside a function.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Poole, Dorset, UK
Offline
God Member
Karma: 8
Posts: 672
|
 |
« Reply #4 on: March 03, 2013, 03:54:45 pm » |
Because you need loop()
Mark
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 5
|
 |
« Reply #5 on: March 03, 2013, 03:56:18 pm » |
But how do I do a break outside a loop?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #6 on: March 03, 2013, 03:58:13 pm » |
Do you mean function called "loop" or a while or for loop?
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 5
|
 |
« Reply #7 on: March 03, 2013, 04:00:50 pm » |
I mean a break outside a loop (not function), a "for", "while" etc, what admit a break sentence.
|
|
|
|
|
Logged
|
|
|
|
|
Des Moines, WA - USA
Offline
God Member
Karma: 21
Posts: 707
|
 |
« Reply #8 on: March 03, 2013, 04:21:02 pm » |
const uint8_t pinLED = 13;
const uint8_t LED_OFF = LOW; const uint8_t LED_ON = HIGH; const unsigned long HALF_SECOND = 500UL;
void loop() {}
void setup() { pinMode(pinLED, OUTPUT);
digitalWrite(pinLED, LED_OFF;
int loop_counter = 100; while ( loop_counter-- ) { digitalWrite(pinLED, LED_ON); delay(HALF_SECOND);
digitalWrite(pinLED, LED_OFF); delay(HALF_SECOND); } }
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 5
|
 |
« Reply #9 on: March 03, 2013, 04:26:32 pm » |
Thank you, It's a bad habit inherited of BASIC programation.
|
|
|
|
|
Logged
|
|
|
|
|
|