Go Down

Topic: Brackets error (Read 802 times) previous topic - next topic

jonbloom

Hello!
I'm trying to run this really simple sketch through "Simulator for Arduino" ver V0.97B and it kicks out an error related to the brackets of my "if" statement.
"Sketch Error - no opening bracket for switch"

My code has both opening and closing brackets containing the "to do" commands.  Not sure if this is a simulator glitch or syntax error on my part.  (Waiting for an Uno board delivery, thus simulator use.)

Any insights would be appreciated. 
Jon

It seems everyone at home thinks the dog had been fed, or he gets double fed.  So why not use a microcontroller, right?
/*
*  Feed the Dog Timer
*  When LED is green, dog has been fed; When red, dog is hungry.
*  Momentary switch depression (green - fed) starts timer (long delay)
*   upon timeout, (red - hungry)
*  First microcontroller project by Jon Bloom, 11/2012
*/

int switchPin = 2;              // switch is connected to pin 2
int grnLED = 6;                 // green LED connected to pin 6
int redLED = 7;                 // red LED connected to pin 7


void setup() {
  pinMode(switchPin, INPUT);    // Set the switch pin as input
  pinMode(grnLED, OUTPUT);      // Set fed LED pin as output
  pinMode(redLED, OUTPUT);      // Set hungry LED pin as output
}


void loop(){
 
  digitalWrite(grnLED,LOW);     // turns off fed lamp
  digitalWrite(redLED,HIGH);    // turns on hungry lamp
  if (switchPin==HIGH){
    digitalWrite(redLED,LOW);  // turns off hungry lamp
    digitalWrite(grnLED,HIGH); // turns on fed lamp
    delay(28800000);               // sets fed lamp on time duration, 8 hours
  }
 
}

Coding Badly

Hello.

I'm trying to run this really simple sketch through "Simulator for Arduino" ...


Why?

fungus


Hello.

I'm trying to run this really simple sketch through "Simulator for Arduino" ...


Why?


Because he hasn't got his board yet. He says so in his post.

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

CrossRoads

#3
Nov 20, 2012, 10:10 pm Last Edit: Nov 20, 2012, 10:12 pm by CrossRoads Reason: 1
Use CTRL-T (autoformat), will help you spot mismatched qtys of { }, mayebe ( ) and [ ] even.
If nothing else, clickt to right of ], ), }, will highlight the opening (, {, [ so you can see what the code is doing.

Altho I don't see any problems like that here, nothing the IDE compiler would complain about.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Arrch


Hello!
I'm trying to run this really simple sketch through "Simulator for Arduino" ver V0.97B and it kicks out an error related to the brackets of my "if" statement.
"Sketch Error - no opening bracket for switch"


It sounds like the simulator sees "switch" and assumes it means it's a switch statement. Try changing the name of the variable to something without switch.

Go Up