Skip to content

Instantly share code, notes, and snippets.

View cat-haines's full-sized avatar

Cat Haines cat-haines

View GitHub Profile
@cat-haines
cat-haines / web.config
Created September 25, 2012 01:36
This goes in your API folder of Nancy + AppHarbor project - you DO NOT add anything to any other web.configs in the project to make it work
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="Off" />
<httpHandlers>
<add verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" path="*"/>
</httpHandlers>
</system.web>
@cat-haines
cat-haines / electricimp - hello world
Last active December 11, 2015 02:59
electric imp code for a "hello world" program - doesn't get much simpler than this.
// This line of code will be shown in the planner to help identify what the code module does.
imp.configure("first program", [], []);
server.show("Hello from beardedinventor!");
@cat-haines
cat-haines / electricimp - blink
Last active December 11, 2015 03:08
electric imp code to make an led blink
@cat-haines
cat-haines / electric imp - read button
Created January 19, 2013 19:25
electric imp code to read a digital signal and react when it changes.
// Register with the server
imp.configure("button example", [], []);
// readButton function called every 100ms
function changeState()
{
local pinState = hardware.pin1.read();
if (pinState)
server.show("pressed");
else
@cat-haines
cat-haines / electric imp - read button (and send to output signal)
Last active November 24, 2023 04:40
electric imp code to read a button, and send it to an output signal (to be processed in another node).
// readButton function called every 100ms
function changeState()
{
local buttonState = hardware.pin1.read();
buttonOutput.set(buttonState)
}
// set pin1 as a digital input with a pullup resistor and call changeState when the stateChanges
hardware.pin1.configure(DIGITAL_IN_PULLUP, changeState);
@cat-haines
cat-haines / electric imp - read sensor on press
Created January 19, 2013 20:59
This example reads the value of an analog sensor hooked up to pin 2, and writes it to the server whenever the button is pressed.
// Register with the server
imp.configure("Press button to read", [], []);
// readButton function called every 100ms
function changeState()
{
local pinState = hardware.pin1.read();
if (pinState)
{
local sensorValue = hardware.pin2.read();
@cat-haines
cat-haines / SimpleInputPort
Last active December 14, 2015 00:49
ElectricImp code for setting an LED based on value from an InputPort
class simpleInputPort extends InputPort
{
function set(value)
{
if (value == 1)
{
server.show("on");
hardware.pin2.write(0);
}
else if (value == 0)
@cat-haines
cat-haines / RGB Imp
Last active December 14, 2015 02:29
Electric Imp code to go with Electric_Imp_Example repository. Passes RGB json object to Electric_Imp_Example API.
local redPot = hardware.pin5;
local greenPot = hardware.pin7;
local bluePot = hardware.pin8;
local red = 0;
local green = 0;
local blue = 0;
local redPort = OutputPort("red");
local greenPort = OutputPort("green");
@cat-haines
cat-haines / gist:5014004
Created February 22, 2013 14:57
Electric Imp code for polling an analog input every half second.
imp.configure("Analog In", [], []);
function readPots()
{
local p = hardware.pin5.read();
server.show(p);
imp.wakeup(0.5, readPots);
}
hardware.pin5.configure(ANALOG_IN);
@cat-haines
cat-haines / HttpRequestResponse.nut
Created April 19, 2013 21:10
Electric Imp example code that processes an incoming HTTP Request (through an HttpIn node hooked up to an InputPort) and sends a "response" (which is actually just an HTTP Post to a predefined location).
// This is the function that actually handles the incoming HTTP Request
function SimpleRequestHandler(data) {
server.log("Got a request with value='" + data + "'");
return 200;
}
// handles incoming HttpIn requests, and sends "responses" to an HttpRequest node through
// an output port. The ResponsePort sends a url-encoded message where "value" is the response code.
class HttpInPortWithResponse extends InputPort {
RequestHandler = null; // function that will be called whenever a request comes into the input port. Should return a status code.