Fixed invalid led color on initialization.

This commit is contained in:
John Shaver 2018-12-12 13:47:48 -08:00
parent 67edc68d64
commit b0b4a358e5

View file

@ -19,7 +19,13 @@ let state = {
color: "red"
}
let updateState = setInterval(() => {
updateState();
let updateStateInterval = setInterval(updateState, 1000);
let renderInterval = setInterval(render, 50);
function updateState() {
let time = getTime();
let timing = timings.find(x => x.start <= time && x.end > time);
if(timing.color !== state.color) {
@ -27,9 +33,9 @@ let updateState = setInterval(() => {
color: timing.color
};
}
}, 1000);
}
let render = setInterval(() => {
function render() {
switch(state.color) {
case "red":
if(ledGreen.digitalRead()) {
@ -48,7 +54,7 @@ let render = setInterval(() => {
//return ledGreen.hardwarePwmWrite(HZ, getBrightness(Date.now()));
break;
}
}, 50);
}
function getBrightness(x) {
return Math.floor(breathingCurve(x, 6000, 100000, 1000000));