diff options
Diffstat (limited to 'code')
-rw-r--r-- | code/004-display.js | 12 | ||||
-rw-r--r-- | code/005-event.js | 20 | ||||
-rw-r--r-- | code/006-button.js | 24 | ||||
-rw-r--r-- | code/007-contrast.js | 28 | ||||
-rw-r--r-- | code/008-logging.js | 42 |
5 files changed, 118 insertions, 8 deletions
diff --git a/code/004-display.js b/code/004-display.js index e7b4cd1..4815e14 100644 --- a/code/004-display.js +++ b/code/004-display.js @@ -1,11 +1,7 @@ -var dht = require("DHT22").connect(C11); +function start() { + g.drawString("Hello World!",2,2); + g.flip(); +} I2C1.setup({scl:B6,sda:B7}); var g = require("SH1106").connect(I2C1, start); - -dht.read(function (data) { - console.log("Read DHT22"); - g.drawString("Temp: "+data.temp.toString(),2,2); - g.drawString(" RH: "+data.rh.toString(),2,10); - g.flip(); -});
\ No newline at end of file diff --git a/code/005-event.js b/code/005-event.js new file mode 100644 index 0000000..94d6d77 --- /dev/null +++ b/code/005-event.js @@ -0,0 +1,20 @@ +function draw_screen(data) { + console.log("Drawing the screen with data"); + console.log(data); + g.drawString("Espruino demo", 2, 2); + if (data) { + g.drawString("Temp: "+data.temp.toString(),2,10); + g.drawString(" RH: "+data.rh.toString(),2,18); + } + g.flip(); +} + +function start() { + dht = require("DHT22").connect(C11); + I2C1.setup({scl:B6,sda:B7}); + g = require("SH1106").connect(I2C1, draw_screen); +} + +E.on('init', start); + +start();
\ No newline at end of file diff --git a/code/006-button.js b/code/006-button.js new file mode 100644 index 0000000..4bd0c31 --- /dev/null +++ b/code/006-button.js @@ -0,0 +1,24 @@ +function draw_screen(data) { + console.log("Drawing the screen with data"); + console.log(data); + g.drawString("Espruino demo", 2, 2); + if (data) { + g.drawString("Temp: "+data.temp.toString(),2,10); + g.drawString(" RH: "+data.rh.toString(),2,18); + } + g.flip(); +} + +function start() { + dht = require("DHT22").connect(C11); + I2C1.setup({scl:B6,sda:B7}); + g = require("SH1106").connect(I2C1, draw_screen); +} + +E.on('init', start); + +setWatch(function(e) { + dht.read(draw_screen); +}, BTN, { repeat: true, edge: 'rising' }); + +start();
\ No newline at end of file diff --git a/code/007-contrast.js b/code/007-contrast.js new file mode 100644 index 0000000..432eb00 --- /dev/null +++ b/code/007-contrast.js @@ -0,0 +1,28 @@ +function draw_screen(data) { + console.log("Drawing the screen with data"); + console.log(data); + g.drawString("Espruino demo", 2, 2); + if (data) { + g.drawString("Temp: "+data.temp.toString(),2,10); + g.drawString(" RH: "+data.rh.toString(),2,18); + } + g.flip(); +} + +function start() { + dht = require("DHT22").connect(C11); + I2C1.setup({scl:B6,sda:B7}); + g = require("SH1106").connect(I2C1, draw_screen); +} + +E.on('init', start); + +setWatch(function(e) { + g.setContrast(255); + dht.read(draw_screen); + setTimeout(function () { + g.setContrast(1); + }, 4000); +}, BTN, { repeat: true, edge: 'rising' }); + +start();
\ No newline at end of file diff --git a/code/008-logging.js b/code/008-logging.js new file mode 100644 index 0000000..d5cb2a3 --- /dev/null +++ b/code/008-logging.js @@ -0,0 +1,42 @@ +function draw_screen(data) { + console.log("Drawing the screen with data"); + console.log(data); + g.drawString("Espruino demo", 2, 2); + if (data) { + g.drawString("Temp: "+data.temp.toString(),2,10); + g.drawString(" RH: "+data.rh.toString(),2,18); + } + g.flip(); +} + +function start() { + dht = require("DHT22").connect(C11); + I2C1.setup({scl:B6,sda:B7}); + g = require("SH1106").connect(I2C1, draw_screen); + fs = require("fs"); +} + +E.on('init', start); + +setWatch(function(e) { + g.setContrast(255); + dht.read(draw_screen); + setTimeout(function () { + g.setContrast(1); + }, 4000); +}, BTN, { repeat: true, edge: 'rising' }); + +setTimeout(function() { + dht.read(function(data) { + entry = "- {time: " + + Date.now() + + ", temp: " + + data.temp.toString() + + ", rh: " + + data.rh.toString(); + console.log("saving: " + entry); + fs.appendFileSync("temp_rh.yaml", entry); + }); +}, 60000); + +start();
\ No newline at end of file |