Expand Control of 1 LED to all 6 LEDs from April board code

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


`// create a global variabled called led,
// and assign pin9 to it
led <- hardware.pin9;

// configure led to be a digital output

// function to turn LED on or off
function setLed(ledState) {
server.log("Set LED: " + ledState);


`// 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

You might find what you need here:

and here:

Or for $50, buy the Imp 002 with 12 I/O pins …
View: Item number 2000-0003

Essentially, you want the following at the start of the device code:

led1 <- hardware.pin1 led2 <- hardware.pin2 . . . led9 <- hardware.pin9

and add into requestHandler() in the agent code:

`if (request.query.led == “allon” || request.query.led == “alloff”)
local ledState = 0
if (request.query.led == “allon”) ledState = 1

device.send("led1", ledState)
device.send("led2", ledState)
. . .
device.send("led9", ledState)


This can certainly be optimised and made much more efficient (for speed and for memory footprint), but it should get you started.