-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchange_led_brightness.js
More file actions
28 lines (27 loc) · 845 Bytes
/
change_led_brightness.js
File metadata and controls
28 lines (27 loc) · 845 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
// The program shows heart image on LED at the beginning
// When button A is pressed, LED brightness change by 50, means 50 brighter than before.
// When button B is pressed, LED brightness change by -50, means 50 darker than before.
// LED value is between 0 and 255, but changing the brightness by 1 isn't really making any noticeable
// change, changing by 50 to make things easiler.
input.onButtonPressed(Button.A, function () {
if (degrees < 205) {
degrees += STEP
} else {
degrees = 255
}
led.setBrightness(degrees)
})
input.onButtonPressed(Button.B, function () {
if (degrees > STEP) {
degrees += 0 - STEP
} else {
degrees = 0
}
led.setBrightness(degrees)
})
let STEP = 0
let degrees = 0
degrees = 255
STEP = 50
led.setBrightness(degrees)
basic.showIcon(IconNames.Heart)