For what its worth, here's my hacked up working sketch. I'll see if I can find the globe still and maybe take a picture of my base IR short and my replacement IR setup.
Code:
int ir_pin = 8; //Sensor pin 1 wired through a 220 ohm resistor
int led_pin = 12; //"Ready to Receive" flag, not needed but nice
int debug = 1; //Serial connection must be started to debug
int start_bit = 2400; //Start bit threshold (Microseconds)
int bin_1 = 0; //Binary 1 threshold (Microseconds)
int bin_0_start = 760; //Binary 0 threshold (Microseconds)
int bin_0 = bin_0_start; //Binary 0 threshold (Microseconds)
int bin_0_tweak = 0; //Binary 0 threshold (Microseconds)
int searchSize = 30;
int dataOut = 0;
int guardTime = 0;
int loopCount = 0;
int switchPin = 10;
bool lastSwitchState;
bool currentSwitchState;
bool ledState;
void setup() {
pinMode(led_pin, OUTPUT); //This shows when we're ready to recieve
pinMode(ir_pin, OUTPUT);
digitalWrite(led_pin, LOW); //not ready yet
digitalWrite(ir_pin, LOW); //not ready yet
Serial.begin(9600);
pinMode(switchPin, INPUT);
lastSwitchState = digitalRead(switchPin);
ledState = LOW;
}
void loop() {
checkButton();
}
int sendIRKey(int dataOut) {
int data[8];
digitalWrite(led_pin, HIGH); //Ok, i'm ready to send
for (int i=0; i<8; i++)
//data[i] = dataOut >> (i & B1); //encode data as '1' or '0'
if (dataOut & (B1<<i)) {
data[i] = 1;
} else {
data[i] = 0;
}
// send startbit
// oscillationWrite(ir_pin, start_bit);
// send separation bit
//digitalWrite(ir_pin, HIGH);
//delayMicroseconds(guardTime);
// startTime = millis();
// send the whole string of data
for (int i=7; i>=0; i--) {
//digitalWrite(ir_pin, LOW);
//if (data[i] == 0) delayMicroseconds(bin_0);
//else delayMicroseconds(bin_1);
if (data[i] == 0) {
oscillationWrite(ir_pin, bin_0);
} else {
// oscillationWrite(ir_pin, bin_1);
digitalWrite(ir_pin, LOW);
delayMicroseconds(1010 - bin_1);
}
// Serial.print(data[i]);
// send separation bit
// digitalWrite(ir_pin, HIGH);
// delayMicroseconds(guardTime);
}
/*
endTime = millis();
duration = endTime - startTime;
Serial.print(' ');
Serial.print(duration);
Serial.println();
*/
digitalWrite(led_pin, LOW); //done sending
// return dataOut; //Return key number
}
// this will write an oscillation at 38KHz for a certain time in useconds
void oscillationWrite(int pin, int time) {
for(int i = 0; i <= time/26; i++) {
digitalWrite(pin, HIGH);
delayMicroseconds(13);
digitalWrite(pin, LOW);
delayMicroseconds(13);
}
}
void checkButton() {
currentSwitchState = digitalRead(switchPin);
Serial.println(currentSwitchState);
if (currentSwitchState != lastSwitchState) {
if (currentSwitchState == LOW) {
// button depressed
sendSignal();
}
delay(50);
}
lastSwitchState = currentSwitchState;
}
void sendSignal() {
sendIRKey(0x01);
//sendIRKey(0x48); // H
//sendIRKey(0x49); // I
/*
sendIRKey(0x48); // H
sendIRKey(0x45); // E
sendIRKey(0x4C); // L
sendIRKey(0x4C); // L
sendIRKey(0x4F); // O
sendIRKey(0x20); //
sendIRKey(0x57); // W
sendIRKey(0x4F); // O
sendIRKey(0x52); // R
sendIRKey(0x4C); // L
sendIRKey(0x44); // D
*/
/*
bin_0_tweak++;
if (bin_0_tweak > searchSize) {
bin_1++;
if (bin_1 > searchSize) {
bin_1 = 0;
}
bin_0_tweak = 0;
}
bin_0 = bin_0_start - bin_0_tweak;
Serial.print("bin_0: ");
Serial.print(bin_0);
Serial.print(" bin_1: ");
Serial.println(bin_1);
*/
delay(100);
}
int led_pin = 12; //"Ready to Receive" flag, not needed but nice
int debug = 1; //Serial connection must be started to debug
int start_bit = 2400; //Start bit threshold (Microseconds)
int bin_1 = 0; //Binary 1 threshold (Microseconds)
int bin_0_start = 760; //Binary 0 threshold (Microseconds)
int bin_0 = bin_0_start; //Binary 0 threshold (Microseconds)
int bin_0_tweak = 0; //Binary 0 threshold (Microseconds)
int searchSize = 30;
int dataOut = 0;
int guardTime = 0;
int loopCount = 0;
int switchPin = 10;
bool lastSwitchState;
bool currentSwitchState;
bool ledState;
void setup() {
pinMode(led_pin, OUTPUT); //This shows when we're ready to recieve
pinMode(ir_pin, OUTPUT);
digitalWrite(led_pin, LOW); //not ready yet
digitalWrite(ir_pin, LOW); //not ready yet
Serial.begin(9600);
pinMode(switchPin, INPUT);
lastSwitchState = digitalRead(switchPin);
ledState = LOW;
}
void loop() {
checkButton();
}
int sendIRKey(int dataOut) {
int data[8];
digitalWrite(led_pin, HIGH); //Ok, i'm ready to send
for (int i=0; i<8; i++)
//data[i] = dataOut >> (i & B1); //encode data as '1' or '0'
if (dataOut & (B1<<i)) {
data[i] = 1;
} else {
data[i] = 0;
}
// send startbit
// oscillationWrite(ir_pin, start_bit);
// send separation bit
//digitalWrite(ir_pin, HIGH);
//delayMicroseconds(guardTime);
// startTime = millis();
// send the whole string of data
for (int i=7; i>=0; i--) {
//digitalWrite(ir_pin, LOW);
//if (data[i] == 0) delayMicroseconds(bin_0);
//else delayMicroseconds(bin_1);
if (data[i] == 0) {
oscillationWrite(ir_pin, bin_0);
} else {
// oscillationWrite(ir_pin, bin_1);
digitalWrite(ir_pin, LOW);
delayMicroseconds(1010 - bin_1);
}
// Serial.print(data[i]);
// send separation bit
// digitalWrite(ir_pin, HIGH);
// delayMicroseconds(guardTime);
}
/*
endTime = millis();
duration = endTime - startTime;
Serial.print(' ');
Serial.print(duration);
Serial.println();
*/
digitalWrite(led_pin, LOW); //done sending
// return dataOut; //Return key number
}
// this will write an oscillation at 38KHz for a certain time in useconds
void oscillationWrite(int pin, int time) {
for(int i = 0; i <= time/26; i++) {
digitalWrite(pin, HIGH);
delayMicroseconds(13);
digitalWrite(pin, LOW);
delayMicroseconds(13);
}
}
void checkButton() {
currentSwitchState = digitalRead(switchPin);
Serial.println(currentSwitchState);
if (currentSwitchState != lastSwitchState) {
if (currentSwitchState == LOW) {
// button depressed
sendSignal();
}
delay(50);
}
lastSwitchState = currentSwitchState;
}
void sendSignal() {
sendIRKey(0x01);
//sendIRKey(0x48); // H
//sendIRKey(0x49); // I
/*
sendIRKey(0x48); // H
sendIRKey(0x45); // E
sendIRKey(0x4C); // L
sendIRKey(0x4C); // L
sendIRKey(0x4F); // O
sendIRKey(0x20); //
sendIRKey(0x57); // W
sendIRKey(0x4F); // O
sendIRKey(0x52); // R
sendIRKey(0x4C); // L
sendIRKey(0x44); // D
*/
/*
bin_0_tweak++;
if (bin_0_tweak > searchSize) {
bin_1++;
if (bin_1 > searchSize) {
bin_1 = 0;
}
bin_0_tweak = 0;
}
bin_0 = bin_0_start - bin_0_tweak;
Serial.print("bin_0: ");
Serial.print(bin_0);
Serial.print(" bin_1: ");
Serial.println(bin_1);
*/
delay(100);
}


