Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include <IRremote.h>
  2.  
  3. IRsend irsend;
  4.  
  5. const int offButtonPin = 4;
  6. const int nightButtonPin = 5;
  7.  
  8. int offButtonState = 0;
  9. int nightButtonState = 0;
  10.  
  11. unsigned long lastCode = 0;
  12. unsigned long newCode = 0;
  13. unsigned long empty = 0;
  14.  
  15. void setup() {
  16. pinMode(offButtonPin, INPUT);
  17. pinMode(nightButtonPin, INPUT);
  18. }
  19.  
  20. void loop() {
  21.  
  22. newCode = empty;
  23.  
  24. if(isButtonPressed(offButtonPin)){
  25. newCode = 0x203552AD;
  26. }
  27.  
  28. if(isButtonPressed(nightButtonPin)){
  29. newCode = 0x203540BF;
  30. }
  31.  
  32. if(newCode > empty && newCode == lastCode){
  33. repeat();
  34. } else if (newCode > empty){
  35. send(newCode);
  36. lastCode = newCode;
  37. } else {
  38. lastCode = empty;
  39. }
  40. delay(100);
  41. }
  42.  
  43. bool isButtonPressed(int button){
  44. if(digitalRead(button) == HIGH){
  45. return true;
  46. }
  47. return false;
  48. }
  49. void send(unsigned long code){
  50. irsend.sendNEC(code, 32);
  51. }
  52.  
  53. void repeat() {
  54. unsigned int buf[3];
  55. buf[0] = 9000; // Mark 9ms
  56. buf[1] = 2250; // Space 2.25ms
  57. buf[2] = 560; // Burst
  58. irsend.sendRaw(buf, 3, 38);
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement