Today I spoke to Joe for the first time of my life...
He explained that we should do three buttons with an if else statement with three motors. However, what he explained to us is that instead of the motors we should so it with the LED lights. This way the motors wouldn't burn and we would safely see what how and where it works.
This was an incredible way of thinking and converting the code.
So how I made this work was by creating one button with one led light. Then I turned this into three buttons and three led lights and just copied the code twice more as it was already correct.
One problem I had was that two of the led lights kept turning on, but what me and Shiv saw is that the code was fine and so was the wiring which was weird we couldn't understand what was happening. Xavi managed to help me and all I was missing was a '}' - closing bracket.
What I learned from this;
THE LITTLE THINGS MATTER THE MOST.
https://www.arduino.cc/en/tutorial/button
New code;
// constants won't change. They're used here to set pin numbers:
const int buttonPinOne = 2; // the number of the pushbutton pin
const int ledPinOne = 8; // the number of the LED pin
const int buttonPinTwo = 4; // the number of the pushbutton pin
const int ledPinTwo = 10; // the number of the LED pin
const int buttonPinThree = 6; // the number of the pushbutton pin
const int ledPinThree = 12; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
//MAYBE NEEDS TO HAVE STATE OF ALL BUTTONS
void setup() {
// initialize the LED pin as an output:
pinMode(ledPinOne, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPinOne, INPUT);
// initialize the LED pin as an output:
pinMode(ledPinTwo, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPinTwo, INPUT);
// initialize the LED pin as an output:
pinMode(ledPinThree, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPinThree, INPUT);
}
void loop() {
// read the state of the pushbutton value:
// BUTTON ONE
buttonState = digitalRead(buttonPinOne);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPinOne, HIGH);
} else {
// turn LED off:
digitalWrite(ledPinOne, LOW);
// read the state of the pushbutton value:
//BUTTON TWO
buttonState = digitalRead(buttonPinTwo);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPinTwo, HIGH);
} else {
// turn LED off:
digitalWrite(ledPinTwo, LOW);
// read the state of the pushbutton value:
// BUTTON THREE
buttonState = digitalRead(buttonPinThree);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPinThree, HIGH);
} else {
// turn LED off:
digitalWrite(ledPinThree, LOW);
}
}
}
}
v
Comments