Skip to content

Instantly share code, notes, and snippets.

@fponticelli
Last active December 17, 2015 18:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fponticelli/5654112 to your computer and use it in GitHub Desktop.
Save fponticelli/5654112 to your computer and use it in GitHub Desktop.
Rotating RGB LED color hue with BeagleBone Black, Haxe and BoneScript.
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