Last active
December 17, 2015 18:29
-
-
Save fponticelli/5654112 to your computer and use it in GitHub Desktop.
Rotating RGB LED color hue with BeagleBone Black, Haxe and BoneScript.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bone.Bone; | |
import thx.color.Color; | |
import thx.color.HSL; | |
using thx.color.Convert; | |
class RGBLed | |
{ | |
public static function main() | |
{ | |
reset(); | |
var led = new RGBLed("P8_19", "P9_14", "P8_13"), | |
hsl = new HSL(0, 1, 0.5); | |
N.setInterval(function() { | |
led.setColor(hsl); | |
hsl.hue++; | |
}, 20); | |
} | |
public static function reset() | |
{ | |
["USR0", "USR1", "USR2", "USR3"] | |
.map(function(pin) { | |
Bone.pinMode(pin, Bone.OUTPUT); | |
Bone.digitalWrite(pin, Bone.LOW); | |
}); | |
} | |
var channels : Array<String>; | |
var invert : Bool; | |
public function new(pinR : String, pinG : String, pinB : String, invert : Bool = true) | |
{ | |
channels = [pinR, pinG, pinB]; | |
this.invert = invert; | |
} | |
function norm(c : Float) | |
return invert ? 1 - c : c; | |
public function setColor(color : Color) | |
{ | |
var rgbx = color.toRGBX(); | |
Bone.analogWrite(channels[0], norm(rgbx.redf)); | |
Bone.analogWrite(channels[1], norm(rgbx.greenf)); | |
Bone.analogWrite(channels[2], norm(rgbx.bluef)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment