Pages: [1]   Go Down
Author Topic: Modifyed blink  (Read 405 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Brattain Member
*****
Karma: 308
Posts: 26469
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

but I tryed with while without void and it does the same error.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 308
Posts: 26469
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Poole, Dorset, UK
Offline Offline
Edison Member
*
Karma: 52
Posts: 2363
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Because you need loop()

Mark
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

But how do I do a break outside a loop?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 308
Posts: 26469
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I mean  a break outside a loop (not function), a "for", "while" etc, what admit a break sentence.
Logged

Des Moines, WA - USA
Offline Offline
God Member
*****
Karma: 25
Posts: 779
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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 Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you, It's a bad habit inherited of BASIC programation.
Logged

Pages: [1]   Go Up
Jump to: