-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblink.js
163 lines (105 loc) · 2.76 KB
/
blink.js
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
'use strict';
const SG_CODE = "singapore" ; //country codes to be used
const CN_CODE = "romania";
const IND_CODE = "noida";
const INDO_CODE = "indonesia";
const INSERT_YOUR_TOKEN = process.argv();
const fetch = require('node-fetch'); //required to use fetch function and async await
//async await to call the country, to be replicated inside the board
async function getAir(country){
const response = await fetch("https://api.waqi.info/feed/" + country + "/?token=INSERT_YOUR_TOKEN");
const data = await response.json();
let airQuality = data.data.aqi;
return airQuality;
}
//connecting the huzzah to hotspot
const { EtherPortClient} = require('etherport-client');
const five = require('johnny-five');
const Led = require('johnny-five');
const { ShiftRegister} = require('johnny-five');
const { Board, Expander, Leds } = require("johnny-five");
const board = new five.Board({ //intitalise board using the internet client host
port: new EtherPortClient({
host: '192.168.137.120', //ip address is based on your own machine
port: 3030
}),
repl: true
});
//defining pins, make sure they are pwm (can test out one by one on your own)
board.on("ready", () => {
const expander = new Expander({
controller: "74HC595",
pins: {
data: 2,
clock: 16,
latch: 15
}
});
const virtual = new Board.Virtual(expander);
const leds = new Leds(
Array.from(Array(8), (_, pin) =>
({ pin, board: virtual })
)
);
/* const anode = new five.Led.RGB({
pins : {
red : leds[4],
green:leds[5],
blue : leds[6]
},
isAnode: true
}) */
const SG_RED = leds[4];
const SG_GREEN = leds[5];
const CN_RED = leds[6];
const CN_GREEN = leds[7];
const INDIA_RED = leds[0];
const INDIA_GREEN = leds[1];
const INDO_RED = leds[2];
const INDO_GREEN = leds[3];
getAir(SG_CODE).then( result =>{
console.log(result + " singapore api");
SG_RED.on();
SG_GREEN.on();
SG_GREEN.blink(500);
})
getAir(IND_CODE).then( result => {
INDO_RED.on();
INDO_GREEN.on();
INDO_RED.blink(500);
})
getAir(CN_CODE).then( result => {
CN_RED.on();
CN_GREEN.on();
CN_RED.blink(500);
})
getAir(INDO_CODE).then(result => {
console.log("This is the code for indoensia" + result);
INDIA_RED.on();
INDIA_GREEN.on();
INDIA_RED.blink(500);
})
board.wait(10000, () => {
// stop() terminates the interval
// off() shuts the led off
leds.stop().on();
});
board.repl.inject({
leds
});
});
/* board.on("ready", () => {
const register = new ShiftRegister({
pins: {
data: 2,
clock: 16,
latch: 15
}
});
var output = 0b10000000;
board.loop(100, () => {
output = output > 0 ? output >> 1 : 0b10000000;
register.send(output);
});
});
*/