Skip to content

Commit bd5aefe

Browse files
committed
Variable LED
1 parent 93d3521 commit bd5aefe

File tree

3 files changed

+37
-26
lines changed

3 files changed

+37
-26
lines changed

index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
<h1>
1414
Physical Computing for Web Devs
1515
</h1>
16-
<input type="text" placeholder="Type your question that can be answered by yes or no"/>
16+
<image src="libs/ball-pit-balls.png"/>
17+
<canvas></canvas>
1718
</body>
1819

1920
</html>

script.js

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,40 @@ window.addEventListener("DOMContentLoaded", function() {
1313
board.on("ready", function() {
1414
console.log("I can see the board!");
1515

16-
var led = new five.Led();
17-
led.on();
18-
19-
var servo = new five.Servo({
20-
pin: 10,
21-
center: true,
22-
});
23-
24-
document.querySelector("input").addEventListener("keyup", function(e) {
25-
if(e.keyCode != 13) return;
26-
var positions = {
27-
yes: 30,
28-
maybe: 90,
29-
no: 150
16+
var led = new five.Led.RGB({
17+
pins: {
18+
red: 3,
19+
blue: 5,
20+
green: 6
3021
}
31-
var answer = ["yes", "maybe", "no"][Math.floor(Math.random() * 3)];
32-
servo.sweep();
33-
setTimeout(function() {
34-
servo.stop();
35-
servo.to(positions[answer]);
36-
}, 3000);
3722
});
23+
24+
var settings = QuickSettings.create(100, 100, "Settings")
25+
.addRange("intensity", 0, 100, 50, 1, function() {
26+
led.intensity(settings.getRangeValue("intensity"));
27+
})
28+
.addColor("color", "#ffffff", function() {
29+
led.color(settings.getColor("color"));
30+
})
31+
.addButton("toggle", function() {
32+
led.toggle();
33+
});
34+
35+
var image = document.querySelector("img");
36+
var canvas = document.querySelector("canvas");
37+
var context = canvas.getContext("2d");
38+
39+
canvas.width = window.innerWidth;
40+
canvas.height = window.innerHeight;
41+
42+
context.drawImage(image, 0, 0, image.width, image.height);
43+
canvas.addEventListener("mousemove", function(e) {
44+
let [r, g, b, a] = context.getImageData(e.clientX, e.clientY, 1, 1).data;
45+
led.color({
46+
red: r,
47+
green: g,
48+
blue: b
49+
});
50+
});
3851
});
3952
});

styles.css

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ canvas {
1313
height: 100%;
1414
}
1515

16-
input {
17-
margin: 150px auto 0 auto;
18-
display: block;
19-
width: 80%;
20-
font-size: 1.5em;
16+
img {
17+
display: none;
2118
}

0 commit comments

Comments
 (0)