Skip to content

Instantly share code, notes, and snippets.

@lvidarte
Last active June 18, 2016 20:26
Show Gist options
  • Save lvidarte/c5412ae4976e54521aa64a00cd5ac706 to your computer and use it in GitHub Desktop.
Save lvidarte/c5412ae4976e54521aa64a00cd5ac706 to your computer and use it in GitHub Desktop.
-- rgb.lua
PIN_R = 3
PIN_G = 2
PIN_B = 1
function led(r, g, b)
pwm.setduty(PIN_R, r)
pwm.setduty(PIN_G, g)
pwm.setduty(PIN_B, b)
end
function get_random_value()
return math.random(1, 512)
end
function random_color()
led(get_random_value(), get_random_value(), get_random_value())
end
function init()
pwm.setup(PIN_R, 500, 512)
pwm.setup(PIN_G, 500, 512)
pwm.setup(PIN_B, 500, 512)
pwm.start(PIN_R)
pwm.start(PIN_G)
pwm.start(PIN_B)
tmr.alarm(1, 500, tmr.ALARM_AUTO, random_color)
end
init()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment