diff options
-rw-r--r-- | code/listing.rest | 37 | ||||
-rw-r--r-- | slides/presentazione_espruino.rst | 122 |
2 files changed, 155 insertions, 4 deletions
diff --git a/code/listing.rest b/code/listing.rest new file mode 100644 index 0000000..7b94e40 --- /dev/null +++ b/code/listing.rest @@ -0,0 +1,37 @@ +.. include:: 001-blink.js + :code: js + +------ + +.. include:: 002-button.js + :code: js + +------ + +.. include:: 003-dht22.js + :code: js + +------ + +.. include:: 004-display.js + :code: js + +------ + +.. include:: 005-event.js + :code: js + +------ + +.. include:: 006-button.js + :code: js + +------ + +.. include:: 007-contrast.js + :code: js + +------ + +.. include:: 008-logging.js + :code: js diff --git a/slides/presentazione_espruino.rst b/slides/presentazione_espruino.rst index fa06723..4f6a16f 100644 --- a/slides/presentazione_espruino.rst +++ b/slides/presentazione_espruino.rst @@ -118,17 +118,33 @@ Blink, seconda versione .. image:: img/blink_text.png :align: center +------ + +.. code:: javascript + + var on = false; + setInterval(function() { + on = !on; + LED1.write(on); + }, 500); + Bottoni ------- .. image:: img/button.png :align: center -Funzioni --------- +------ -.. image:: img/function.png - :align: center +.. code:: javascript + + var on = false; + var change = function() { + on = !on; + LED1.write(on); + }; + + setWatch(change, BTN1, {repeat:true, edge:"rising"}); DHT22 ----- @@ -136,30 +152,105 @@ DHT22 .. image:: img/dht22.png :align: center +------ + +.. code:: javascript + + var dht = require("DHT22").connect(C11); + + dht.read(function (data) { + console.log( + "Temp is " + + data.temp.toString() + + " and RH is " + + data.rh.toString()); + }); + OLED ---- .. image:: img/display.png :align: center +------ + +.. code:: javascript + + function start() { + g.drawString("Hello World!",2,2); + g.flip(); + } + + I2C1.setup({scl:B6,sda:B7}); + var g = require("SH1106").connect(I2C1, start); + Saving and loading ------------------ .. image:: img/display_interrupt.png :align: center +------ + +.. code:: javascript + + 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(); + } + +------ + +.. code:: javascript + + 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(); + Reading with a button --------------------- .. image:: img/temp_with_button.png :align: center +------ + +.. code:: javascript + + setWatch(function(e) { + dht.read(draw_screen); + }, BTN, { repeat: true, edge: 'rising' }); + Lowering contrast ----------------- .. image:: img/contast_with_button.png :align: center +------ + +.. code:: javascript + + setWatch(function(e) { + g.setContrast(255); + dht.read(draw_screen); + setTimeout(function () { + g.setContrast(1); + }, 4000); + }, BTN, { repeat: true, edge: 'rising' }); + Setting the date ---------------- @@ -172,6 +263,29 @@ Logging data .. image:: img/logging_data.png :align: center +------ + +.. code:: javascript + + + function start() { + [...] + fs = require("fs"); + } + + setInterval(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); + Per proseguire -------------- |