Hey guys, I'm working on a project for an intro to engineering course, and we haven't had any experience with C++ prior to this. The professor isn't helping at all, so I figured I'd ask you guys.
Basically this is a miniature game, where if you press the button while the Red LED (ledPin1) is on, the Red LED will turn off, a green Win LED will turn on (winPin), and a motor will spin.
For some reason I can't get this and statement working... It might be the boolean, the if statement, or the and statement. When I verify Arduino says it's fine.
Thanks!
const int ledPin1 = 0;
const int buttonPin1 = 1;
const int winPin = 2;
int buttonState1 = 0;
boolean ledState1 = false;
void setup() {
pinMode(ledPin1, OUTPUT);
pinMode(buttonPin1, INPUT);
}
void loop() {
buttonState1 = digitalRead(ButtonPin1);
digitalWrite(ledPin1, HIGH);
ledState1 = !ledState1;
delay(10000);
digitalWrite(ledPin1, LOW);
ledState1 = !ledState1;
delay(10000);
// First LED, First button
if (buttonState1 == HIGH and ledState1 == true) {
digitalWrite(ledPin1, LOW);
// add motor start here
digitalWrite(winPin, HIGH);
delay(7000); //thinking about changing this delay to a longer number, has to be longer than any delays in the LED on/off cycle, which will later be expanded to seem semi-random
// add motor end here
digitalWrite(winPin, LOW);
}
//cycle repeats, will check
}