Browse Source

Fine-tuned the breathing algorithm.

master
John Shaver 4 years ago
parent
commit
dc4d7b5886
  1. 18
      runSchedule.js

18
runSchedule.js

@ -41,19 +41,25 @@ let render = setInterval(() => {
if(ledRed.digitalRead()) {
return ledRed.digitalWrite(0);
}
return ledGreen.hardwarePwmWrite(HZ, getBrightness(Date.now()));
if(!ledGreen.digitalRead()) {
return ledGreen.digitalWrite(1);
}
//Commenting out. Probably don't need breathing on green leds
//return ledGreen.hardwarePwmWrite(HZ, getBrightness(Date.now()));
break;
}
}, 50);
function getBrightness(x) {
return Math.floor(breathingCurve(x, 3000, 1000000, 100000));
return Math.floor(breathingCurve(x, 5000, 100000, 1000000));
}
function breathingCurve(x, interval = 3000, max, min) {
let t = (x)/interval;
let y = (Math.sin(t) + 1)/2;
return ((max-min) * y) + min;
function breathingCurve(x, interval = 3000, min, max) {
let t = x * Math.PI/(interval/2);
let y = Math.sin(t + Math.sin(t) * 0.2);
let untranslatedY = Math.sin(t + Math.sin(t) * 0.25);
y = (untranslatedY + 1)/2;
return y * (max - min) + min;
}
function splitAtMidnight(arr) {

Loading…
Cancel
Save