Go Down

Topic: First Project: LEDs (Read 335 times) previous topic - next topic

_OverLord_

I just started using Arduino but every time I make a project it creates errors that I dont know how to fix.
Here's my sketch.

if (SwitchState == LOW) {
 
 
   digitalWrite(3, HIGH);
   digitalWrite(4, LOW);
   digitalWrite(5, LOW);
 
 
 }

 else{
   digitalWrite(3, LOW);
   digitalWrite(4, LOW);
   digitalWrite(5, HIGH);
 
   delay(250); 
   digitalWrite(4, HIGH);
   digitalWrite(5, LOW);
   delay(250);
 
  }
 
 

Delta_G

Go have a look at some of the example sketches.  You have to have your code in functions.  Two functions, setup and loop MUST be defined for your sketch.  Again, go look at some of the examples and you'll see how this stuff is supposed to be laid out. 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

CrossRoads

Yes, you're missing the beginning, and end, which can be inferred to be:
Code: [Select]

byte switchPin = 2;
byte switchState;
void setup(){
pinMode (3, OUTPUT);
pinMode (4, OUTPUT);
pinMode (5, OUTPUT);
pinMode (switchPin, INPUT_PULLUP);
}
void loop(){
switchState = digitalRead (switchPin);
// then your code

} // end of loop()
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.

CrossRoads

check upper/lower case consistency in naming also.
SwitchState is a different variable than switchState, so you need to make those match.
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.

Go Up