Digital Input – Button
Digital Input – Troubleshooter
Analog Input – Potentiometer
My code doesn’t work.. I tried adding and changing the ‘else’ and ‘if’ commands, but that didn’t work either.
const int buttonPin1 = 2; const int buttonPin2 = 3; const int ledPin = 13; int buttonState = 0; void setup() { pinMode(ledPin, OUTPUT); pinMode(buttonPin1, INPUT); pinMode(buttonPin2, INPUT); } void loop() { buttonState = digitalRead(buttonPin1); if (buttonState == HIGH); digitalWrite(ledPin, HIGH); else digitalWrite(ledPin, LOW); } void loop() { buttonState = digitalRead(buttonPin2); if (buttonState == HIGH); digitalWrite(ledPin, LOW); else digitalWrite(ledPin, HIGH); } }
You’re missing curly braces to start/end your if/else statements, and you have two loops when you should only have one. Why didn’t you reach out over email for help? Next time please do. The solution to this particular code example is in the assignment post: https://makingstudio.blog/2017/09/21/week-3-homework-3/