Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <IRremote.h>
- IRsend irsend;
- const int offButtonPin = 4;
- const int nightButtonPin = 5;
- int offButtonState = 0;
- int nightButtonState = 0;
- unsigned long lastCode = 0;
- unsigned long newCode = 0;
- unsigned long empty = 0;
- void setup() {
- pinMode(offButtonPin, INPUT);
- pinMode(nightButtonPin, INPUT);
- }
- void loop() {
- newCode = empty;
- if(isButtonPressed(offButtonPin)){
- newCode = 0x203552AD;
- }
- if(isButtonPressed(nightButtonPin)){
- newCode = 0x203540BF;
- }
- if(newCode > empty && newCode == lastCode){
- repeat();
- } else if (newCode > empty){
- send(newCode);
- lastCode = newCode;
- } else {
- lastCode = empty;
- }
- delay(100);
- }
- bool isButtonPressed(int button){
- if(digitalRead(button) == HIGH){
- return true;
- }
- return false;
- }
- void send(unsigned long code){
- irsend.sendNEC(code, 32);
- }
- void repeat() {
- unsigned int buf[3];
- buf[0] = 9000; // Mark 9ms
- buf[1] = 2250; // Space 2.25ms
- buf[2] = 560; // Burst
- irsend.sendRaw(buf, 3, 38);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement