Skip to content

Instantly share code, notes, and snippets.

@electricimp
electricimp / ht16k33big.class.nut
Created November 11, 2014 15:31
Squirrel Class to control Adafruit HT16K33-based 1.2in, 4-digit, 7-segment LED via I2C
class HT16K33BIG
{
// Squirrel class for 1.2-inch four-digit, 7-segment LED displays driven by the HT16K33 controller
// For example: http://www.adafruit.com/products/1270
// Communicates with any imp I2C bus
// Written by Tony Smith (@smittytone) October 2014
// Version 1.0
// HT16K33 registers and HT16K33-specific variables
@electricimp
electricimp / ht16k33quad.class.nut
Created November 11, 2014 15:20
Squirrel Class to control Adafruit HT16K33-based 0.54in, 4-digit, 14-segment LED via I2C
class HT16K33QUAD
{
// Squirrel class for 0.54-inch four-digit, 14-segment LED displays driven by the HT16K33 controller
// For example: http://shop.pimoroni.com/products/quad-alphanumeric-display-0-54-digits-w-i2c-backpack
// and: http://www.adafruit.com/product/1912
// Communicates with any imp I2C bus
// Written by Tony Smith (@smittytone) August/September 2014
// Version 1.0
@electricimp
electricimp / twitter.agent.nut
Last active August 29, 2015 14:08
Twitter Scrolling Display Project
// Twitter Keys
const API_KEY = "YOUR API KEY"
const API_SECRET = "YOUR API SECRET"
const AUTH_TOKEN = "YOUR AUTH TOKEN"
const TOKEN_SECRET = "YOUR TOKEN SECRET"
// Twitter Access Class
class Twitter
@electricimp
electricimp / weather.agent.nut
Last active March 18, 2018 21:26
Wireless Weather Monitor Project
// WEATHER UPDATE CLASS
class WeatherUpdate
{
// Simple Squirrel class for interaction with Forecast.io
url = "https://api.forecast.io/forecast/"
apikey = "YOUR API KEY HERE"
function forecastRequest(longitude = 52.205082, latitude = 0.130209)
@electricimp
electricimp / longpoll.agent.nut
Last active August 29, 2015 14:08
Long Polling Agent HTTP Request Recipe
// Set up outgoing request object as a global (we may need to cancel it, so we need a reference to it)
request <- http.get(webServiceURL, webServiceHeaders)
// Define the response handler
function handleResponse(responseTable)
{
// Called when the imp receives an immediate acknowledgement from the remote service
@electricimp
electricimp / httpgetasync.agent.nut
Last active August 29, 2015 14:08
Agent-to-Internet Outgoing HTTP Request Recipe
// Set up outgoing request object
local request = http.get(webServiceURL, webServiceHeaders)
// Define the response handler
function handleResponse(responseTable)
{
// Called when the imp receives a response from the remote service
@electricimp
electricimp / http.agent.nut
Last active August 29, 2015 14:08
Agent Incoming HTTP Request Handling Recipe
// Define an HTTP request handler
function requestHandler(request, response)
{
try
{
if ("setting" in request.query)
{
// 'setting' is a URL-encoded parameter, ie. '/setting=4'
@electricimp
electricimp / disconnect.device.nut
Created October 28, 2014 16:40
Unexpected Server Disconnection Recipe
// Set the disconnection policy
server.setsendtimeoutpolicy(RETURN_ON_ERROR, WAIT_TIL_SENT, 30)
// Define the disconnection handler function
function disconnectionHandler(reason)
{
if (reason != SERVER_CONNECTED)
{
@electricimp
electricimp / comms.agent.nut
Last active June 8, 2018 22:11
Agent-Device Communications
// Agent Globals
locationLong <- 999
locationLat <- 999
dummyValue <- 0
// Weather functions
function getForecast()
@electricimp
electricimp / comms.device.nut
Last active August 29, 2015 14:08
Agent-Device Communications
// Device Globals
dummyValue <- 0
function updateWeatherDisplay(forecast)
{
// This function, omitted for clarity, takes the supplied
// forecast value and uses it to present a weather icon
// on the device's display