Skip to content

Instantly share code, notes, and snippets.

@truongtpa
Last active October 18, 2022 10:02
Show Gist options
  • Select an option

  • Save truongtpa/5741d494691b676f5d26189993fdc61d to your computer and use it in GitHub Desktop.

Select an option

Save truongtpa/5741d494691b676f5d26189993fdc61d to your computer and use it in GitHub Desktop.
void setup() {
Serial.begin(9600);
Serial.println("Xin chao.....");
pinMode(13, OUTPUT);
pinMode(3, INPUT);
}
int st_nut = LOW; // Trạng thái trước đó của nút
long time_A = 0; // TG nhấn nút A
void loop() {
int st = digitalRead(3);
// A
if(st_nut == LOW && st == HIGH){
time_A = millis();
}
// B
if(st_nut == HIGH && st == LOW){
Serial.println(millis() - time_A);
if(millis() - time_A > 500){
digitalWrite(13, HIGH);
delay(5000);
}
}
digitalWrite(13, LOW);
st_nut = st;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment