-
Notifications
You must be signed in to change notification settings - Fork 0
/
Traffic-light.html
62 lines (58 loc) · 1.74 KB
/
Traffic-light.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
59
60
61
62
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>Traffic light</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://webduino.io/components/webduino-js/dist/webduino-all.min.js"></script>
<script src="https://blockly.webduino.io/webduino-blockly.js"></script>
<script src="https://blockly.webduino.io/lib/runtime.min.js"></script>
<style>
#light img {height: 200px; display: none;}
#light.off #light_off, #light.on #light_on {display: inline-block;}
</style>
</head>
<body>
<div id="light" class="off">
<img src="../image/light-off.jpg" id="light_off">
<img src="../image/light-on.jpg" id="light_on">
</div>
<script>
var led_red, led_yellow, led_green;
var light = document.getElementById("light");
(async function () {
boardReady({device: 'wa8w'}, async board => {
board.systemReset();
board.samplingInterval = 250;
led_red = getLed(board, 10);
led_yellow = getLed(board, 11);
led_green = getLed(board, 7);
led_red.off();
led_yellow.off();
led_green.on();
light.className = "off";
light.addEventListener("click", Traffic_Light);
});
}());
async function Traffic_Light() {
if (light.className == "off") {
await delay(2);
led_red.off();
led_yellow.on();
led_green.off();
await delay(2);
led_red.on();
led_yellow.off();
led_green.off();
light.className = "on";
} else {
await delay(2);
led_red.off();
led_yellow.off();
led_green.on();
light.className = "off";
}
}
</script>
</body>