Checking in Synchronizer code from Sigrun's dropbox folder
This commit is contained in:
227
dawn/prior-art/Synchronizer_prg1/IR_Get_Code/IR_Get_Code.pde
Normal file
227
dawn/prior-art/Synchronizer_prg1/IR_Get_Code/IR_Get_Code.pde
Normal file
@@ -0,0 +1,227 @@
|
||||
/* IR Remote control
|
||||
* capture a infrared burst from a remote control and generate code template for reproducing that burst
|
||||
* measure the infrared carrier frequency / capture ir pulse train (max 200 pulses )
|
||||
* connect the IR receiver Module (IR_reveiver_schematic.jpg)
|
||||
* to pin 4,5,6,7
|
||||
*
|
||||
*
|
||||
* KHM 2010 / Martin Nawrath
|
||||
* Kunsthochschule fuer Medien Koeln
|
||||
* Academy of Media Arts Cologne
|
||||
*/
|
||||
|
||||
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
|
||||
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
|
||||
|
||||
//! Macro that clears all Timer/Counter1 interrupt flags.
|
||||
#define CLEAR_ALL_TIMER1_INT_FLAGS (TIFR1 = TIFR1)
|
||||
|
||||
|
||||
int pinLed = 13; // LED connected to digital pin 13
|
||||
int pinGND = 4; // Ground for IR reveiver Module
|
||||
int pinVCC = 5; // +5V for IR reveiver Module
|
||||
int pinAIN0= 6; // Analog Comparator In 0 / IR reveiver Module
|
||||
int pinAIN1= 7; // Analog Comparator In 0 / IR reveiver Module
|
||||
int pinTest = 8;
|
||||
unsigned int khz;
|
||||
|
||||
byte bb;
|
||||
byte bba;
|
||||
int cnt;
|
||||
const int maxlen = 300;
|
||||
int codelen;
|
||||
unsigned int timecode[maxlen+5];
|
||||
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(pinLed, OUTPUT); // sets the digital pin as output
|
||||
pinMode(pinTest, OUTPUT);
|
||||
pinMode(pinGND, OUTPUT);
|
||||
pinMode(pinVCC, OUTPUT);
|
||||
pinMode(pinAIN0, INPUT);
|
||||
pinMode(pinAIN1, INPUT);
|
||||
|
||||
|
||||
digitalWrite(pinVCC,1);
|
||||
digitalWrite(pinGND,0);
|
||||
|
||||
|
||||
Serial.begin(115200); // connect to the serial port
|
||||
|
||||
// hardware counter setup ( refer atmega168.pdf chapter 16-bit counter1)
|
||||
TCCR1A=0; // reset timer/counter1 control register A
|
||||
TCCR1B=0; // reset timer/counter1 control register A
|
||||
TCNT1=0; // counter value = 0
|
||||
// set timer/counter1 hardware as counter , counts events on pin T1 ( arduino pin 5)
|
||||
// normal mode, wgm10 .. wgm13 = 0
|
||||
cbi (TCCR1B ,CS10); // no clock
|
||||
cbi (TCCR1B ,CS11);
|
||||
cbi (TCCR1B ,CS12);
|
||||
|
||||
|
||||
// timer2 setup / is used for frequency measurement gatetime generation
|
||||
// timer 2 presaler set to 256 / timer 2 clock = 16Mhz / 256 = 62500 Hz
|
||||
cbi (TCCR2B ,CS20);
|
||||
sbi (TCCR2B ,CS21);
|
||||
sbi (TCCR2B ,CS22);
|
||||
|
||||
//set timer2 to CTC Mode
|
||||
cbi (TCCR2A ,WGM20);
|
||||
sbi (TCCR2A ,WGM21);
|
||||
cbi (TCCR2B ,WGM22);
|
||||
OCR2A = 124; // CTC at top of OCR2A / timer2 interrupt when coun value reaches OCR2A value
|
||||
|
||||
// interrupt control
|
||||
|
||||
// sbi (TIMSK2,OCIE2A); // enable Timer2 Interrupt
|
||||
cbi(ADCSRB,ACME);
|
||||
cbi(ACSR,ACD);
|
||||
cbi(ACSR,ACBG);
|
||||
|
||||
Serial.println(" Infrared code detector");
|
||||
while ((ACSR & 32) == 0) {
|
||||
}
|
||||
khz=f_measure();
|
||||
|
||||
Serial.print(khz);
|
||||
Serial.print( " KHz");
|
||||
Serial.println( "");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
|
||||
if (ACSR & 32) { // if IR Signal on pin 5 present
|
||||
|
||||
TCCR1B=0; //timer1 off
|
||||
sbi(TIFR1,TOV1); // clear Timer/Counter 1 overflow flag
|
||||
TCNT1=0; // clear timer1
|
||||
TCCR1B=3; //timer1 prescaler =64;
|
||||
bba=0;
|
||||
|
||||
cnt=1;
|
||||
while ((TIFR1 & 1)==0 ) { // wait for T1 period length 250ms TIFR1 Flag
|
||||
|
||||
bb=0;
|
||||
bb = ACSR & 32; // sample IR Strobe Signal for HIGH/LOW
|
||||
delayMicroseconds(5);
|
||||
bb =bb | ACSR & 32;
|
||||
delayMicroseconds(5);
|
||||
bb =bb | ACSR & 32;
|
||||
delayMicroseconds(5);
|
||||
bb =bb | ACSR & 32;
|
||||
delayMicroseconds(5);
|
||||
bb =bb | ACSR & 32;
|
||||
delayMicroseconds(5);
|
||||
bb =bb | ACSR & 32;
|
||||
delayMicroseconds(5);
|
||||
bb =bb | ACSR & 32;
|
||||
delayMicroseconds(5);
|
||||
bb =bb | ACSR & 32;
|
||||
|
||||
if (bb != bba) { // if IR strobe level changed
|
||||
PORTB = PORTB ^ 32; // LED blink
|
||||
timecode[cnt]=TCNT1; // Store Timecode in Table
|
||||
codelen=TCNT1;
|
||||
cnt++; // Count IR Strobes
|
||||
if (cnt > maxlen) cnt =maxlen-1; // cnt max
|
||||
delayMicroseconds(200);
|
||||
}
|
||||
bba=bb;
|
||||
}
|
||||
timecode[cnt]=0;
|
||||
print_code_template();
|
||||
for (int ii=1;ii < maxlen;ii++) timecode[ii]=0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//******************************************************************
|
||||
// print a code template according to a pressed button
|
||||
void print_code_template(){
|
||||
unsigned int ix,ia,ia1,ia2;
|
||||
char st1[20];
|
||||
unsigned long int w1,w2;
|
||||
Serial.println( "//****************** CODE TEMPLATE FOR IR REMOTE ****************************");
|
||||
|
||||
|
||||
Serial.print( "// IR codelength = ");
|
||||
Serial.print( codelen*4/1000);
|
||||
Serial.print( " ms");
|
||||
Serial.println( "");
|
||||
|
||||
Serial.print( "ICR1 = 16000 /") ;
|
||||
Serial.print(khz);
|
||||
Serial.println( "; // IR carrier frequency") ;
|
||||
for (ix=1;ix < maxlen;ix+=2) {
|
||||
ia=timecode[ix];
|
||||
ia1=timecode[ix+1];
|
||||
ia2=timecode[ix+2];
|
||||
|
||||
if (ia !=0) {
|
||||
Serial.print( "sbi(DDRB,1); delayMicroseconds(");
|
||||
w1=ia1-ia;
|
||||
w1=w1*4;
|
||||
|
||||
sprintf(st1, "%4d );", w1);
|
||||
Serial.print( st1);
|
||||
timecode[ix]=0;
|
||||
|
||||
}
|
||||
if (ia2 !=0) {
|
||||
w2=ia2-ia1;
|
||||
w2=w2*4;
|
||||
Serial.print( " cbi(DDRB,1); delayMicroseconds(" );
|
||||
sprintf(st1, "%4d );", w2);
|
||||
Serial.print( st1);
|
||||
|
||||
timecode[ix]=0;
|
||||
timecode[ix+1]=0;
|
||||
Serial.print( " // ");
|
||||
sprintf(st1, "ix:%3d", ix);
|
||||
Serial.print( st1);
|
||||
sprintf(st1, " ton:%4d", w1);
|
||||
Serial.print( st1);
|
||||
sprintf(st1, " toff:%4d", w2);
|
||||
Serial.print( st1);
|
||||
Serial.println("");
|
||||
}
|
||||
}
|
||||
Serial.print( " cbi(DDRB,1);" );
|
||||
Serial.println("");
|
||||
Serial.println("");
|
||||
Serial.println("");
|
||||
|
||||
}
|
||||
//******************************************************************
|
||||
// measure infrared carrier frequency at pin 6,7 / analog comparator
|
||||
unsigned int f_measure() {
|
||||
|
||||
TCCR1B=0; //timer1 off
|
||||
sbi(TIFR1,TOV1); // clear Timer/Counter 1 overflow flag
|
||||
TCNT1=0; // clear timer1
|
||||
TCCR1B=3; //timer1 prescaler =64;
|
||||
int cnt=0;
|
||||
byte bb,bba;
|
||||
|
||||
while (TCNT1 < 250) {
|
||||
bb=ACSR;
|
||||
if (bb != bba) {
|
||||
cnt++;
|
||||
// PORTB ^= 32;
|
||||
}
|
||||
bba=bb;
|
||||
}
|
||||
cnt=cnt/2;
|
||||
return (cnt);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
/* DVD IR Synchronizer for Toshiba SD590EKE V1.0
|
||||
* Developed for Art Installation "Dawn" by Sigrun Hardardottir<sigrun@stalverk.is>
|
||||
* Code written by Joe Foley <foley@ru.is>
|
||||
* on 2013-09-08
|
||||
*
|
||||
* Based upon Sychronizer code by
|
||||
* KHM 2010 / Martin Nawrath
|
||||
* Kunsthochschule fuer Medien Koeln
|
||||
* Academy of Media Arts Cologne
|
||||
*
|
||||
* Requires libraries:
|
||||
* MsTimer2 http://playground.arduino.cc/Main/MsTimer2
|
||||
* Arduino-IRremote https://github.com/shirriff/Arduino-IRremote
|
||||
*
|
||||
* The IRremote library uses Pin 3 for the Anode (longer pin)
|
||||
* We have made a ground pin on Pin 4 for the Cathode (shorter pin)
|
||||
*/
|
||||
|
||||
|
||||
#include <MsTimer2.h>
|
||||
#include <IRremote.h>
|
||||
|
||||
int pinGND=4; // Longer leg on the IR LED
|
||||
|
||||
int secs;
|
||||
int playtime= 6*60+9; // set here ypur DVD title playtime in sec leave a little extra
|
||||
//int playtime= 10; // testing
|
||||
|
||||
IRsend irsend;
|
||||
|
||||
void setup() {
|
||||
pinMode(pinGND,OUTPUT);
|
||||
Serial.begin(115200);
|
||||
|
||||
Serial.println("Toshiba DVD SD590EKE Synchronizer V1.0");
|
||||
Serial.println("For \"Dawn\" by Sigrun Hardardottir");
|
||||
Serial.println("Code by Joe Foley <foley@ru.is>");
|
||||
Serial.print("Playtime: ");
|
||||
secs=playtime;
|
||||
Serial.print("sec:");
|
||||
Serial.print(secs);
|
||||
Serial.print(" / mm:ss ");
|
||||
Serial.print(secs/60);
|
||||
Serial.print(":");
|
||||
Serial.print(secs % 60);
|
||||
Serial.println("");
|
||||
|
||||
Serial.println("play");
|
||||
send_play();
|
||||
Serial.println("wait 7 seconds");
|
||||
delay(7000);
|
||||
|
||||
secs=playtime;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/********************************************************************/
|
||||
void loop() {
|
||||
Serial.println("Sync");
|
||||
|
||||
Serial.println(" pause");
|
||||
send_pause();
|
||||
delay(2000);
|
||||
|
||||
Serial.println(" skip");
|
||||
send_previous();
|
||||
delay(2000);
|
||||
|
||||
Serial.println(" play");
|
||||
send_play();
|
||||
|
||||
|
||||
for(int t = 0; t < playtime; t++) {
|
||||
Serial.print("sec:");
|
||||
Serial.print(playtime);
|
||||
Serial.print(" / mm:ss ");
|
||||
Serial.print(t/60);
|
||||
Serial.print(":");
|
||||
Serial.print(t % 60);
|
||||
Serial.println("");
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
void send_stop() {
|
||||
// First comes the pre-data bits, then the command code
|
||||
irsend.sendNEC(0xA25D28D7,32);
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
void send_play() {
|
||||
// First comes the pre-data bits, then the command code
|
||||
irsend.sendNEC(0xA25DA857,32);
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
void send_pause() {
|
||||
// First comes the pre-data bits, then the command code
|
||||
irsend.sendNEC(0xA25D00FF, 32);
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
void send_previous() {
|
||||
// First comes the pre-data bits, then the command code
|
||||
irsend.sendNEC(0xA25DC43B, 32);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* IRremote: IRsendDemo - demonstrates sending IR codes with IRsend
|
||||
* An IR LED must be connected to Arduino PWM pin 3.
|
||||
* Version 0.1 July, 2009
|
||||
* Copyright 2009 Ken Shirriff
|
||||
* http://arcfn.com
|
||||
* JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post)
|
||||
*/
|
||||
#include <IRremote.h>
|
||||
|
||||
#define PanasonicAddress 0x4004 // Panasonic address (Pre data)
|
||||
#define PanasonicPower 0x100BCBD // Panasonic Power button
|
||||
|
||||
#define JVCPower 0xC5E8
|
||||
|
||||
IRsend irsend;
|
||||
|
||||
void setup()
|
||||
{
|
||||
}
|
||||
|
||||
void loop() {
|
||||
irsend.sendPanasonic(PanasonicAddress,PanasonicPower); // This should turn your TV on and off
|
||||
|
||||
irsend.sendJVC(JVCPower, 16,0); // hex value, 16 bits, no repeat
|
||||
delayMicroseconds(50); // see http://www.sbprojects.com/knowledge/ir/jvc.php for information
|
||||
irsend.sendJVC(JVCPower, 16,1); // hex value, 16 bits, repeat
|
||||
delayMicroseconds(50);
|
||||
}
|
||||
Reference in New Issue
Block a user