Skip to content

Instantly share code, notes, and snippets.

@ersatzavian
Created April 17, 2015 16:49
Show Gist options
  • Select an option

  • Save ersatzavian/db25ffaeb1a5854d2baf to your computer and use it in GitHub Desktop.

Select an option

Save ersatzavian/db25ffaeb1a5854d2baf to your computer and use it in GitHub Desktop.
Test IR Tail
// -----------------------------------------------------------------------------
// PIN mux
irtrx <- hardware.uart1289;
irpwm <- hardware.pin7;
btn1 <- hardware.pin1;
btn2 <- hardware.pin2;
led <- hardware.pin5;
// -----------------------------------------------------------------------------
// Handle the stage change for button 1
function btn1_change() {
server.log("Btn1");
// Debounce (give the button a chance to settle)
imp.sleep(0.01);
// Read the button state and if down (value of 1) then
if (btn1.read()) {
led.write(1);
} else {
led.write(0);
}
}
// Handle the stage change for button 2
function btn2_change() {
// Debounce (give the button a chance to settle)
imp.sleep(0.01);
led.write(btn2.read());
if (btn2.read()) {
irtrx.write("testing!");
server.log("sending");
}
// Set the LED state to match the button state
}
// -----------------------------------------------------------------------------
imp.enableblinkup(true);
server.log("Running SW: "+imp.getsoftwareversion());
// Configure the LED pin as digital output and initialise its value to 0
led.configure(DIGITAL_OUT, 0);
// Configure the IR transceiver
// Carrier Signal: 38 kHz, 50% duty cycle
irpwm.configure(PWM_OUT, 1.0 / 38000, 0.5);
// Modulating signal: UART, 2400 baud
irtrx.configure(2400, 8, PARITY_NONE, 1, NO_CTSRTS, function() {
imp.sleep(0.10);
server.log(irtrx.readstring());
});
// Configure button 1 as an input and set an event handler
btn1.configure(DIGITAL_IN_PULLDOWN, btn1_change);
// Configure button 2 as an input and set an event handler
btn2.configure(DIGITAL_IN_PULLDOWN, btn2_change);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment