-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathFade.js
More file actions
36 lines (32 loc) · 844 Bytes
/
Fade.js
File metadata and controls
36 lines (32 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
PWM.js
his example shows how to use PWM in order to modify the brightness in a LED
This example code is in the public domain.
Revision History
------------------------------------------------
Author Date Description
------------------------------------------------
Carlos Mata 2-9-2015 Example created
*/
var mraa = require('mraa'); //Imports MRAA library
var LED = new mraa.Pwm(3);
LED.period_us(700);
LED.enable(true);
Brightness = 0.0;
FadeAmount = 0.01;
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
while (true){
LED.write(Brightness);
Brightness = Brightness + FadeAmount;
if ((Brightness >= 1.0) || (Brightness <= 0.0)){
FadeAmount = -1 * FadeAmount;
}
sleep(30);
}