Hacks

Web controlled IR blaster

hello


#include <SPI.h>
#include <Ethernet.h>
#include <IRremote.h>

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = {
  10, 0, 0, 177 };
Server server(23);  

unsigned int c = 0;

//IR sequence to toggle A/C power.
unsigned int ac_toggle_code[] = {
  3050,3800 ,1850,950 ,950,1900 ,1850,950 ,950,950 ,950,950 ,950,950 ,900,950 ,950,950 ,900,1000 ,900,1900 ,950,950 ,900,950 ,1850,950 ,950,950 ,950,950 ,950,950 ,900,950 ,950,950 ,950,950 ,900,950 ,950,950 ,950,950 ,900,1900 ,950,950 ,900,1000 ,1850,900 ,1000,950 ,900,950 ,950,950 ,950,950 ,900,950 ,950,950 ,900,950 ,950,1900 ,1850,950 ,2900,3850 ,1850};

IRsend irsend;

unsigned long timer_start_time = millis();
int timer_status =0;
int timer_duration=0;

void setup()
{
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.begin(9600);
}

void loop()
{
  IRTimerCheck();
  Client client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        c = client.read();
        switch (c) {
        case 'o':
          sendIR();
          client.println("SENT IR");
          break;
        case 't':
          if (client.available()) IRTimerSet(client.read());
          break;
        default:
          break;
        }
      }
    }
  }
}

void IRTimerSet (int mins) {
  timer_duration=mins;
  if (mins==0){
    timer_status=0;
  }
  else {
    timer_status=1;
    timer_start_time = millis();
    Serial.println("TIMER_START");
    sendIR();
  }
}

void IRTimerCheck (void) {
  if (timer_status && (millis()-timer_start_time>(timer_duration*1000*60))){
    Serial.println("TIMER_END");
    sendIR();
    timer_status=0;
  }
}

void sendIR (void) {
  //Send IR code in 3 repeat bursts to increase transfer chance.
  irsend.sendRaw(ac_toggle_code, sizeof(ac_toggle_code)/sizeof(int), 38);
  delayMicroseconds(30);
  irsend.sendRaw(ac_toggle_code, sizeof(ac_toggle_code)/sizeof(int), 38);
  delayMicroseconds(30);
  irsend.sendRaw(ac_toggle_code, sizeof(ac_toggle_code)/sizeof(int), 38);
  Serial.println("SENT IR");
}
Saturday, June 11th, 2011 Hacks 1 Comment