User Tools

Site Tools


2016:simple_raw_infrared_replay_for_irremote.h
// Simple raw infrared replay for IRremote.h
//
// Martin Schmitt <unixtippse at gmail dot com>
//
// IR LED is on PIN 3
// driven by ULN 2803 with 5R8 series resistor

#include <IRremote.h>
#define ON         11
#define OFF        12
#define ACT        13
#define DEBOUNCE   50

IRsend irsend;

unsigned int on[129] = {
  7800, 4200, 400, 2050, 850, 1550, 400, 2050, 900, 1600, 900, 1550, 400, 2050, 900, 1550, 
  900, 1600, 850, 1600, 400, 2000, 900, 1550, 900, 1600, 850, 1600, 850, 1600, 850, 1550, 
  450, 2050, 900, 1550, 850, 1600, 850, 1550, 900, 1600, 900, 1550, 850, 1600, 850, 1600, 
  850, 1600, 900, 1550, 850, 1600, 850, 1600, 850, 1600, 900, 1550, 900, 1550, 850, 1600, 
  850, 1600, 900, 1550, 900, 1550, 850, 1600, 850, 1600, 900, 1550, 900, 1550, 850, 1600, 
  850, 1600, 900, 1550, 900, 1550, 900, 1550, 850, 1600, 900, 1550, 900, 1550, 900, 1550, 
  850, 1600, 900, 1550, 900, 1550, 900, 1550, 850, 1650, 850, 1550, 900, 1550, 900, 1500, 
  900, 1650, 850, 1550, 900, 1550, 900, 1550, 400, 2100, 400, 2050, 850, 1550, 400, 2050, 
  400 };
unsigned int off[129]  = {
  7750, 4200, 400, 2050, 900, 1550, 400, 2050, 900, 1600, 850, 1600, 400, 2050, 850, 1550, 
  900, 1600, 850, 1600, 850, 1600, 850, 1550, 900, 1600, 850, 1600, 850, 1600, 850, 1550, 
  450, 2050, 900, 1550, 850, 1600, 850, 1550, 900, 1600, 900, 1550, 850, 1600, 850, 1600, 
  850, 1600, 900, 1550, 850, 1600, 850, 1600, 850, 1600, 900, 1550, 900, 1550, 850, 1600, 
  850, 1600, 900, 1550, 900, 1500, 900, 1600, 850, 1600, 900, 1550, 900, 1550, 850, 1600, 
  850, 1600, 900, 1550, 900, 1550, 900, 1550, 850, 1600, 900, 1550, 900, 1550, 850, 1600, 
  850, 1600, 900, 1550, 900, 1550, 900, 1550, 850, 1650, 850, 1550, 900, 1550, 900, 1550, 
  850, 1650, 850, 1550, 450, 2000, 900, 1550, 400, 2100, 400, 2050, 850, 1600, 400, 2050, 
  400 };

// Button states and debouncing
// Inverted input logic, so we can use internal pull-up
long last_statechange_on;
long last_statechange_off;

int state_on  = HIGH;
int state_off = HIGH;

int oldstate_on = HIGH;
int oldstate_off = HIGH;

void setup() {
  pinMode(ACT, OUTPUT);
  pinMode(ON,  INPUT);
  pinMode(OFF, INPUT);
  // Activate internal pull-up for inputs
  // Observe that this inverts button press logic. Don't be confused. ;-)
  digitalWrite(ON,  HIGH);
  digitalWrite(OFF, HIGH);
}

void loop() {
  int reading;
  long now = millis();
  
  // Track state of ON button & debounce
  reading = digitalRead(ON);
  if(reading != oldstate_on){
    last_statechange_on = now;
  }
  if (now - last_statechange_on > DEBOUNCE){
      state_on = reading;
  }
  oldstate_on = reading;

  // Track state of OFF button & debounce
  reading = digitalRead(OFF);
  if(reading != oldstate_off){
    last_statechange_off = now;
  }
  if (now - last_statechange_off > DEBOUNCE){
      state_off = reading;
  }
  oldstate_off = reading;

  if ((state_on == LOW) and (state_off == HIGH)){
    // Send ON code
    digitalWrite(ACT, HIGH);
    irsend.sendRaw(on, 129, 38);
    digitalWrite(ACT, LOW);
  }
  if ((state_on == HIGH) and (state_off == LOW)){
    // Send OFF code
    digitalWrite(ACT, HIGH);
    irsend.sendRaw(off, 129, 38);
    digitalWrite(ACT, LOW);
  }
}
2016/simple_raw_infrared_replay_for_irremote.h.txt · Last modified: 2016/06/25 18:06 by 75.177.137.2