#include <IRremote.h> #include <IRremoteInt.h> #include <IRremote.h> #include <Wire.h> const byte SLAVE_ADDRESS = 0x15; int led = 13; byte x; int tmp; IRsend irsend; void setup() { Serial.begin(115200); Wire.begin(SLAVE_ADDRESS); TWBR = 12; // 50 kHz speed Wire.onReceive(receiveData); pinMode(2, OUTPUT); } void receiveData(int n){ while(Wire.available()){ int c; c= Wire.read(); // receive byte as a character Serial.print(c); // print the character tmp=c; } } void loop() { if(tmp=='a'){ irsend.sendNEC(0x807F30CF, 32); // TV power code 這邊採用NEC的模式 ,807F30CF 是我的電視訊號 tmp=' '; } else if(tmp=='b'){ irsend.sendNEC(0x807F30CF, 32); // TV power code 這邊採用NEC的模式 ,807F30CF 是我的電視訊號 tmp=' '; } else if(tmp=='c'){ digitalWrite(2, HIGH); // sets the LED on tmp=' '; } else if(tmp=='d'){ digitalWrite(2, LOW); // sets the LED off tmp=' '; } delay(500); }