FUNGERER MED FJERNKONTROLL

Dependencies:   XBeeLib mbed

Fork of Trinket_remote by David Bottrill

Revision:
1:0aae52ba2e8d
Parent:
0:0124991faa9d
--- a/main.cpp	Tue May 19 09:43:35 2015 +0000
+++ b/main.cpp	Sat Feb 24 23:08:27 2018 +0000
@@ -1,22 +1,5 @@
-
-/* Trinket/Gemma compatible Raw IR decoder sketch
-This sketch/program uses an Adafruit Trinket or Gemma
-ATTiny85 based mini microcontroller and a PNA4602 to
-decode IR received. This can be used to make a IR receiver
-(by looking for a particular code) or transmitter
-(by pulsing an IR LED at ~38KHz for the durations detected
-
-Based on Adafruit tutorial http://learn.adafruit.com/ir-sensor/using-an-ir-sensor
-
-and ATTiny program by TinyPCRemote Nathan Chantrell http://nathan.chantrell.net
-under Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) license
-
-Modified to work on MBed by David Bottrill May 2015
-This has been tested on a KL25z using a Grove IR sensor with a number of different
-Infrared Remote controls.
-
-*/
 #include "mbed.h"
+#include "XBeeLib.h"
 
 #define MAXPULSE    10000                               // the maximum pulse we'll listen for - 10 milliseconds 
 #define NUMPULSES    200                                // max IR pulse pairs to sample
@@ -27,19 +10,23 @@
 uint16_t currentpulse = 0;                              // index for pulses we're storing
 uint32_t irCode = 0;
 Serial pc(USBTX, USBRX);                                // tx, rx
-DigitalIn IRpin (D2);                                   // Listen to IR receiver on Trinket/Gemma pin D2
+DigitalIn IRpin (p8);                                   // Listen to IR receiver on Trinket/Gemma pin D2
 
 int listenForIR(void);                                  // IR receive code
 void printcode(void);                                   // Print IR code in HEX
 
+using namespace XBeeLib;
+
 int main(void)
 {
     pc.printf("Ready to decode IR!\n");
+    XBeeZB xbee = XBeeZB(RADIO_TX, RADIO_RX, RADIO_RESET);
+    RadioStatus radioStatus;
 
     while (1) {
 
         int numpulse=listenForIR();                     // Wait for an IR Code
-
+        RemoteXBeeZB remoteDevice = RemoteXBeeZB(0x0013A20041642F34);
         // Process the pulses to get a single number representing code
         for (int i = 0; i < 32; i++) {
             irCode=irCode<<1;
@@ -50,14 +37,112 @@
             }
         }
 
-        printcode();                                    // Print IR code 
+        // Print IR code
         wait_ms(100);
 
+        if (irCode ==  0xc489211e) {
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO12, DigitalOutLow);    //d0
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO4, DigitalOutLow);    //d1  
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO0_AD0, DigitalOutLow);    //d2
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO3_AD3, DigitalOutLow);    //d3
+        }
+                if (irCode ==  0xc489112e) {
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO12, DigitalOutHigh);    //d0
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO4, DigitalOutLow);    //d1  
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO0_AD0, DigitalOutLow);    //d2
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO3_AD3, DigitalOutLow);    //d3
+        }
+                if (irCode ==  0xc489310e) {
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO12, DigitalOutLow);    //d0
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO4, DigitalOutHigh);    //d1  
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO0_AD0, DigitalOutLow);    //d2
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO3_AD3, DigitalOutLow);    //d3
+        }
+                if (irCode ==  0xc4890936) {
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO12, DigitalOutHigh);    //d0
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO4, DigitalOutHigh);    //d1  
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO0_AD0, DigitalOutLow);    //d2
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO3_AD3, DigitalOutLow);    //d3
+        }
+                if (irCode ==  0xc489201f) {
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO12, DigitalOutLow);    //d0
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO4, DigitalOutLow);    //d1  
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO0_AD0, DigitalOutHigh);    //d2
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO3_AD3, DigitalOutLow);    //d3
+        }
+                if (irCode ==  0xc489102f) {
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO12, DigitalOutHigh);    //d0
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO4, DigitalOutLow);    //d1  
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO0_AD0, DigitalOutHigh);    //d2
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO3_AD3, DigitalOutLow);    //d3
+        }
+                if (irCode ==  0xc489300f) {
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO12, DigitalOutLow);    //d0
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO4, DigitalOutHigh);    //d1  
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO0_AD0, DigitalOutHigh);    //d2
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO3_AD3, DigitalOutLow);    //d3
+        }
+                if (irCode ==  0xc4890837) {
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO12, DigitalOutHigh);    //d0
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO4, DigitalOutHigh);    //d1  
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO0_AD0, DigitalOutHigh);    //d2
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO3_AD3, DigitalOutLow);    //d3
+        }
+                if (irCode ==  0xc4892817) {
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO12, DigitalOutLow);    //d0
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO4, DigitalOutLow);    //d1  
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO0_AD0, DigitalOutLow);    //d2
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO3_AD3, DigitalOutHigh);    //d3
+        }
+                if (irCode ==  0xc4891827) {
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO12, DigitalOutHigh);    //d0
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO4, DigitalOutLow);    //d1  
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO0_AD0, DigitalOutLow);    //d2
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO3_AD3, DigitalOutHigh);    //d3
+        }
+                if (irCode ==  0xc4893807) {
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO12, DigitalOutLow);    //d0
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO4, DigitalOutHigh);    //d1  
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO0_AD0, DigitalOutLow);    //d2
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO3_AD3, DigitalOutHigh);    //d3
+        }
+                if (irCode ==  0xc489043b) {
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO12, DigitalOutHigh);    //d0
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO4, DigitalOutHigh);    //d1  
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO0_AD0, DigitalOutLow);    //d2
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO3_AD3, DigitalOutHigh);    //d3
+        }
+                if (irCode ==  0xc489241b) {
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO12, DigitalOutLow);    //d0
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO4, DigitalOutLow);    //d1  
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO0_AD0, DigitalOutHigh);    //d2
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO3_AD3, DigitalOutHigh);    //d3
+        }
+                if (irCode ==  0xc4892996) {
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO12, DigitalOutHigh);    //d0
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO4, DigitalOutLow);    //d1  
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO0_AD0, DigitalOutHigh);    //d2
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO3_AD3, DigitalOutHigh);    //d3
+        }
+                if (irCode ==  0xc489003f) {
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO12, DigitalOutLow);    //d0
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO4, DigitalOutHigh);    //d1  
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO0_AD0, DigitalOutHigh);    //d2
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO3_AD3, DigitalOutHigh);    //d3
+        }
+                if (irCode ==  0xc4890c33) {
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO12, DigitalOutHigh);    //d0
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO4, DigitalOutHigh);    //d1  
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO0_AD0, DigitalOutHigh);    //d2
+              radioStatus = xbee.set_pin_config(remoteDevice, XBeeZB::DIO3_AD3, DigitalOutHigh);    //d3
+        }
+
     }  //end of main loop
 }
 
 
-int listenForIR(void){                                  // IR receive code
+int listenForIR(void)                                   // IR receive code
+{
     currentpulse = 0;
     while (1) {
         unsigned int highpulse, lowpulse;               // temporary storage timing
@@ -83,12 +168,4 @@
         currentpulse++;
     }
 }
-
-void printcode(void)
-{
-    uint16_t half;
-    half=irCode>>16;                                    // Get first 16 bits of code
-    pc.printf("0x%x",half);                             // Print upper 16 bits in hex
-    pc.printf("%x\n",(irCode & 0xFFFF));                // print lower 16 bits in hex
-}
-
+