Stap 5: codering:
#include<LiquidCrystal.h>#include<IRremote.h>LiquidCrystal lcd(7,6, 5, 4, 3, 2);int RECV_PIN = 11;IRrecv irrecv(RECV_PIN);decode_results results;void setup(){ Serial.begin(9600); pinMode(13,OUTPUT); digitalWrite(13,1); lcd.begin(16, 2); irrecv.enableIRIn(); // Start the receiver } // Dumps out the decode_results structure. // Call this after IRrecv::decode() // void * to work around compiler issue //void dump(void *v) { // decode_results *results = (decode_results *)v void dump(decode_results *results) { lcd.setCursor(0, 0); int count = results->rawlen; if (results->decode_type == UNKNOWN) { Serial.print("Unknown encoding: "); lcd.print("Unknown encoding: "); } else if (results->decode_type == NEC) { Serial.print("Decoded NEC: "); lcd.print("Decoded NEC: "); } else if (results->decode_type == SONY) { Serial.print("Decoded SONY: "); lcd.print("Decoded SONY: "); } else if (results->decode_type == RC5) { Serial.print("Decoded RC5: "); lcd.print("Decoded RC5: "); } else if (results->decode_type == RC6) { Serial.print("Decoded RC6: "); lcd.print("Decoded RC6: "); } else if (results->decode_type == PANASONIC) { Serial.print("Decoded PANASONIC - Address: "); Serial.print(results->panasonicAddress,HEX); Serial.print(" Value: "); } else if (results->decode_type == LG) { Serial.print("Decoded LG: "); lcd.print("Decoded LG: "); } else if (results->decode_type == JVC) { Serial.print("Decoded JVC: "); lcd.print("Decoded JVC: "); } lcd.setCursor(0, 1); Serial.print(results->value, HEX); lcd.print(results->value, HEX); Serial.print(" ("); Serial.print(results->bits, DEC); Serial.println(" bits)"); Serial.print("Raw ("); Serial.print(count, DEC); Serial.print("): "); for (int i = 0; i < count; i++) { if ((i % 2) == 1) { Serial.print(results->rawbuf[i]*USECPERTICK, DEC); } else { Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC); } Serial.print(" "); } Serial.println(""); }void loop() { if (irrecv.decode(&results)) { Serial.println(results.value, HEX); dump(&results); irrecv.resume(); // Receive the next value } }
Voor deze code kan worden uitgevoerd u nodig een externe bibliotheek van IR.
Jusr Goole het of u kunt vanaf hier ook downloaden.