Lysregulering
/
SET_DIO_HIGH_IR_FUNGERER
FUNGERER MED FJERNKONTROLL
Fork of Trinket_remote by
Revision 1:0aae52ba2e8d, committed 2018-02-24
- Comitter:
- andreasbirkeland97
- Date:
- Sat Feb 24 23:08:27 2018 +0000
- Parent:
- 0:0124991faa9d
- Commit message:
- Fungerende program med IR kontroll. Styrer DIO p? xbee
Changed in this revision
diff -r 0124991faa9d -r 0aae52ba2e8d XBeeLib.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/XBeeLib.lib Sat Feb 24 23:08:27 2018 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/Digi-International-Inc/code/XBeeLib/#b5f4a0e92249
diff -r 0124991faa9d -r 0aae52ba2e8d config.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/config.h Sat Feb 24 23:08:27 2018 +0000 @@ -0,0 +1,57 @@ +/** + * Copyright (c) 2015 Digi International Inc., + * All rights not expressly granted are reserved. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343 + * ======================================================================= + */ + +#ifndef __CONFIG_H_ +#define __CONFIG_H_ + +/** Library configuration options */ +#define ENABLE_LOGGING +#define ENABLE_ASSERTIONS +#define FRAME_BUFFER_SIZE 4 +#define MAX_FRAME_PAYLOAD_LEN 128 + +#define SYNC_OPS_TIMEOUT_MS 2000 + +#define RADIO_TX p9 /* TODO: specify your setup's Serial TX pin connected to the XBee module DIN pin */ +#define RADIO_RX p10 /* TODO: specify your setup's Serial RX pin connected to the XBee module DOUT pin */ +//#define RADIO_RTS NC /* TODO: specify your setup's Serial RTS# pin connected to the XBee module RTS# pin */ +//#define RADIO_CTS NC /* TODO: specify your setup's Serial CTS# pin connected to the XBee module CTS# pin */ +#define RADIO_RESET p19 /* TODO: specify your setup's GPIO (output) connected to the XBee module's reset pin */ +//#define RADIO_SLEEP_REQ NC /* TODO: specify your setup's GPIO (output) connected to the XBee module's SLEEP_RQ pin */ +//#define RADIO_ON_SLEEP NC /* TODO: specify your setup's GPIO (input) connected to the XBee module's ON_SLEEP pin */ +#define DEBUG_TX USBTX /* TODO: specify your setup's Serial TX for debugging */ +#define DEBUG_RX USBRX /* TODO: specify your setup's Serial RX for debugging (optional) */ + +#if !defined(RADIO_TX) + #error "Please define RADIO_TX pin" +#endif + +#if !defined(RADIO_RX) + #error "Please define RADIO_RX pin" +#endif + +#if !defined(RADIO_RESET) + #define RADIO_RESET NC + #warning "RADIO_RESET not defined, defaulted to 'NC'" +#endif + +#if defined(ENABLE_LOGGING) + #if !defined(DEBUG_TX) + #error "Please define DEBUG_TX" + #endif + #if !defined(DEBUG_RX) + #define DEBUG_RX NC + #warning "DEBUG_RX not defined, defaulted to 'NC'" + #endif +#endif + +#endif /* __CONFIG_H_ */
diff -r 0124991faa9d -r 0aae52ba2e8d main.cpp --- 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 -} - +