Go Down

Topic: error message please help (Read 111 times) previous topic - next topic

vinau

Nov 08, 2015, 11:14 pm Last Edit: Nov 08, 2015, 11:30 pm by CrossRoads
this is one of my first programs and my error message says  "expected ')' before ';' token" in the void loop() function please help
(Please use code tags. Thanks! Moderator.)
Code: [Select]

// set pin numbers:
const int buttonPin[] = {5,6};     // the number of the pushbutton pins
const int relayPin =  13;// the number of the relay pin
// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
 // initialize the LED pin as an output:
 pinMode(relayPin, OUTPUT);    
 // initialize the pushbutton pin as an input:
 for(int x=0; x<2; x++)
 {
   pinMode(buttonPin[x], INPUT);
 }  
}

void loop(){
 // read the state of the pushbutton value:
 for(int x=0; x<2; x++)
{
   (buttonState = digitalRead(buttonPin[x]);

   // check if the pushbutton is pressed.
   // if it is, the buttonState is HIGH:
 
   if (buttonState == HIGH && buttonPin[x] == 2) {    
     // turn LED on:  
     digitalWrite(relayPin, LOW);
   }
   if (buttonState == LOW && buttonPin[x] == 2) {    
     // turn LED on:  
     digitalWrite(relayPin, HIGH);
   }
   if (buttonState == HIGH && buttonPin[x] == 3) {
     // turn LED off:
     digitalWrite(relayPin, LOW);
   }
  }
}

Delta_G

You're going to have to put that in code tags.  My browser is turning out all sorts of weird symbols.  Please read the "How To Use This Forum" post at the top of the board.  Pay attention to point 7.
Ad hoc, ad loc, and quid pro quo.  So little time - so much to know!  ~Jeremy Hillary Boob Ph.D

vinau

sorry here is the program
Code: [Select]
const int buttonPin[] = {2,3};     // the number of the pushbutton pins
const int relayPin =  13;// the number of the relay pin
// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(relayPin, OUTPUT);     
  // initialize the pushbutton pin as an input:
  for(int x=0; x<2; x++)
  {
    pinMode(buttonPin[x], INPUT);
  } 
}

void loop(){
  // read the state of the pushbutton value:
  for(int x=0; x<2; x++)
{
    (buttonState = digitalRead(buttonPin[x]);

    // check if the pushbutton is pressed.
    // if it is, the buttonState is HIGH:
   
    if (buttonState == HIGH && buttonPin[x] == 2) {   
      // turn LED on:   
      digitalWrite(relayPin, LOW);
    }
    if (buttonState == LOW && buttonPin[x] == 2) {   
      // turn LED on:   
      digitalWrite(relayPin, HIGH);
    }
    if (buttonState == HIGH && buttonPin[x] == 3) {
      // turn LED off:
      digitalWrite(relayPin, LOW);
    }
   }
 }

CrossRoads

#3
Nov 08, 2015, 11:33 pm Last Edit: Nov 08, 2015, 11:33 pm by CrossRoads
This line has an extra ( at the start (or, is missing one at the end).
Code: [Select]

  (buttonState = digitalRead(buttonPin[x]);
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Delta_G

#4
Nov 08, 2015, 11:33 pm Last Edit: Nov 08, 2015, 11:34 pm by Delta_G
Does it highlight that first line in the for loop?  Notice anything funny about that line?  What's that at the beginning of it?
Ad hoc, ad loc, and quid pro quo.  So little time - so much to know!  ~Jeremy Hillary Boob Ph.D

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy