-
Notifications
You must be signed in to change notification settings - Fork 5
/
BasicExample.html
58 lines (49 loc) · 1.51 KB
/
BasicExample.html
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="Adafruit_NeoPixel.css">
<script src="Adafruit_NeoPixel.js"></script>
<script>
//USER
var PIN = 10
var NUM_LEDS = 60
var BRIGHTNESS = 255
//ws2812b, arduino pro mini
var strip = new Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800)
function setup() {
strip.setBrightness(BRIGHTNESS)
strip.begin()
strip.show()
}
var red = strip.Color(255, 0, 0)
var yellow = strip.Color(255, 255, 0)
var blue = strip.Color(0, 0, 255)
var colors = [red,yellow,blue]
var currentColorIndex = 0
function loop() {
var animationDone = colorWipe(colors[currentColorIndex])
if (animationDone)
currentColorIndex = (currentColorIndex>=colors.length-1 ? 0 : currentColorIndex+1)
}
function colorWipe(color) {
var now = millis()
if (now > colorWipe.lastUpdate+colorWipe.delay) {
strip.setPixelColor(colorWipe.currentLed, color)
strip.show()
colorWipe.currentLed = colorWipe.currentLed>=strip.numPixels()-1 ? 0 : colorWipe.currentLed+1
colorWipe.lastUpdate = now
if (colorWipe.currentLed === 0)
return true;
}
return false
} //c++-like static variables for this fucntion:
colorWipe.delay = 10
colorWipe.lastUpdate = 0
colorWipe.currentLed = 0
</script>
</head>
<body>
<div class="ledStrip" data-pin="10"></div>
<div class="editor"></div>
</body>
</html>