Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "IRremote.h"
- IRrecv irrecv(11); // Указываем пин, к которому подключен приемник
- decode_results results;
- String inputString = "";
- boolean stringComplete = false;
- boolean LampIsON = false;
- int lastPoz = 0;
- int lastPozTimeOut = 0;
- int lastPozTimeOutSet = 200;
- #define BTN_ONOFF 9435
- #define BTN_PHOTO 5355
- #define BTN_DISPLAY 30855
- #define BTN_SELF_TIMER -11221
- #define BTN_ZERO_MEMORY 14535
- #define BTN_DATE_TIME 1275
- #define BTN_PHOTO_SEARCH -13261
- #define BTN_DUB -21421
- #define BTN_SLOW -10201
- #define BTN_X2 11475
- #define BTN_W 17595
- #define BTN_T -31621
- #define BTN_BACK 6375
- #define BTN_NEXT 22695
- #define BTN_PLAY -26521
- #define BTN_PAUSE 26775
- #define BTN_STOP -22441
- #define BTN_MINUS -5101
- #define BTN_PLUS 27795
- #define BTN_FADV 23715
- //#define BTN_ 0x;
- void setup()
- {
- Serial.begin(9600); // Выставляем скорость COM порта
- irrecv.enableIRIn(); // Запускаем прием
- pinMode(2, OUTPUT);
- // reserve 200 bytes for the inputString:
- inputString.reserve(200);
- }
- void loop() {
- if (irrecv.decode(&results)) // Если данные пришли
- {
- int res = results.value;
- //Serial.println(results.value, HEX);
- //Serial.println(res);
- if(res == BTN_ONOFF || res == BTN_PHOTO || res == BTN_DISPLAY || res == BTN_SELF_TIMER || res == BTN_ZERO_MEMORY || res == BTN_DATE_TIME || res == BTN_PHOTO_SEARCH || res == BTN_DUB || res == BTN_SLOW || res == BTN_X2 || res == BTN_W || res == BTN_T || res == BTN_BACK || res == BTN_NEXT || res == BTN_PLAY || res == BTN_PAUSE || res == BTN_STOP || res == BTN_MINUS || res == BTN_PLUS || res == BTN_FADV) {
- if(res != lastPoz) {
- if(lastPoz != 0) {
- ButtonUp(lastPoz);
- }
- lastPoz = res;
- ButtonDown(res);
- } else {
- ButtonHold(res);
- }
- }
- lastPozTimeOut = 0;
- irrecv.resume(); // Принимаем следующую команду
- }
- if(stringComplete) {
- //Serial.println(inputString);
- if(inputString == "on\n") {
- digitalWrite(2, HIGH);
- LampIsON = true;
- }
- if(inputString == "off\n") {
- digitalWrite(2, LOW);
- LampIsON = false;
- }
- if(inputString == "stat\n") {
- if(LampIsON) {
- Serial.println("1");
- } else {
- Serial.println("0");
- }
- }
- // clear the string:
- inputString = "";
- stringComplete = false;
- }
- lastPozTimeOut += 1;
- if(lastPozTimeOut >= lastPozTimeOutSet) {
- if(lastPoz != 0) {
- ButtonUp(lastPoz);
- lastPoz = 0;
- }
- }
- delay(1);
- }
- void ButtonDown(int BtnCode) {
- //Serial.println("ButtonDown: ");
- //Serial.println(BtnCode);
- }
- void ButtonUp(int BtnCode) {
- //Serial.println("ButtonUp: ");
- //Serial.println(BtnCode);
- if(BtnCode == BTN_ONOFF) {
- if(!LampIsON) {
- digitalWrite(2, HIGH);
- LampIsON = true;
- } else {
- digitalWrite(2, LOW);
- LampIsON = false;
- }
- }
- }
- void ButtonHold(int BtnCode) {
- //Serial.println("ButtonHold: ");
- //Serial.println(BtnCode);
- }
- void serialEvent() {
- while(Serial.available()) {
- // get the new byte:
- char inChar = (char)Serial.read();
- // add it to the inputString:
- inputString += inChar;
- // if the incoming character is a newline, set a flag
- // so the main loop can do something about it:
- if (inChar == '\n') {
- stringComplete = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement