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 characters
#!/usr/bin/env python | |
import serial | |
s = serial.Serial("/dev/ttyAMA0", baudrate=115200, timeout=3.0) | |
message = "" | |
while True: | |
logChar = s.read() | |
if logChar: |
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 characters
class Logger { | |
_serial = null; | |
constructor (impUART) { | |
if (impUART != null) { | |
_serial = impUART; | |
_serial.configure(115200, 8, PARITY_NONE, 1, NO_RX); | |
} | |
} | |
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 characters
// These constants may be different for your servo | |
const SERVO_MIN = 0.03; | |
const SERVO_MAX = 0.1; | |
// Create global variable for the pin to which the servo is connected | |
// then configure the pin for PWM | |
servo <- hardware.pin7; | |
servo.configure(PWM_OUT, 0.02, SERVO_MIN); | |
// Define a function to control the servo. |
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 characters
// Assign pin9 to a global variable | |
led <- hardware.pin9; | |
// Configure LED pin for DIGITAL_OUTPUT, and set initial state to off | |
led.configure(DIGITAL_OUT, 0); | |
// Assign a global variable to track current state of LED pin | |
state <- 0; | |
// Function to blink LED |
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 characters
// Alias the GPIO pin as 'button' | |
button <- hardware.pin1; | |
function buttonPress() { | |
local state = button.read(); | |
if (state == 1) { | |
// The button is released | |
server.log("Release"); | |
} else { | |
// The button is pressed |
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 characters
// Alias pin 2 as pot | |
pot <- hardware.pin2; | |
// Configure the pin for analog input | |
pot.configure(ANALOG_IN); | |
// Define a function to poll the pin every 0.1 seconds | |
function poll() { | |
// Read the pin and log its value | |
server.log(pot.read()); |
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 characters
// Assign hardware.pin5 to a global variable, therm | |
therm <- hardware.pin5; | |
// Configure pin5/therm for analog input | |
therm.configure(ANALOG_IN); | |
// These constants are particular to the thermistor we're using. | |
// Check your datasheet for what values you should be using | |
const B_THERM = 3977.0; | |
const T0_THERM = 298.15; |
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 characters
function loop() { | |
// Get an integer reading from the imp's light sensor and relay it via UART | |
uart57.write("Current light level is: " + hardware.lightlevel() + "\r\n"); | |
// Set the imp to check again in two seconds' time | |
imp.wakeup(2.0, loop); | |
} | |
// Start of program | |
// Initiate main loop |
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 characters
server.settimeoutpolicy(SUSPEND_ON_ERROR, WAIT_FOR_ACK, 10); | |
// Program does some work... | |
foreach (count, blob in buffer) { | |
// Every send will not return until the server has ACK’d | |
// Assume no timeout for this example | |
local outcome = agent.send(“process.data”, blob); | |
server.log(“Blob %u sent to server”, count + 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 characters
// Agent Code | |
class TFLData { | |
_apikey = null; | |
_appID = null; | |
_stops = null; | |
_url = null; | |
_listTimes = 4; | |
constructor (apiKey = null, appID = null, busStops = null, listTimes = 4) { | |
_apikey = apiKey; |
OlderNewer