Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include <IRremote.h>
  2. int RECV_PIN = 11;
  3. int led = 13;
  4. #define code1 16753245 // แก้ค่าปุ่มกดที่ 1
  5. #define code2 16736925 // แก้ค่าปุ่มกดที่ 2
  6. IRrecv irrecv(RECV_PIN);
  7. decode_results results;
  8. void setup()
  9. {
  10. Serial.begin(9600);
  11. irrecv.enableIRIn(); // Start the receiver
  12. pinMode(led, OUTPUT);
  13. digitalWrite(led, LOW);
  14. }
  15. void loop() {
  16. if (irrecv.decode(&results)) {
  17. Serial.print("รหัสปุ่มกด: ");
  18. Serial.println(results.value);
  19. if (results.value == code1) { // ถ้าค่าที่ส่งมาตรงกับ ค่าในตัวแปร code1 ให้ทำใน ปีกกา if
  20. Serial.println("LED ON");
  21. digitalWrite(led, HIGH);
  22. }
  23. if (results.value == code2) { // ถ้าค่าที่ส่งมาตรงกับ ค่าในตัวแปร code2 ให้ทำใน ปีกกา if
  24. Serial.println("LED OFF");
  25. digitalWrite(led, LOW);
  26. }
  27. irrecv.resume(); // Receive the next value
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement