Skip to content

Instantly share code, notes, and snippets.

@ersatzavian
Created March 14, 2014 17:09
Show Gist options
  • Save ersatzavian/9552161 to your computer and use it in GitHub Desktop.
Save ersatzavian/9552161 to your computer and use it in GitHub Desktop.
LED Breather
// Pulse the LED
// Adapted from http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ by Sean Voisen
function pulse_led(led) {
imp.wakeup(0.05, function() {
pulse_led(led);
});
// Work out the next PWM level
local led_level = (math.exp(math.sin(hardware.millis()/2000.0*PI)) - 0.36787944) * 0.423529412;
led.write(led_level);
}
led_red <- hardware.pin1;
led_red.configure(PWM_OUT, 1.0/400.0, 0.0);
led_red.write(0);
pulse_led(led_red);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment