mirror of
https://github.com/digistump/DigistumpArduino.git
synced 2025-09-17 09:22:28 -07:00
added updated tinypinchange and associated libraries to support PRO
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
#include <IRLib.h> // In {path_of_installation}/Digispark-Arduino-1.0.x/libraries/DigisparkIRLib/IRLib.h, set MY_PROTOCOL to NEC, SONY, RC5 to find the one used by your own IR Remote Control
|
||||
#include <DigiUSB.h> // In {path_of_installation}/Digispark-Arduino-1.0.x/libraries/DigisparkUSB/DigiUSB.h, RING_BUFFER_SIZE shall be set to 32
|
||||
/*
|
||||
_____ ____ __ _ ____ _ _ _ _
|
||||
| __ \ / __ \ | \ | | / __ \ | | | | | | | |
|
||||
| |__| | | / \_| | . \ | | / / \ \ | | | | \ \ / /
|
||||
| _ / | | _ | |\ \| | | |__| | | | | | \ ' /
|
||||
| | \ \ | \__/ | | | \ ' | | __ | \ \/ / | |
|
||||
|_| \_\ \____/ |_| \__| |_| |_| \__/ |_| 2013
|
||||
|
||||
http://p.loussouarn.free.fr
|
||||
|
||||
*************************************************
|
||||
* Optimized <IRLib> library Dump Demo *
|
||||
*************************************************
|
||||
|
||||
This sketch allows you to discover the protocol used by your own IR Remote Control and the code of each key when pressed.
|
||||
You will see the decoded key codes in the DigiUSB console.
|
||||
|
||||
IMPORTANT:
|
||||
=========
|
||||
- In {path_of_installation}/Digispark-Arduino-1.0.x/libraries/DigisparkIRLib/IRLib.h, set MY_PROTOCOL to NEC, SONY, RC5 to find the protocol used by your own IR Remote Control
|
||||
- In {path_of_installation}/Digispark-Arduino-1.0.x/libraries/DigisparkUSB/DigiUSB.h, RING_BUFFER_SIZE shall be set to 32
|
||||
|
||||
Sensor wiring: (Warning: the wiring may vary depending of the model of IR sensor)
|
||||
=============
|
||||
.-------.
|
||||
| ___ |
|
||||
| / \ | InfraRed
|
||||
| \___/ | Sensor
|
||||
| |
|
||||
'+--+--+'
|
||||
| | | 100
|
||||
P5 <----' | '--+---###--- +5V
|
||||
| |
|
||||
| '==='4.7uF
|
||||
| |
|
||||
'--+--'
|
||||
|
|
||||
GND
|
||||
|
||||
*/
|
||||
|
||||
#define LED_PIN 1
|
||||
#define IR_RX_PIN 5
|
||||
|
||||
#define BUTTON_OFF 0xF740BF //Set here the OFF code for the built-in LED when determined
|
||||
#define BUTTON_ON 0xF7C03F //Set here the ON code for the built-in LED when determined
|
||||
|
||||
IRrecv My_Receiver(IR_RX_PIN);//Receive on pin IR_RX_PIN
|
||||
IRdecode My_Decoder;
|
||||
|
||||
void setup()
|
||||
{
|
||||
My_Receiver.enableIRIn(); // Start the receiver
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
DigiUSB.begin();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if(My_Receiver.GetResults(&My_Decoder))
|
||||
{
|
||||
My_Decoder.decode();
|
||||
switch(My_Decoder.value)
|
||||
{
|
||||
case BUTTON_OFF:
|
||||
digitalWrite(LED_PIN, LOW);
|
||||
break;
|
||||
case BUTTON_ON:
|
||||
digitalWrite(LED_PIN, HIGH);
|
||||
break;
|
||||
default:break;
|
||||
}
|
||||
My_Receiver.resume();
|
||||
DigiUSB.println(My_Decoder.value, HEX);
|
||||
}
|
||||
if(DigiUSB.available())
|
||||
{
|
||||
DigiUSB.read();
|
||||
}
|
||||
DigiUSB.refresh();
|
||||
}
|
||||
|
@@ -0,0 +1,201 @@
|
||||
#include <TinySoftPwm.h>
|
||||
#include <IRLib.h>
|
||||
/*
|
||||
_____ ____ __ _ ____ _ _ _ _
|
||||
| __ \ / __ \ | \ | | / __ \ | | | | | | | |
|
||||
| |__| | | / \_| | . \ | | / / \ \ | | | | \ \ / /
|
||||
| _ / | | _ | |\ \| | | |__| | | | | | \ ' /
|
||||
| | \ \ | \__/ | | | \ ' | | __ | \ \/ / | |
|
||||
|_| \_\ \____/ |_| \__| |_| |_| \__/ |_| 2013
|
||||
|
||||
http://p.loussouarn.free.fr
|
||||
|
||||
*************************************************
|
||||
* Optimized <IRLib> library Controller Demo *
|
||||
*************************************************
|
||||
|
||||
This sketch allows you to use the Digispark as an IR RGB Controller.
|
||||
This sketch is designed to used low cost 24 keys IR Remote Control for RGB strip LED,
|
||||
but you can adapt it to your own IR Remote Control.
|
||||
|
||||
Sensor wiring: (Warning: the wiring may vary depending of the model of IR sensor)
|
||||
=============
|
||||
.-------.
|
||||
| ___ |
|
||||
| / \ | InfraRed
|
||||
| \___/ | Sensor
|
||||
| |
|
||||
'+--+--+'
|
||||
| | | 100
|
||||
P5 <----' | '--+---###--- +5V
|
||||
| |
|
||||
| '==='4.7uF
|
||||
| |
|
||||
'--+--'
|
||||
|
|
||||
GND
|
||||
|
||||
/* P0, P1 and P2 shall be declared in Digispark-Arduino-1.0.x/libraries/TinySoftPwm.h */
|
||||
#define LED_GREEN_PIN 0
|
||||
#define LED_RED_PIN 1
|
||||
#define LED_BLUE_PIN 2
|
||||
|
||||
#define IR_RX_PIN 5
|
||||
|
||||
#define CODE_OFF 0xF740BF
|
||||
#define CODE_ON 0xF7C03F
|
||||
#define CODE_BRIGHT_MINUS 0xF7807F
|
||||
#define CODE_BRIGHT_PLUS 0xF700FF
|
||||
|
||||
#define CODE_FLASH 0xF7D02F
|
||||
#define CODE_STROBE 0xF7F00F
|
||||
#define CODE_FADE 0xF7C837
|
||||
#define CODE_SMOOTH 0xF7E817
|
||||
|
||||
#define CODE_RED 0xF720DF
|
||||
#define CODE_GREEN 0xF7A05F
|
||||
#define CODE_BLUE 0xF7609F
|
||||
#define CODE_WHITE 0xF7E01F
|
||||
|
||||
#define CODE_ORANGE 0xF710EF
|
||||
#define CODE_ORANGE_LIGTH 0xF730CF
|
||||
#define CODE_BROWN 0xF708F7
|
||||
#define CODE_YELLOW 0xF728D7
|
||||
|
||||
#define CODE_GREEN_LIGTH 0xF7906F
|
||||
#define CODE_GREEN_BLUE1 0xF7B04F
|
||||
#define CODE_GREEN_BLUE2 0xF78877
|
||||
#define CODE_GREEN_BLUE3 0xF7A857
|
||||
|
||||
#define CODE_BLUE_LIGTH 0xF750AF
|
||||
#define CODE_PURPLE_DARK 0xF7708F
|
||||
#define CODE_PURPLE_LIGTH 0xF748B7
|
||||
#define CODE_PINK 0xF76897
|
||||
|
||||
#define BRIGTH_STEP 10
|
||||
#define CODE_REPEAT 0xFFFFFFFF
|
||||
|
||||
IRrecv My_Receiver(IR_RX_PIN);//Receive on pin IR_RX_PIN
|
||||
IRdecode My_Decoder;
|
||||
|
||||
uint8_t PwmRed=0, PwmGreen=0, PwmBlue=0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
My_Receiver.enableIRIn(); // Start the receiver
|
||||
pinMode(LED_RED_PIN, OUTPUT);
|
||||
TinySoftPwm_begin(255,0);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
static uint32_t StartUs=micros(), LastIrCode=0;
|
||||
|
||||
if(My_Receiver.GetResults(&My_Decoder))
|
||||
{
|
||||
My_Decoder.decode();
|
||||
if(My_Decoder.value==REPEAT && LastIrCode)
|
||||
{
|
||||
My_Decoder.value=LastIrCode;
|
||||
}
|
||||
switch(My_Decoder.value)
|
||||
{
|
||||
case CODE_BRIGHT_MINUS:
|
||||
Tune(&PwmRed, -BRIGTH_STEP);
|
||||
Tune(&PwmGreen, -BRIGTH_STEP);
|
||||
Tune(&PwmBlue, -BRIGTH_STEP);
|
||||
LastIrCode=CODE_BRIGHT_MINUS;
|
||||
break;
|
||||
case CODE_BRIGHT_PLUS:
|
||||
if(PwmRed) Tune(&PwmRed, BRIGTH_STEP);
|
||||
if(PwmGreen) Tune(&PwmGreen, BRIGTH_STEP);
|
||||
if(PwmBlue) Tune(&PwmBlue, BRIGTH_STEP);
|
||||
LastIrCode=CODE_BRIGHT_PLUS;
|
||||
break;
|
||||
default:
|
||||
LastIrCode=0; /* No repeat for the following codes */
|
||||
switch(My_Decoder.value)
|
||||
{
|
||||
case CODE_OFF:
|
||||
RGB(0x00, 0x00, 0x00);
|
||||
break;
|
||||
case CODE_ON:
|
||||
RGB(0x7A, 0x00, 0xBF);
|
||||
break;
|
||||
case CODE_RED: RGB(0xFF, 0x00, 0x00);break;
|
||||
case CODE_GREEN: RGB(0x00, 0xFF, 0x00);break;
|
||||
case CODE_BLUE: RGB(0x00, 0x00, 0xFF);break;
|
||||
case CODE_WHITE: RGB(0xFF, 0xFF, 0xFF);break;
|
||||
|
||||
case CODE_ORANGE: RGB(0xFF, 0x7F, 0x00); break;
|
||||
case CODE_ORANGE_LIGTH: RGB(0xFF, 0xAA, 0x00); break;
|
||||
case CODE_BROWN: RGB(0xFF, 0xD4, 0x00); break;
|
||||
case CODE_YELLOW: RGB(0xFF, 0xFF, 0x00); break;
|
||||
|
||||
case CODE_GREEN_LIGTH: RGB(0x00, 0xFF, 0xAA); break;
|
||||
case CODE_GREEN_BLUE1: RGB(0x00, 0xFF, 0xFF); break;
|
||||
case CODE_GREEN_BLUE2: RGB(0x00, 0xAA, 0xFF); break;
|
||||
case CODE_GREEN_BLUE3: RGB(0x00, 0x55, 0xFF); break;
|
||||
|
||||
case CODE_BLUE_LIGTH: RGB(0x00, 0x00, 0x80); break;
|
||||
case CODE_PURPLE_DARK: RGB(0x3F, 0x00, 0x80); break;
|
||||
case CODE_PURPLE_LIGTH: RGB(0x7A, 0x00, 0xBF); break;
|
||||
case CODE_PINK: RGB(0xFF, 0x00, 0xFF); break;
|
||||
|
||||
case CODE_FLASH: /* to be implemented */break;
|
||||
case CODE_STROBE: /* to be implemented */break;
|
||||
case CODE_FADE: /* to be implemented */break;
|
||||
case CODE_SMOOTH: /* to be implemented */break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
My_Receiver.resume();
|
||||
TinySoftPwm_analogWrite(LED_RED_PIN, GammaCorrection(PwmRed));
|
||||
TinySoftPwm_analogWrite(LED_GREEN_PIN, GammaCorrection(PwmGreen));
|
||||
TinySoftPwm_analogWrite(LED_BLUE_PIN, GammaCorrection(PwmBlue));
|
||||
}
|
||||
/***********************************************************/
|
||||
/* Call TinySoftPwm_process() with a period of 60 us */
|
||||
/* The PWM frequency = 255 x 60 # 15 ms -> F # 65Hz */
|
||||
/* 255 is the first argument passed to TinySoftPwm_begin() */
|
||||
/***********************************************************/
|
||||
if((micros() - StartUs) >= 60)
|
||||
{
|
||||
/* We arrived here every 60 microseconds */
|
||||
StartUs=micros();
|
||||
TinySoftPwm_process(); /* This function shall be called periodically (like here, based on micros(), or in a timer ISR) */
|
||||
}
|
||||
}
|
||||
|
||||
void RGB(uint8_t Red, uint8_t Green, uint8_t Blue)
|
||||
{
|
||||
PwmRed=Red;
|
||||
PwmGreen=Green;
|
||||
PwmBlue=Blue;
|
||||
}
|
||||
|
||||
uint8_t GammaCorrection(uint8_t Pwm)
|
||||
{
|
||||
return((Pwm*Pwm)>>8);
|
||||
}
|
||||
|
||||
void Tune(uint8_t* Color, int8_t Offset)
|
||||
{
|
||||
if (Offset > 0) {
|
||||
if ( *Color + Offset <= 255) {
|
||||
*Color += Offset;
|
||||
} else {
|
||||
*Color = 255;
|
||||
}
|
||||
} else {
|
||||
if (*Color + Offset >= 0) {
|
||||
*Color += Offset;
|
||||
} else {
|
||||
// *Color = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,48 @@
|
||||
/* Example program for from IRLib – an Arduino library for infrared encoding and decoding
|
||||
* Version 1.0 January 2013
|
||||
* Copyright 2013 by Chris Young http://cyborg5.com
|
||||
* Based on original example sketch for IRremote library
|
||||
* Version 0.11 September, 2009
|
||||
* Copyright 2009 Ken Shirriff
|
||||
* http://arcfn.com
|
||||
*/
|
||||
/*
|
||||
* IRhashdecode - decode an arbitrary IR code.
|
||||
* Instead of decoding using a standard encoding scheme
|
||||
* (e.g. Sony, NEC, RC5), the code is hashed to a 32-bit value.
|
||||
* This should produce a unique 32-bit number however that number cannot be used
|
||||
* to retransmit the same code. This is just a quick and dirty way to detect a unique code
|
||||
* for controlling a device when you don't really care what protocol or values
|
||||
* are being sent.
|
||||
*/
|
||||
|
||||
#include <IRLib.h>
|
||||
|
||||
int RECV_PIN = 11;
|
||||
IRrecv My_Receiver(RECV_PIN);
|
||||
IRdecode My_Decoder;
|
||||
IRdecodeHash My_Hash_Decoder;
|
||||
|
||||
void setup()
|
||||
{
|
||||
My_Receiver.enableIRIn(); // Start the receiver
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (My_Receiver.GetResults(&My_Decoder)) {//Puts results in My_Decoder
|
||||
//Restart the receiver so it can be capturing another code
|
||||
//while we are working on decoding this one.
|
||||
My_Receiver.resume();
|
||||
My_Hash_Decoder.copyBuf(&My_Decoder);//copy the results to the hash decoder
|
||||
My_Decoder.decode();
|
||||
Serial.print("real decode type:");
|
||||
Serial.print(Pnames(My_Decoder.decode_type));
|
||||
Serial.print(" value: 0x");
|
||||
Serial.print(My_Decoder.value, HEX);
|
||||
My_Hash_Decoder.decode();
|
||||
Serial.print(", hash decode: 0x");
|
||||
Serial.println(My_Hash_Decoder.hash, HEX); // Do something interesting with this value
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,130 @@
|
||||
/* Example program for from IRLib – an Arduino library for infrared encoding and decoding
|
||||
* Version 1.0 January 2013
|
||||
* Copyright 2013 by Chris Young http://cyborg5.com
|
||||
* Based on original example sketch for IRremote library
|
||||
* Version 0.11 September, 2009
|
||||
* Copyright 2009 Ken Shirriff
|
||||
* http://arcfn.com
|
||||
*/
|
||||
/*
|
||||
* IRrecord: record and play back IR signals
|
||||
* An IR detector/demodulator must be connected to the input RECV_PIN.
|
||||
* An IR LED must be connected to the output PWM pin 3.
|
||||
* Unlike the original version of this demo sketch, you need not hook up a pushbutton
|
||||
* Simply send any character from the serial screen to send the recorded code.
|
||||
* Also demonstrates how to use toggle bits which must be controlled outside
|
||||
* the library routines.
|
||||
* The logic is:
|
||||
* If an IR code is received, record it.
|
||||
* If A serial character is received, send the IR code.
|
||||
*/
|
||||
|
||||
#include <IRLib.h>
|
||||
|
||||
int RECV_PIN = 11;
|
||||
|
||||
IRrecv My_Receiver(RECV_PIN);
|
||||
IRdecode My_Decoder;
|
||||
IRsend My_Sender;
|
||||
/*
|
||||
* Because this version of the library separated the receiver from the decoder,
|
||||
* technically you would not need to "store" the code outside the decoder object
|
||||
* for this overly simple example. All of the details would remain in the object.
|
||||
* However we are going to go ahead and store them just to show you how.
|
||||
*/
|
||||
// Storage for the recorded code
|
||||
IRTYPES codeType; // The type of code
|
||||
unsigned long codeValue; // The data bits if type is not raw
|
||||
int codeBits; // The length of the code in bits
|
||||
// These values are only stored if it's an unknown type and we are going to use
|
||||
// raw codes to resend the information.
|
||||
unsigned int rawCodes[RAWBUF]; // The durations if raw
|
||||
int rawCount; //The number of interval samples
|
||||
|
||||
bool GotOne, GotNew;
|
||||
|
||||
void setup()
|
||||
{
|
||||
GotOne=false; GotNew=false;
|
||||
codeType=UNKNOWN;
|
||||
codeValue=0;
|
||||
Serial.begin(9600);
|
||||
Serial.println(F("Send a code from your remote and we will record it."));
|
||||
Serial.println(F("Type any character and press enter. We will send the recorded code."));
|
||||
My_Receiver.enableIRIn(); // Start the receiver
|
||||
}
|
||||
|
||||
// Stores the code for later playback
|
||||
void storeCode(void) {
|
||||
GotNew=true;
|
||||
codeType = My_Decoder.decode_type;
|
||||
if (codeType == UNKNOWN) {
|
||||
Serial.println("Received unknown code, saving as raw");
|
||||
// To store raw codes:
|
||||
// Drop first value (gap)
|
||||
// Convert from ticks to microseconds
|
||||
// Tweak marks shorter, and spaces longer to cancel out IR receiver distortion
|
||||
rawCount = My_Decoder.rawlen-1;
|
||||
for (int i = 1; i <=rawCount; i++) {
|
||||
rawCodes[i - 1] = My_Decoder.Interval_uSec(i);//Converts to microseconds and adjusts for Mark/space
|
||||
};
|
||||
My_Decoder.DumpResults();
|
||||
codeType=UNKNOWN;
|
||||
}
|
||||
else {
|
||||
Serial.print(F("Received "));
|
||||
Serial.print(Pnames(codeType));
|
||||
if (My_Decoder.value == REPEAT) {
|
||||
// Don't record a NEC repeat value as that's useless.
|
||||
Serial.println("repeat; ignoring.");
|
||||
}
|
||||
else {
|
||||
codeValue = My_Decoder.value;
|
||||
codeBits = My_Decoder.bits;
|
||||
}
|
||||
Serial.print(F(" Value:0x"));
|
||||
Serial.println(My_Decoder.value, HEX);
|
||||
}
|
||||
}
|
||||
void sendCode(int repeat) {
|
||||
if(codeType== UNKNOWN) {
|
||||
// Assume 38 KHz
|
||||
My_Sender.IRsendRaw::send(rawCodes,rawCount,38);
|
||||
Serial.println("Sent raw");
|
||||
return;
|
||||
}
|
||||
if( !GotNew ) {//We've already sent this so handle toggle bits
|
||||
if (codeType == RC5) {
|
||||
codeValue ^= 0x0800;
|
||||
}
|
||||
else if (codeType == RC6) {
|
||||
codeValue ^= 0x10000;
|
||||
}
|
||||
}
|
||||
GotNew=false;
|
||||
My_Sender.send(codeType,codeValue,codeBits);
|
||||
Serial.print(F("Sent "));
|
||||
Serial.print(Pnames(codeType));
|
||||
Serial.print(F(" Value:0x"));
|
||||
Serial.println(codeValue, HEX);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (Serial.read() != -1) {
|
||||
if(GotOne) {
|
||||
sendCode(0);
|
||||
My_Receiver.enableIRIn(); // Re-enable receiver
|
||||
}
|
||||
}
|
||||
else if (My_Receiver.GetResults(&My_Decoder)) {
|
||||
//Restart the receiver so it can be capturing another code
|
||||
//while we are working on decoding this one.
|
||||
if(My_Decoder.decode()) {
|
||||
GotOne=true;
|
||||
storeCode();
|
||||
}
|
||||
delay(500);
|
||||
My_Receiver.resume();
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,39 @@
|
||||
/* Example program for from IRLib – an Arduino library for infrared encoding and decoding
|
||||
* Version 1.0 January 2013
|
||||
* Copyright 2013 by Chris Young http://cyborg5.com
|
||||
* Based on original example sketch for IRremote library
|
||||
* Version 0.11 September, 2009
|
||||
* Copyright 2009 Ken Shirriff
|
||||
* http://arcfn.com
|
||||
*/
|
||||
/*
|
||||
* IRLib: IRrecvDump - dump details of IR codes with IRrecv
|
||||
* An IR detector/demodulator must be connected to the input RECV_PIN.
|
||||
*/
|
||||
|
||||
#include <IRLib.h>
|
||||
|
||||
int RECV_PIN = 11;
|
||||
|
||||
IRrecv My_Receiver(RECV_PIN);
|
||||
|
||||
IRdecode My_Decoder;
|
||||
unsigned int Buffer[RAWBUF];
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
My_Receiver.enableIRIn(); // Start the receiver
|
||||
My_Decoder.UseExtnBuf(Buffer);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (My_Receiver.GetResults(&My_Decoder)) {
|
||||
//Restart the receiver so it can be capturing another code
|
||||
//while we are working on decoding this one.
|
||||
My_Receiver.resume();
|
||||
My_Decoder.decode();
|
||||
My_Decoder.DumpResults();
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,25 @@
|
||||
/* Example program for from IRLib – an Arduino library for infrared encoding and decoding
|
||||
* Version 1.0 January 2013
|
||||
* Copyright 2013 by Chris Young http://cyborg5.com
|
||||
* Based on original example sketch for IRremote library
|
||||
* Version 0.11 September, 2009
|
||||
* Copyright 2009 Ken Shirriff
|
||||
* http://arcfn.com
|
||||
*/
|
||||
#include <IRLib.h>
|
||||
|
||||
IRsend My_Sender;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (Serial.read() != -1) {
|
||||
//send a code every time a character is received from the serial port
|
||||
//Sony DVD power A8BCA
|
||||
My_Sender.send(SONY,0xa8bca, 20);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,37 @@
|
||||
/* Example program for from IRLib – an Arduino library for infrared encoding and decoding
|
||||
* Version 1.0 January 2013
|
||||
* Copyright 2013 by Chris Young http://cyborg5.com
|
||||
* Based on original example sketch for IRremote library
|
||||
* Version 0.11 September, 2009
|
||||
* Copyright 2009 Ken Shirriff
|
||||
* http://arcfn.com
|
||||
*/
|
||||
/*
|
||||
* JVC sends repeat codes that are identical to the regular JVC codes
|
||||
* however they have no header. Therefore there is an additional parameter
|
||||
* that tells you whether or not to send as an original code or as a repeat.
|
||||
*
|
||||
* The only device I had to test this protocol was an old JVC VCR. It would only work if at least
|
||||
* 2 frames are sent separated by 45us of "space". All JVC is the same bit length so we use
|
||||
* the third parameter as a to tell it whether or not to send the header.
|
||||
* Once with the third parameter "1" then delay about 50 microseconds and send again
|
||||
* with the third parameter "0".
|
||||
*/
|
||||
|
||||
#include <IRLib.h>
|
||||
|
||||
IRsend My_Sender;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
//send a code every time a character is received from the serial port
|
||||
void loop() {
|
||||
if (Serial.read() != -1) {
|
||||
My_Sender.send(JVC,0xc2d0,1); delayMicroseconds (50);
|
||||
My_Sender.send(JVC,0xc2d0,0); delayMicroseconds (50);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,50 @@
|
||||
#include <IRLib.h>
|
||||
|
||||
IRsend My_Sender;
|
||||
|
||||
int protocol;
|
||||
long code;
|
||||
int bits;
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
long parseHex (void) {
|
||||
long Value=0; char C;delay(100);
|
||||
while (Serial.available()>0) {
|
||||
C= tolower(Serial.read());
|
||||
if ((C>='0')&&(C<='9'))
|
||||
C=C-'0';
|
||||
else
|
||||
if ((C>='a') && (C<='f'))
|
||||
C=C-'a'+10;
|
||||
else
|
||||
return Value;
|
||||
Value= C+(Value<<4);
|
||||
};
|
||||
return Value;
|
||||
}
|
||||
void parseDelimiter () {
|
||||
char C;
|
||||
while(Serial.available()>0) {
|
||||
C=tolower(Serial.peek());
|
||||
if( (C>='0') && (C<='9') )return;
|
||||
if( (C>='a') && (C<='f') )return;
|
||||
C=Serial.read();//throwaway delimiters
|
||||
delay (5);
|
||||
}
|
||||
}
|
||||
// enum IRTYPES {UNKNOWN, NEC, SONY, RC5, RC6, PANASONIC_OLD, JVC, NECX, HASH_CODE, LAST_PROTOCOL=HASH_CODE};
|
||||
|
||||
void loop() {
|
||||
if (Serial.available ()>0) {
|
||||
protocol = Serial.parseInt (); parseDelimiter();
|
||||
code = parseHex (); parseDelimiter();
|
||||
bits = Serial.parseInt (); parseDelimiter();
|
||||
/* Serial.print("Prot:"); Serial.print(protocol);
|
||||
Serial.print(" Code:"); Serial.print(code,HEX);
|
||||
Serial.print(" Bits:"); Serial.println(bits);
|
||||
*/
|
||||
My_Sender.send(IRTYPES(protocol), code, bits);
|
||||
}
|
||||
}
|
@@ -0,0 +1,133 @@
|
||||
# IRLib demo script
|
||||
# version 1.0 by Chris Young http://tech.cyborg5.com/irlib/
|
||||
# Displays a "Virtual remote" on your screen. Clicking on the
|
||||
# buttons sends serial datato the Arduino which in turn
|
||||
# since IR signals to a cable box in TV.
|
||||
|
||||
# Import all of the necessary pieces of code
|
||||
import serial, sys, pygame, pygame.mixer
|
||||
from pygame.locals import *
|
||||
|
||||
# You will have to edit this to the proper port and speed
|
||||
ser = serial.Serial('COM4', 9600)
|
||||
|
||||
pygame.init()
|
||||
# Established screen size, size of buttons and position
|
||||
size = width, height = 400, 768
|
||||
button_size=54; button_offset=71
|
||||
button_x1=65;button_y1=39
|
||||
max_rows=10; max_columns=4
|
||||
|
||||
# Specify a font. I'm using Arial narrow bold from my Windows
|
||||
# font folder. However the default font shown below also works.
|
||||
myfont =pygame.font.Font ("c:/windows/fonts/ARIALNB.TTF",30)
|
||||
#myfont=pygame.font.Font(None,36)
|
||||
|
||||
# These are the text labels that will appear on each button
|
||||
label_text=("TVp", "CBp", "P^", "Pv",\
|
||||
"<<", ">", ">>", "->",\
|
||||
"Rec", "=", "s", "<-",\
|
||||
"Gd", "^", "Fav", "Inf",\
|
||||
|
||||
"<", "sel", ">", "Lis",\
|
||||
"ret", "v", "Prv", "Mnu",\
|
||||
"1", "2", "3", "Ch+",\
|
||||
|
||||
"4", "5", "6", "Ch-",\
|
||||
"7", "8", "9", "Vol+",\
|
||||
"Pip", "0", "Mut", "Vol-",\
|
||||
)
|
||||
# Each of these 40 strings of text correspond to the
|
||||
# protocol in code which will be sent over the USB serial
|
||||
# to the Arduino. The first number is the protocol number.
|
||||
# See the defined protocols in "IRLib.h"for the
|
||||
# enum IRTYPES at about line 50. This example uses
|
||||
# protocol 3 which is "RC5" used by my Magnavox TV
|
||||
# and protocol 5 "PANASONIC_OLD" used by my Scientific
|
||||
# Atlantic SA 8300 DVR. The protocol number is followed by
|
||||
# the hex code to be transmitted. That is followed by the
|
||||
# number of bits. Note that the PANASONIC_OLD protocol
|
||||
# does not need the number of bits specified so they are omitted.
|
||||
IR_Codes= ("3,180c,13","5,37c107","5,36d924","5,37d904",\
|
||||
"5,37291a","5,37990c","5,36293a","5,36b129",\
|
||||
"5,375914","5,374117","5,365934","5,37c906",\
|
||||
"5,36c127","5,36812f","5,37f101","5,36213b",\
|
||||
|
||||
"5,37810f","5,366133","5,364137","5,36c926",\
|
||||
"5,366932","5,37a10b","5,36e123","5,373918",\
|
||||
"5,36113d","5,37111d","5,36912d","5,377111",\
|
||||
|
||||
"5,37910d","5,365135","5,375115","5,36f121",\
|
||||
"5,36d125","5,37d105","5,363139","3,1810,13",\
|
||||
"5,37b908","5,373119","3,180d,13","3,1811,13",\
|
||||
)
|
||||
# This function gets called to shut everything down
|
||||
def Finished():
|
||||
pygame.quit()
|
||||
sys.exit()
|
||||
|
||||
# Gets the button index based on mouse position. Returned
|
||||
# value is from 0 to 39 (number of buttons-1)
|
||||
# Returns -1 if you are not over a button.
|
||||
def ComputeButton():
|
||||
mx,my=pygame.mouse.get_pos()
|
||||
mx=mx-button_x1
|
||||
my=my-button_y1
|
||||
bx=mx/button_offset; by=my/button_offset
|
||||
if bx<0 or bx>=max_columns:return -1
|
||||
if by<0 or by> max_rows:return -1
|
||||
if (mx%button_offset)>button_size:return -1
|
||||
if (my%button_offset)>button_size:return -1
|
||||
return bx+by*max_columns
|
||||
|
||||
# Blits the button text from button number "i"
|
||||
# onto the specified layer using the specified color.
|
||||
def Show_Text(i,Layer,color=(0,0,0)):
|
||||
t=label_text[i]
|
||||
label = myfont.render (t,1,color)
|
||||
labelpos= label.get_rect()
|
||||
labelpos.centerx=button_x1+button_size/2+i%max_columns*button_offset
|
||||
labelpos.centery=button_y1+button_size/2+i/max_columns*button_offset
|
||||
Layer.blit(label,labelpos)
|
||||
|
||||
# Create the screen and load the background image.
|
||||
screen = pygame.display.set_mode(size)
|
||||
bg = pygame.image.load("remotebg.png")
|
||||
|
||||
# Blit black text labels onto the background image
|
||||
for i in range (max_rows*max_columns):
|
||||
Show_Text(i, bg)
|
||||
# Copy the background to the display
|
||||
screen.blit(bg,(0,0))
|
||||
pygame.display.flip()
|
||||
|
||||
# Load the clicking sound
|
||||
Click=pygame.mixer.Sound("click.wav")
|
||||
|
||||
# Used to detect when the mouse hovers over a different button
|
||||
previous=-1
|
||||
|
||||
while 1:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
Finished()
|
||||
elif event.type == KEYDOWN and event.key == K_ESCAPE:
|
||||
Finished ()
|
||||
elif event.type == MOUSEBUTTONDOWN:
|
||||
i=ComputeButton() #which button did we click
|
||||
if i>=0:
|
||||
Click.play() #play the sound
|
||||
ser.write(IR_Codes[i]) #send the codes
|
||||
elif event.type==MOUSEMOTION:
|
||||
i=ComputeButton() #which button are we over
|
||||
if i!=previous: #difference in the last one?
|
||||
if i>=0: #turn it red
|
||||
Show_Text(i,screen,(255,0,0))
|
||||
else: #or put it back the way it was
|
||||
screen.blit(bg,(0,0))
|
||||
previous=i
|
||||
pygame.display.flip() #update the display
|
||||
# That's all folks
|
||||
|
||||
|
||||
|
@@ -0,0 +1,62 @@
|
||||
//POV-Ray source to generate the background image for IRserial_remote
|
||||
// create rectangular areas with rounded corners for use as
|
||||
// buttons and background objects.
|
||||
|
||||
// Render at 1024x768 then crop 312 pixels from each side
|
||||
// leaving 400x768 final image.
|
||||
#declare Area=15; //size of area lights
|
||||
#declare CR=0.1; //corner radius
|
||||
#declare ER= 0.5; //edge radius
|
||||
#declare CX= 3; //width from corner to corner
|
||||
#declare CY= 7.75; //height from corner to corner
|
||||
#declare BZ=-ER; //Z offset for buttons
|
||||
|
||||
plane {z,0 pigment{rgb<0.8,0.85,1>*0.8}}//background
|
||||
|
||||
#macro Thing (ER,CR,CX,CY,T)
|
||||
#local Corner=
|
||||
union {
|
||||
torus {CR,ER rotate x*90}
|
||||
cylinder {ER*z,-ER*z,CR}
|
||||
}
|
||||
union {
|
||||
object{Corner translate< CX,CY,0>}
|
||||
object{Corner translate<-CX,CY,0>}
|
||||
object{Corner translate< CX,-CY,0>}
|
||||
object{Corner translate<-CX,-CY,0>}
|
||||
cylinder{CY*y,-CY*y,ER translate<-CX-CR,0,0>}
|
||||
cylinder{CY*y,-CY*y,ER translate< CX+CR,0,0>}
|
||||
cylinder{CX*x,-CX*x,ER translate<0,-CY-CR,0>}
|
||||
cylinder{CX*x,-CX*x,ER translate<0, CY+CR,0>}
|
||||
box{<-CX,-CY-CR,-ER><CX,CY+CR,ER>}
|
||||
box{<-CX-CR,-CY,-ER><CX+CR,CY,ER>}
|
||||
texture {T}
|
||||
}
|
||||
#end
|
||||
|
||||
#declare BX= 0.4; #declare BY=BX;//size of the buttons
|
||||
#declare White_Texture=texture{pigment{rgb 1}finish {ambient 0.3}}
|
||||
#declare Blue_Texture=texture{pigment {rgb<0.85,0.9 ,1>}}
|
||||
|
||||
object {Thing(ER,CR,CX,CY, White_Texture)}//main object
|
||||
//loop through the buttons
|
||||
#declare R=-4.5;
|
||||
#while (R<5.5)
|
||||
#declare C=-1.5;
|
||||
#while (C<=1.5)
|
||||
object{Thing(0.1,0.2,(BX*0.8),(BY*0.8), Blue_Texture)
|
||||
translate <C*BX*4,R*BY*4,BZ>
|
||||
}
|
||||
#declare C=C+1;
|
||||
#end
|
||||
#declare R=R+1;
|
||||
#end
|
||||
|
||||
|
||||
light_source{<50,50,-100>*5 color 0.8
|
||||
#if (Area)area_light x*Area,y*Area,9,9#end
|
||||
}
|
||||
light_source{<0,0,-400>*3 rgb 1}
|
||||
|
||||
camera{orthographic location <0,0,-120> look_at <0,0,0> angle 11 }
|
||||
//That's all folks!
|
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 48 KiB |
@@ -0,0 +1,68 @@
|
||||
/* Example program for from IRLib – an Arduino library for infrared encoding and decoding
|
||||
* Version 1.1 April 2013 by Chris Young http://cyborg5.com
|
||||
* "IRservo" Control a servo using an IR remote
|
||||
*/
|
||||
#include <IRLib.h>
|
||||
#include <Servo.h>
|
||||
// You will have to set these values depending on the protocol
|
||||
// and remote codes that you are using. These are from my Sony DVD/VCR
|
||||
#define MY_PROTOCOL SONY
|
||||
#define RIGHT_ARROW 0x86bca //Move several clockwise
|
||||
#define LEFT_ARROW 0x46bca //Move servo counterclockwise
|
||||
#define SELECT_BUTTON 0xd0bca //Center the servo
|
||||
#define UP_ARROW 0x42bca //Increased number of degrees servo moves
|
||||
#define DOWN_ARROW 0xc2bca //Decrease number of degrees servo moves
|
||||
#define BUTTON_0 0x90bca //Pushing buttons 0-9 moves to fix positions
|
||||
#define BUTTON_1 0x00bca // each 20 degrees greater
|
||||
#define BUTTON_2 0x80bca
|
||||
#define BUTTON_3 0x40bca
|
||||
#define BUTTON_4 0xc0bca
|
||||
#define BUTTON_5 0x20bca
|
||||
#define BUTTON_6 0xa0bca
|
||||
#define BUTTON_7 0x60bca
|
||||
#define BUTTON_8 0xe0bca
|
||||
#define BUTTON_9 0x10bca
|
||||
|
||||
IRrecv My_Receiver(11);//Receive on pin 11
|
||||
IRdecode My_Decoder;
|
||||
Servo My_Servo; // create servo object to control a servo
|
||||
int pos; // variable to store the servo position
|
||||
int Speed; // Number of degrees to move each time a left/right button is pressed
|
||||
|
||||
void setup()
|
||||
{
|
||||
My_Receiver.No_Output();//Turn off any unused IR LED output circuit
|
||||
My_Servo.attach(9); // attaches the servo on pin 9 to the servo object
|
||||
pos = 90; // start at midpoint 90 degrees
|
||||
Speed = 3; // servo moves 3 degrees each time left/right is pushed
|
||||
My_Servo.write(pos); // Set initial position
|
||||
My_Receiver.enableIRIn(); // Start the receiver
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (My_Receiver.GetResults(&My_Decoder)) {
|
||||
My_Decoder.decode();
|
||||
if(My_Decoder.decode_type==MY_PROTOCOL) {
|
||||
switch(My_Decoder.value) {
|
||||
case LEFT_ARROW: pos=min(180,pos+Speed); break;
|
||||
case RIGHT_ARROW: pos=max(0,pos-Speed); break;
|
||||
case SELECT_BUTTON: pos=90; break;
|
||||
case UP_ARROW: Speed=min(10, Speed+1); break;
|
||||
case DOWN_ARROW: Speed=max(1, Speed-1); break;
|
||||
case BUTTON_0: pos=0*20; break;
|
||||
case BUTTON_1: pos=1*20; break;
|
||||
case BUTTON_2: pos=2*20; break;
|
||||
case BUTTON_3: pos=3*20; break;
|
||||
case BUTTON_4: pos=4*20; break;
|
||||
case BUTTON_5: pos=5*20; break;
|
||||
case BUTTON_6: pos=6*20; break;
|
||||
case BUTTON_7: pos=7*20; break;
|
||||
case BUTTON_8: pos=8*20; break;
|
||||
case BUTTON_9: pos=9*20; break;
|
||||
}
|
||||
My_Servo.write(pos); // tell servo to go to position in variable 'pos'
|
||||
}
|
||||
My_Receiver.resume();
|
||||
}
|
||||
}
|
@@ -0,0 +1,120 @@
|
||||
/* Example program for from IRLib – an Arduino library for infrared encoding and decoding
|
||||
* Version 1.0 January 2013
|
||||
* Copyright 2013 by Chris Young http://cyborg5.com
|
||||
* Based on original example sketch for IRremote library
|
||||
* Version 0.11 September, 2009
|
||||
* Copyright 2009 Ken Shirriff
|
||||
* http://arcfn.com
|
||||
*/
|
||||
/*
|
||||
* This example demonstrates how to extend this library to add a new protocol
|
||||
* without actually modifying or recompiling the library itself. It implements a 36 bit
|
||||
* Samsung protocol that is used on a Blu-ray player that I own.
|
||||
* Because a 36 bit value will not fit in the value field (only 32 bits) we have to create
|
||||
* a second value field.
|
||||
*/
|
||||
#include <IRLib.h>
|
||||
#include <IRLibMatch.h>
|
||||
|
||||
int RECV_PIN = 11;
|
||||
|
||||
IRrecv My_Receiver(RECV_PIN);
|
||||
#define SAMSUNG36 (LAST_PROTOCOL+1) //Unfortunately cannot extend an enum. This is the best we can do.
|
||||
|
||||
/*Is the value in this if statement is "1" then we will extend the base decoder.
|
||||
*The result is this will only decode Samsung 36 and no others.
|
||||
*If the value is "0" we will extend the all-inclusive decoder.
|
||||
*Try changing this value and note the effect on code size when compiling.
|
||||
*/
|
||||
#if(1)
|
||||
#define MY_BASE IRdecodeBase
|
||||
#else
|
||||
#define MY_BASE IRdecode
|
||||
#endif
|
||||
class IRdecodeSamsung36: public virtual MY_BASE{
|
||||
public:
|
||||
bool decode(void);
|
||||
unsigned int value2;
|
||||
void Reset(void);
|
||||
void DumpResults(void);
|
||||
private:
|
||||
bool GetBit(void);
|
||||
int offset;
|
||||
unsigned long data;
|
||||
};
|
||||
void IRdecodeSamsung36::Reset(void) {
|
||||
MY_BASE::Reset();//respect your parents
|
||||
value2=0;
|
||||
};
|
||||
|
||||
bool IRdecodeSamsung36::GetBit(void) {
|
||||
if (!MATCH_MARK (rawbuf[offset],500)) return DATA_MARK_ERROR;
|
||||
offset++;
|
||||
if (MATCH_SPACE(rawbuf[offset],1500)) {
|
||||
data = (data << 1) | 1;
|
||||
}
|
||||
else if (MATCH_SPACE (rawbuf[offset],500)) {
|
||||
data <<= 1;
|
||||
}
|
||||
else return DATA_SPACE_ERROR;
|
||||
offset++;
|
||||
return true;
|
||||
};
|
||||
/*
|
||||
* According to http://www.hifi-remote.com/johnsfine/DecodeIR.html#Samsung36
|
||||
* The IRP notation for this protocol is:
|
||||
* {38k,500}<1,-1|1,-3>(9,-9,D:8,S:8,1,-9,E:4,F:8,-68u,~F:8,1,-118)+
|
||||
* This means it uses 38k frequency. Base timing is multiples of 500.
|
||||
* A "0" is mark(500) space(500). A "1" is mark (500) space(1500)
|
||||
* The header is mark(4500) space(4500).
|
||||
* The header is followed by 16 bits (8 device, 8 sub device)
|
||||
* This is followed by a mark(500) space(4500).
|
||||
* This is followed by 12 more bits (4+8)
|
||||
* This is followed by 68us ofspace. Followed by eight more bits
|
||||
* and a final stop bit.
|
||||
*/
|
||||
bool IRdecodeSamsung36::decode(void) {
|
||||
if(MY_BASE::decode()) return true;
|
||||
ATTEMPT_MESSAGE(F("Samsung36"));
|
||||
if (rawlen != 78) return RAW_COUNT_ERROR;
|
||||
if (!MATCH_MARK(rawbuf[1],4500)) return HEADER_MARK_ERROR;
|
||||
if (!MATCH_SPACE(rawbuf[2],4500)) return HEADER_SPACE_ERROR;
|
||||
offset=3; data=0;
|
||||
//Get first 18 bits
|
||||
while (offset < 16*2+2) if(!GetBit()) return false;
|
||||
//Skip middle header
|
||||
if (!MATCH_MARK(rawbuf[offset],500)) return DATA_MARK_ERROR;
|
||||
offset++;
|
||||
if (!MATCH_SPACE(rawbuf[offset],4500)) return DATA_SPACE_ERROR;
|
||||
//save first 18 bits in "value" and reset data
|
||||
offset++; value=data; data=0;
|
||||
rawbuf[62]=(rawbuf[62]*USECPERTICK-68)/USECPERTICK;
|
||||
while(offset<77)if(!GetBit()) return false;
|
||||
bits =36;//set bit length
|
||||
value2 = data;//put remaining bits in value2
|
||||
decode_type= static_cast<IRTYPES>SAMSUNG36;
|
||||
return true;
|
||||
};
|
||||
void IRdecodeSamsung36::DumpResults(void){
|
||||
if(decode_type==SAMSUNG36) {
|
||||
Serial.print(F("Decoded Samsung36: Value1:")); Serial.print(value, HEX);
|
||||
Serial.print(F(": Value2:")); Serial.print(value2, HEX);
|
||||
};
|
||||
MY_BASE::DumpResults();
|
||||
};
|
||||
IRdecodeSamsung36 My_Decoder;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
My_Receiver.enableIRIn(); // Start the receiver
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (My_Receiver.GetResults(&My_Decoder)) {
|
||||
My_Decoder.decode();
|
||||
My_Decoder.DumpResults();
|
||||
My_Receiver.resume();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user