Forked from electricimp/ArduinoUART.device.nut
Last active
August 29, 2015 14:26
Revisions
-
Electric Imp revised this gist
May 15, 2014 . 2 changed files with 52 additions and 29 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,15 @@ server.log("Device Started"); function arduinoData() { // Read the UART for data sent by Arduino to indicate // the state of its LED. local b = arduino.read(); while(b != -1) { // As long as UART read value is not -1, we're getting data local state = "Unknown"; if (b == 0x10) state = "Off"; if (b == 0x11) state = "On" @@ -14,11 +18,21 @@ function arduinoData() { } } function blink(state) { // Write state (1 or 0) to the Arduino server.log("Setting LED to: " + state); arduino.write(state); imp.wakeup(1.0, function(){blink(1 - state);}); } // Alias UART to which Arduino is connected arduino <- hardware.uart57; arduino.configure(9600, 8, PARITY_NONE, 1, NO_CTSRTS, arduinoData); // Start blinking blink(1); This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,24 +1,33 @@ // Arduino device code int led = 13; // LED pin number void setup() { Serial.begin(9600); // Configure serial pinMode(led, OUTPUT); // Configure LED pin digitalWrite(led, 0); // Turn LED off } void loop() { int b = 0; // If there's data available if (Serial.available () > 0) { // Read a byte b = Serial.read(); if (b == 0x00) { digitalWrite(led, LOW); Serial.write(0x10); } else if (b == 0x01) { digitalWrite(led, HIGH); Serial.write(0x11); } } } -
Electric Imp renamed this gist
Dec 17, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Electric Imp renamed this gist
Dec 17, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Electric Imp revised this gist
Sep 25, 2013 . 2 changed files with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes. -
Electric Imp created this gist
Sep 25, 2013 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ // arduino device code int led = 13; // led pin number void setup() { Serial.begin(9600); // configure serial pinMode(led, OUTPUT); // configure LED pin digitalWrite(led, 0); // turn LED off } void loop() { int b = 0; // if there's data available if (Serial.available () > 0) { // read a byte b = Serial.read(); if (b == 0x00) { digitalWrite(led, LOW); Serial.write(0x10); } else if (b == 0x01) { digitalWrite(led, HIGH); Serial.write(0x11); } } } This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ // electric imp device code server.log("Device Started"); arduino <- hardware.uart57; function arduinoData() { local b = arduino.read(); while(b != -1) { local state = "Unknown"; if (b == 0x10) state = "Off"; if (b == 0x11) state = "On" server.log("LED: " + state); b = arduino.read(); } } arduino.configure(9600, 8, PARITY_NONE, 1, NO_CTSRTS, arduinoData); function blink(state) { server.log("Setting LED to: " + state); arduino.write(state); imp.wakeup(1.0, function() { blink(1-state); }); } blink(1);