Here’s a real simple hello world project. This uses 3 pwm pins. I disabled my HDMI port.
Here’s the pic of my wiring and also the code. I’ll post more info later. For now this code wull fad red to green to blue. next will be walking through a rgb table. I already wrote a crzy spinning effect but that will be posted later.
Here’s the board.. just ignore the accelerometer and yello led. You want to copy the lower full spectrum led wiring. Just look at the code, or adapt the code whatever pins you decide to use.
Here’s the code:
cat fadergb.js
var b = require(‘bonescript’);
// setup starting conditions
var awValue = 0.000001;
var awDirection = 1;
// var awPin = “P8_46”;
var greenPin = “P8_46”;
var bluePin = “P8_45”;
var redPin = “P8_34”;
var green;
var blue;
// configure pin
b.pinMode(redPin, b.OUTPUT);
b.pinMode(greenPin, b.OUTPUT);
b.pinMode(bluePin, b.OUTPUT);
b.analogWrite(redPin,1);
b.analogWrite(greenPin,1);
b.analogWrite(bluePin,1);
// call function to update brightness every 10ms
var red=setInterval (fade_red,5);
var fadeloops=0;
function fade_red() {
b.analogWrite(redPin, awValue);
awValue = awValue + (awDirection*0.01);
if(awValue > 1.0) { awValue = 1.0; awDirection = -1;
if(fadeloops >= 1) { clearInterval(red);b.analogWrite(redPin,1);green =setInterval (fade_green,5); }}
else if(awValue <= 0.01) { awValue = 0.000001; awDirection = 1;fadeloops=fadeloops +1;
}
}
function fade_green() {
b.analogWrite(greenPin, awValue);
awValue = awValue + (awDirection*0.01);
if(awValue > 1.0) { awValue = 1.0; awDirection = -1;
if(fadeloops >= 1) { clearInterval(green); b.analogWrite(greenPin,1);blue=setInterval (fade_blue,5); }}
else if(awValue <= 0.01) { awValue = 0.000001; awDirection = 1;fadeloops=fadeloops +1;
}
}
function fade_blue()
{
b.analogWrite(bluePin, awValue);
awValue = awValue + (awDirection*0.01);
if(awValue > 1.0) { awValue = 1.0; awDirection = -1;
if(fadeloops >= 1) { clearInterval(blue);clearInterval(green);clearInterval(red);
b.analogWrite(redPin,1);b.analogWrite(greenPin,1);
b.analogWrite(bluePin,1);red=setInterval (fade_red,5); }}
else if(awValue <= 0.01) { awValue = 0.000001; awDirection = 1;fadeloops=fadeloops +1;
}
}
Comments are not currently available for this post.