Skip to content

Instantly share code, notes, and snippets.

View ersatzavian's full-sized avatar

Tom Buttner ersatzavian

View GitHub Profile
// -----------------------------------------------------------------------------
// PIN mux
irtrx <- hardware.uart1289;
irpwm <- hardware.pin7;
btn1 <- hardware.pin1;
btn2 <- hardware.pin2;
led <- hardware.pin5;
// -----------------------------------------------------------------------------
@ersatzavian
ersatzavian / tone_imp002-evb.device.nut
Created April 1, 2015 18:18
Playing a 1s, 500 Hz tone with PinC on the imp002 EVB
//Playing a 1-second, 500 Hz beep
pwm <- hardware.pinC;
// configure PWM generator for 500 Hz, 50% duty cycle
pwm.configure(PWM_OUT, 1.0/500.0, 0.5);
// in one second, callback changes PWM duty cycle to 0% to stop tone
imp.wakeup(1, function() {
pwm.write(0.0);
});
@ersatzavian
ersatzavian / read_vbat_imp002-evb.device.nut
Last active August 29, 2015 14:18
Reading VBAT on imp002 EVB
vbat_sns <- hardware.pinB;
vbat_sns_en <- hardware.pin2;
vbat_sns.configure(ANALOG_IN);
vbat_sns_en.configure(DIGITAL_OUT, 0);
function getVbat() {
// enable the monitoring circuit
vbat_sns_en.write(1);
@ersatzavian
ersatzavian / 9dof-tail.device.nut
Created January 21, 2015 01:08
Driver code for LSM9DS0-based 9-degrees-of-freedom imp tail
/* 9 Degrees of Freedom Sensor Tail Firmware
* Uses LSM9DS0 IMU from ST
* http://www.adafruit.com/datasheets/LSM9DS0.pdf
*/
const XM_ADDR = 0x3C; // 8-bit I2C Student Address for Accel / Magnetometer
const G_ADDR = 0xD4; // 8-bit I2C Student Address for Angular Rate Sensor
const READING_INTERVAL = 1; // seconds between readings
/* CLASS AND GLOBAL FUNCTION DEFINITIONS ------------------------------------ */
/* Environmental Sensor Tail Firmware
* Ambient Light Sensor: APDS-9007-020 (http://www.avagotech.com/docs/AV02-0512EN)
* Air Pressure Sensor: LPS25HTR (http://www.st.com/web/en/resource/technical/document/datasheet/DM00066332.pdf)
* Humidity/Temp Sensor: SI7020-A10-GMR (http://www.silabs.com/Support%20Documents/TechnicalDocs/Si7020.pdf)
*/
const LPS25H_ADDR = 0xB8; // 8-bit I2C Student Address for LPS25HTR
const SI7020_ADDR = 0x80; // 8-bit I2C Student Address for SI7020
const ALS_RLOAD = 47000.0; // load resistor value on ALS
const READING_INTERVAL = 3; // seconds between readings
@ersatzavian
ersatzavian / textlock.agent.nut
Created November 23, 2014 21:48
twilio lockbox example
/******************** Constants ********************/
// Your MailGun settings
const API_KEY = "key-a1b2c3...";
const SUBDOMAIN = "sandbox123abc.mailgun.org";
// Define what email to notify
const EMAIL = "[email protected]";
const TWILIO_SID = ""; // Your Twilio Account SID
const TWILIO_AUTH = ""; // Your Twilio Auth Token
@ersatzavian
ersatzavian / imp001-thermostat.agent.nut
Created July 7, 2014 18:48
Basic "Thermostat" Example with imp001 with thermistor and LED
// agent code:
target <- 30.0;
current <- "Unkown";
device.send("target", target);
device.on("current", function(t){ current <- format("%0.1f C",t)});
http.onrequest(function(request,res){
if(request.method == "POST"){
local post = http.urldecode(request.body);
@ersatzavian
ersatzavian / imp001-readtemp.agent.nut
Last active August 29, 2015 14:03
Read temperature with Thermistor on imp001, show on small agent webpage
// agent code:
body <- "No value yet";
http.onrequest(function(request,res){
local html = @"<html><meta http-equiv=""refresh"" content=""5"">
<body>" + body + "</body></html>";
res.send(200,html);
});
device.on("temp", function(t){
body = format("Temperature: %0.1f C", t );
@ersatzavian
ersatzavian / imp001-blink.device.nut
Created July 7, 2014 18:40
Blink LED on imp001 pin 1
@ersatzavian
ersatzavian / imp003-evb-blinkblue.device.nut
Created July 7, 2014 18:13
Blink Blue LED on imp003 EVB
// Device Code
led <- hardware.pinK;
led.configure(DIGITAL_OUT);
state <- 0;
function loop(){
server.log("Blink: "+state);
led.write(state);
state = 1 - state;
imp.wakeup(1, loop);