Skip to content

Instantly share code, notes, and snippets.

@imiconsystem2
Created February 23, 2023 08:28
Show Gist options
  • Select an option

  • Save imiconsystem2/638aa224df4a0b2e5f4845cb265551a4 to your computer and use it in GitHub Desktop.

Select an option

Save imiconsystem2/638aa224df4a0b2e5f4845cb265551a4 to your computer and use it in GitHub Desktop.
CUSTOM SWITCH Push Button [Pull-Down] ปุ่มกดที่สามารถกำหนดการใช้งานเอง นี้ เชื่อมต่ออยู่กับ GPIO13 หรือ D13 ของคอนโทลเลอร์
const int buttonPin = 13;
const int ralay = 2;
int buttonState = 0;
void setup() {
Serial.begin(9600);
pinMode(ralay, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
digitalWrite(ralay, HIGH);
Serial.println("on");
} else {
digitalWrite(ralay, LOW);
Serial.println("off");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment