// constants won’t change. They’re used here to set pin numbers:
const int firstButtonPin = 5; // the number of the pushbutton pin
const int ledPin = 12; // the number of the LED pin
const int secondbuttonPin = 3; // the number of the pushbutton pin
int flag=0;
// variables will change:
void setup() {
// initialize the LED pin as an output:
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(firstButtonPin, INPUT);
pinMode(secondbuttonPin, INPUT);
}
void loop() {
// read the state of the pushbutton value:
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (digitalRead(firstButtonPin) == LOW) {
// turn LED on:
flag = 1;
}
if(digitalRead(secondbuttonPin)==LOW){
flag = 0;
}
Serial.print(flag);
if(flag==1){
digitalWrite(ledPin,HIGH);
}else{
digitalWrite(ledPin,LOW);
}
}
AWESOME video, Shuyi!!