Go Down

Topic: unexpected unqualified id before '/' token ----- can someone point out my error (Read 198 times) previous topic - next topic

richandkristen

/* Multiple State Handling
* 05-22-2019
*/

#define button 3                         //Push button on D3
#define lowbeam 5                        //Low Beam on D5
#define highbeam 6                       //High Beam on D6
#define gate 7                          //Gate on D7
/------------------------------------------------------------------------
int state = 0;                          //integer to hold current state
int old = 0;                            //integer to hold last state
int buttonPoll = 0;                     //integer to hold button state
/-------------------------------------------------------------------------
void setup() {
  pinMode(button,INPUT);                //button set as input
  pinMode(lowbeam,OUTPUT);               //relays set as outputs
  pinMode(highbeam,OUTPUT);
  pinMode(gate,OUTPUT);
 
  digitalWrite(lowbeam,LOW);            //initial state as off
  digitalWrite(highbeam,LOW);          //initial state as off
  digitalWrite(gate,LOW);         //initial state as off
}
/-------------------------------------------------------------------------
void loop() {
 
                                        //debouncing routine to read button
  buttonPoll = digitalRead(button);     //poll state of button
  if(buttonPoll == 1){                  //check if it has been pressed
    delay(50);                          //wait 50msec
    buttonPoll = digitalRead(button);   //poll button again
    if(buttonPoll == 0){                //if it is 0 consider 1 press
      state = old +1;                   //increase state by 1
    }}
  else{                                 //if button has not been pressed
  deley(100);                           //wait 100ms
  }
  switch (state) {                      //react to button press & state
    case 1:                             //if state is 1
      digitalWrite(lowbeam,HIGH);        //lowbeam relay on
      digitalWrite(highbeam,LOW);       //highbeam relay off
      digitalWrite(gate,LOW);            //gate relay off
      old = state;                      //set old state as current state
      break;
    case 2:
      digitalWrite(lowbeam,LOW);
      digitalWrite(highbeam,HIGH);
      digitalWrite(gate,LOW);
      old = state;
      break;
    case 3:
      digitalWrite(lowbeam,LOW);
      digitalWrite(highbeam,LOW);
      digitalWrite(gate,HIGH);
      old = state;
      break;
    default:                            //if state if no 1,2,3
      digitalWrite(lowbeam,LOW);         //all relays off
      digitalWrite(highbeam,LOW);
      digitalWrite(gate,LOW);
      old = 0;                          //reset to all off/state 0
      break;
  }   
}

dougp

Everything we call real is made of things that cannot be regarded as real.  If quantum mechanics hasn't profoundly shocked you, you haven't understood it yet. - Niels Bohr

No private consultations undertaken!

fnb111

/............................
will give an error

//..................................... or /*................................*/ is accepted

JCA79B

Code: [Select]
pinMode(button,INPUT);                //button set as input
Code: [Select]
buttonPoll = digitalRead(button);     //poll state of button
  if(buttonPoll == 1){                  //check if it has been pressed

Do you have a pulldown resistor (10k) on pin 3? If not, the above will not work as expected.

Geek Emeritus

the error message means you have punctuation errors. an extra ), a missing comma or semicolon, or

Code: [Select]
void loop() {
 
                                        //debouncing routine to read button
  buttonPoll = digitalRead(button);     //poll state of button
  if(buttonPoll == 1){                  //check if it has been pressed
    delay(50);                          //wait 50msec
    buttonPoll = digitalRead(button);   //poll button again
    if(buttonPoll == 0){                //if it is 0 consider 1 press
      state = old +1;                   //increase state by 1
    }}


that double curly brace

read the bottom half of my signature line
All PMs will be deleted unopened due to arrogant argumentative pot stirring Malfoys.
 If you have not read "How to use this forum - please read", in particular: "7. If you are posting code or error messages, use "code" tags":  expect rude responses

ChrisTenone

pssst, fnb111 gave you the answer. Click his 'add karma' button.
What, I need to say something else too?

Paul__B


Go Up