ผมนำcodeมาปรับแก้ไขครับ ให้รับค่าButton 2 ตัวครับ นับจำนวนครั้งตามที่กด แล้วให้แสดงขึ้น Serial monitor โดยกด Button1 พร้อมกับ Button2 แล้วค่าจะ +1 แต่ติดปัญหาที่กดค้างแล้วค่าขึ้นรัวๆเลยคับ อยากให้ช่วยเรื่อง วิธีหยุด ให้นับเพิ่มแค่1ครั้ง ต่อการ กดButton 1รอบครั้ง (1รอบนี่กดทั้ง2ปุ่มพร้อมกันนะคับ)
นี่codeที่ทำคับ
int Button1 = 2;
int Button2 = 3;
int CountB1;
int CountB2;
int ButtonState = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(Button1, INPUT);
pinMode(Button2, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
CountB1 = digitalRead(Button1);
if(CountB1 == 0){
CountB2 = digitalRead(Button2);
if(CountB2 == 0){
ButtonState = ButtonState+1;
}
}else{
CountB2 = digitalRead(Button2);
if(CountB2 == 0){
CountB1 = digitalRead(Button1);
if(CountB1 == 0){
ButtonState = ButtonState-1;
}
}
}
Serial.println(ButtonState);
delay(100);
}
ขอบคุณครับ
รบกวนช่วยแก้ปัญหา Arduino หน่อยครีบ (หัดเล่น)
นี่codeที่ทำคับ
int Button1 = 2;
int Button2 = 3;
int CountB1;
int CountB2;
int ButtonState = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(Button1, INPUT);
pinMode(Button2, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
CountB1 = digitalRead(Button1);
if(CountB1 == 0){
CountB2 = digitalRead(Button2);
if(CountB2 == 0){
ButtonState = ButtonState+1;
}
}else{
CountB2 = digitalRead(Button2);
if(CountB2 == 0){
CountB1 = digitalRead(Button1);
if(CountB1 == 0){
ButtonState = ButtonState-1;
}
}
}
Serial.println(ButtonState);
delay(100);
}
ขอบคุณครับ