I wanted to ask you for a favor (dunmb favor as I am not a programmer.
I went through the Get Started and the IMP worked great and gave me the handler to control an LED light.
I need the same code but for 6 LEDs….(for the other 5 pins coming out of the April board.
Essentially I need to control each of the 6 LEDs independently and also have control of turning them all ON and OFF at once.
This is the code from your website……can you guide me what I need to do to this code to control all 6 and not only 1?
I was thinking I need to assign different names and hardware pins to all 6 and do the same for the Device code….
…is there perhaps some code inhouse or perhaps a programmer that could crank this out for me? This would be great progress if I could get this done today.
Best Regards
Jens Paetau
DEVICE CODE
`// create a global variabled called led,
// and assign pin9 to it
led <- hardware.pin9;
// configure led to be a digital output
led.configure(DIGITAL_OUT);
// function to turn LED on or off
function setLed(ledState) {
server.log("Set LED: " + ledState);
led.write(ledState);
}`
AGENT CODE
`// register a handler for “led” messages from the agent
agent.on(“led”, setLed);
// Log the URLs we need
server.log("Turn LED On: " + http.agenturl() + “?led=1”);
server.log("Turn LED Off: " + http.agenturl() + “?led=0”);
function requestHandler(request, response) {
try {
// check if the user sent led as a query parameter
if (“led” in request.query) {
// if they did, and led=1.. set our variable to 1
if (request.query.led == "1" || request.query.led == "0") {
// convert the led query parameter to an integer
local ledState = request.query.led.tointeger();
// send "led" message to device, and send ledState as the data
device.send("led", ledState);
}
}
// send a response back saying everything was OK.
response.send(200, "OK");
} catch (ex) {
response.send(500, "Internal Server Error: " + ex);
}
}
// register the HTTP handler
http.onrequest(requestHandler);`