Fine-tuned the breathing algorithm.
This commit is contained in:
parent
cd2198c411
commit
dc4d7b5886
1 changed files with 12 additions and 6 deletions
|
@ -41,19 +41,25 @@ let render = setInterval(() => {
|
||||||
if(ledRed.digitalRead()) {
|
if(ledRed.digitalRead()) {
|
||||||
return ledRed.digitalWrite(0);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}, 50);
|
}, 50);
|
||||||
|
|
||||||
function getBrightness(x) {
|
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) {
|
function breathingCurve(x, interval = 3000, min, max) {
|
||||||
let t = (x)/interval;
|
let t = x * Math.PI/(interval/2);
|
||||||
let y = (Math.sin(t) + 1)/2;
|
let y = Math.sin(t + Math.sin(t) * 0.2);
|
||||||
return ((max-min) * y) + min;
|
let untranslatedY = Math.sin(t + Math.sin(t) * 0.25);
|
||||||
|
y = (untranslatedY + 1)/2;
|
||||||
|
return y * (max - min) + min;
|
||||||
}
|
}
|
||||||
|
|
||||||
function splitAtMidnight(arr) {
|
function splitAtMidnight(arr) {
|
||||||
|
|
Loading…
Reference in a new issue