and this is the device
`
imp.configure(“LED Web Control”, [], []); // Configure the imp
// Setup variables for our pins:
lightreading <- hardware.pin9
redPin <- hardware.pin1; // R of RGB
greenPin <- hardware.pin2; // G of RGB
bluePin <- hardware.pin5; // B of RGB
// Configure our pins:
lightreading.configure(ANALOG_IN);
redPin.configure(PWM_OUT, 0.005, 0); // PWM output 5ms clock, off
greenPin.configure(PWM_OUT, 0.005, 0); // PWM output 5ms clock, off
bluePin.configure(PWM_OUT, 0.005, 0); // PWM output 5ms clock, off
ledState <- 0; // off
ledColor <- { r = 255, g = 255, b = 255 }; // default to white for color
light <- 0;
status<-0;
function setLed(ledStatergb)
{
ledState = ledStatergb;
if (ledState) {
redPin.write(ledColor.r/255.0);
greenPin.write(ledColor.g/255.0);
bluePin.write(ledColor.b/255.0);
}else{
redPin.write(0);
greenPin.write(0);
bluePin.write(0);
status <-false;
ledColor <- { r = 255, g = 255, b = 255 };
}
}
function setRGB(rgbValue)
{
if (ledState) {
ledColor.r = rgbValue.r;
ledColor.g = rgbValue.g;
ledColor.b = rgbValue.b;
redPin.write(ledColor.r/255.0);
greenPin.write(ledColor.g/255.0);
bluePin.write(ledColor.b/255.0);
}
}
function setSensor(ledState)
{
status=ledState;
if (status)
{
readSensor();
}
else
{
redPin.write(0);
greenPin.write(0);
bluePin.write(0);
}
}
function readSensor()
{
light=lightreading.read();
local value = 1- (light / 65535.0);
redPin.write(value);
greenPin.write(value);
bluePin.write(value);
server.log(format(“Lightness is:” +light));
}
// setTimer will turn the LEDs off after a specified number of seconds
// This function will be called by the agent.
function setTimer(time)
{
if (time != 0)
imp.wakeup(time, ledOff); // Call ledsOff in ‘time’ seconds.
}
agent.on(“led”, setLed);
agent.on(“rgb”, setRGB);
agent.on(“timer”, setTimer);
agent.on(“sensor”, setSensor);
// ledsOff just turns all LEDs off.
function ledOff()
{
redPin.write(0);
greenPin.write(0);
bluePin.write(0);
}
`