-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
156 lines (138 loc) · 4.62 KB
/
main.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
// require("https://raw.githubusercontent.com/miseler/PoolAutomation/master/main.js");
// https://www.espruino.com/modules/nodeconfeu2018.js
// https://nodeconfeubadge.org/
// virtual LEDs: https://forum.espruino.com/conversations/341306/#15005751
// virtual LEDs: https://forum.espruino.com/conversations/341372/
// offline development: https://forum.espruino.com/conversations/395908/
// https://www.espruino.com/Pixl.js+Multicolour
// https://github.com/Espruino/EspruinoDocs/blob/master/boards/PixljsMulticolour/simple.js
// https://www.youtube.com/watch?v=H8L8ft830hI
// https://www.youtube.com/watch?v=txZr2GhuoaI
// https://www.youtube.com/watch?v=2ODoIpnTDA4
// https://www.espruino.com/IoT+Services
// https://www.espruino.com/Reference
//Set output 1 to ON
//http://192.168.1.230/r-ee1ac5d/share/set-netio-output1-to-1.json
//http://192.168.1.230/netio.cgi?pass=&output1=4
//http://192.168.1.230/netio.json
//FIFO_FULL
/*
require("Storage").write(".boot0", `
WIFI_NAME = "MyWiFi";
WIFI_PASS = "HelloWorld123";
`);
*/
/*
var c = [127,0,0];
NC.ledTop(c);
NC.ledBottom(c);
NC.backlight(c.concat(c,c,c));
*/
var NC = require("nodeconfeu2018");
var LEDon = false;
var alertOn = false;
var backlightOn = false;
var backlightIndex=0;
const inspect = obj => {
for (const prop in obj) {
if (obj.hasOwnProperty(prop)) {
console.log(`${prop}: ${obj[prop]}`);
}
}
};
// shim to run Pixl.js Multicolour code on the Bangle1.js emulator
if(NC.ledTop == undefined) { NC.ledTop = function(a) { // 3 element array
console.log(a);
};}
if(NC.ledBottom == undefined) { NC.ledBottom = function(a) { // 3 element array
console.log(a);
};}
if(NC.backlight == undefined) { NC.backlight = function(a) { // 3 element array
console.log(a);
};}
setInterval(function() {
if(!alertOn) {
//NC.ledTop();
//NC.ledBottom();
NC.backlight(Array(12).fill(100));
//NC.backlight([255,0,0, 0,255,0, 0,0,255, 0,0,0]);
}
else {
LEDon = !LEDon;
//NC.ledTop([0,255*LEDon,255*!LEDon]);
//NC.ledBottom([0,255*!LEDon,255*LEDon]);
//var backlight = [0,255*!LEDon,255*LEDon,0,255*!LEDon,255*LEDon,0,255*!LEDon,255*LEDon,0,255*!LEDon,255*LEDon];
var backlight;
var backlightWhiteDark = Array(12).fill(100);
var backlightWhite = Array(12).fill(255);
var backlightRedDark = [0,0,120,0,0,120,0,0,120,0,0,120];
var backlightRed = [0,0,255,0,0,255,0,0,255,0,0,255];
var backlightGreenDark = [0,100,0,0,100,0,0,100,0,0,100,0];
var backlightGreen = [0,255,0,0,255,0,0,255,0,0,255,0];
var backlightBlueDark = [225,0,0,225,0,0,225,0,0,225,0,0];
var backlightBlue = [255,40,40,255,40,40,255,40,40,255,40,40];
switch((backlightIndex++)%8) {
case 0: backlight=backlightWhiteDark;break;
case 1: backlight=backlightWhite;break;
case 2: backlight=backlightRedDark;break;
case 3: backlight=backlightRed;break;
case 4: backlight=backlightGreenDark;break;
case 5: backlight=backlightGreen;break;
case 6: backlight=backlightBlueDark;break;
case 7: backlight=backlightBlue;break;
}
/*
backlight[0]=0;
backlight[1]=255*!LEDon;
backlight[2]=255*LEDon;
backlight[6]=0;
backlight[7]=255*!LEDon;
backlight[8]=255*LEDon;
*/
//NC.backlight([0,0*255*!LEDon,0*255*LEDon,0,0*255*!LEDon,0*255*LEDon,0,255*!LEDon,255*LEDon,0,0*255*!LEDon,0*255*LEDon]);
NC.backlight(backlight);
}
}, 800);
function btn1() {
if (digitalRead(BTN1) == 1) alertOn = !alertOn;
console.log("alert is: "+alertOn);
}
function btn3() {
if (digitalRead(BTN3) == 1) backlightOn = !backlightOn;
var backlight=backlightOn?100:0;
NC.backlight(Array(12).fill(backlight));
}
function btn2() {
if (digitalRead(BTN2) == 1) backlightOn = !backlightOn;
var backlight=backlightOn?100:0;
NC.backlight(Array(12).fill(0,0,200));
}
btn2();
btn3();
btn1();
setWatch(btn2, BTN2, true);
setWatch(btn3, BTN3, true);
setWatch(btn1, BTN1, true);
D9.set(); // power on
Serial1.setup(115200,{rx:D0,tx:D1});
var wifi = require("ESP8266WiFi").connect(Serial1, function(err) {
if (err) throw err;
console.log("Connecting to WiFi");
wifi.connect(WIFI_NAME, WIFI_PASS, function(err) {
if (err) throw err;
console.log("Connected");
// Now you can do something, like an HTTP request
require("http").get("http://www.pur3.co.uk/hello.txt", function(res) {
console.log("Response: ",res);
res.on('data', function(d) {
console.log("--->"+d);
});
});
});
});
/*
exports = {
NC : NC,
alertOn : alertOn,
};
*/