aboutsummaryrefslogtreecommitdiff
path: root/code/008-logging.js
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2017-02-24 18:56:53 +0100
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2017-02-24 18:56:53 +0100
commit06b1851216e42923b0df70bb498df8cf106965cc (patch)
tree43e42c037ad87a7137cc3a4715c7bc6edcef7aef /code/008-logging.js
parentfa9c2ee2b01b04b23c249d1f953e1cfef1c8edea (diff)
Completed code project
Diffstat (limited to 'code/008-logging.js')
-rw-r--r--code/008-logging.js42
1 files changed, 42 insertions, 0 deletions
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