Lab 8 Arduino
Lab 8 Arduino
x++;
while(digitalRead(button4));//d
} b4State = digitalRead(button4); etect the button4, if pressed,
out of the while loop
//if the button3 press the first //when button4 (reset) pressed
}
if(b3State == 0) if(b4State == 0)
//if the button2 press the first
{ {
if(b2State == 0)
flag = 0; if(b4State == 0)//confirm that
the button4 is pressed {
digitalWrite(LED4,LOW);
{ flag = 0;
digitalWrite(LED1,LOW);
flag = 1; //if so, flag is 1 digitalWrite(LED4,LOW);
digitalWrite(LED2,LOW);
digitalWrite(LED4, digitalWrite(LED1,LOW);
digitalWrite(LED3,HIGH);
HIGH);//turn the host LED on
digitalWrite(LED2,HIGH);
y++;
delay(200);
digitalWrite(LED3,LOW);
while(digitalRead(button4));
}
y++;
x++;
}
while(digitalRead(button4));
}
if(flag == 1)
}
}
{
//if the button3 press the first
}
//read the state of the button
if(b3State == 0)
of buttons
{
// question3 b1State = digitalRead(button1);
flag = 0;
else if (y == 3) b2State = digitalRead(button2);
digitalWrite(LED4,LOW);
{ b3State = digitalRead(button3);
digitalWrite(LED1,LOW);
lcd.clear(); //if the button1 press the first
digitalWrite(LED2,LOW);
lcd.setCursor(1,0); if(b1State == 0)
digitalWrite(LED3,HIGH);
lcd.print("3. 3 * 2 = ?"); {
y+=1;
lcd.setCursor(1,1); flag = 0;
while(digitalRead(button4));
lcd.print("A.1 B.4 C.6"); digitalWrite(LED4, LOW);
x++;
//turn all the led off
} } y++;
} if(flag == 1) while(digitalRead(button4));
} { }
//read the state of the button //if the button3 press the first
of buttons
// question4 if(b3State == 0)
b1State = digitalRead(button1);
else if (y == 4) {
b2State = digitalRead(button2);
{ flag = 0;
b3State = digitalRead(button3);
lcd.clear(); digitalWrite(LED4,LOW);
//if the button1 press the first
lcd.setCursor(1,0); digitalWrite(LED1,LOW);
if(b1State == 0)
lcd.print("4. 3 + 5 = ?"); digitalWrite(LED2,LOW);
{
lcd.setCursor(1,1); digitalWrite(LED3,HIGH);
flag = 0;
lcd.print("A. 8 B.4 C.2"); y++;
digitalWrite(LED4, LOW);
//turn all the led off while(digitalRead(button4));
digitalWrite(LED1,
digitalWrite(LED1,LOW); }
HIGH);//turn the LED1 on only
digitalWrite(LED2,LOW); }
digitalWrite(LED2,LOW);
digitalWrite(LED3,LOW); }
digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW);
y+=1;
//read the state of the button4 // question5
while(digitalRead(button4));//d else if (y == 5)
etect the button4, if pressed,
b4State = digitalRead(button4); out of the while loop {
if(b4State == 0) } lcd.setCursor(1,0);
if(b4State == 0) } lcd.print(x);}
digitalWrite(LED1, while(digitalRead(button4)); {
HIGH);//turn the LED1 on only
} flag = 0;
digitalWrite(LED2,LOW);
} digitalWrite(LED4, LOW);
digitalWrite(LED3,LOW);
} digitalWrite(LED1,
y+=1; HIGH);//turn the LED1 on only
else if (y == 6){
digitalWrite(LED2,LOW);
lcd.clear();
digitalWrite(LED3,LOW);
y+=1;
while(digitalRead(button4));//d
etect the button4, if pressed,
out of the while loop
x++;
else if (y == 7){
x=0;
y=0;}}