@esi915 via YouTube (http://youtu.be/ev45JqWW35Y): This is the code you asked about. I’ve since switched to using the new IDE with separate agent code which is much more versatile than the old planner.
Web app code:
I’m using JQuery, Bootstrap, modernizer, and bootstrap slider (http://www.eyecon.ro/bootstrap-slider).
`LED Off
$('.slider1').slider()
.on('slide', function(e){
var url = 'https://api.electricimp.com/v1/.../...';
cmd_value = parseFloat(e.value).toFixed(2);
$.post(url, JSONout);
});
$("#led_button").click(function() {
if ($(this).text() == "LED Off")
{
$(this).text("LED On");
$(this).removeClass("btn-default");
$(this).addClass("btn-success");
cmd_value = 1;
}
else
{
$(this).text("LED Off");
$(this).removeClass("btn-success");
$(this).addClass("btn-default");
cmd_value = 0;
}
var JSONout = {
value: {
"c" : "l",
"v" : cmd_value
}
};
var url = 'https://api.electricimp.com/v1/.../...';
$.post(url, JSONout);
});
`
Device Code:
`// Configure hardware
// Set up PWM on both pins at a period of 20 ms, and initialize the duty cycle
hardware.pin1.configure(PWM_OUT, 0.02, 0.085);
hardware.pin9.configure(DIGITAL_OUT_OD_PULLUP);
server.log(“Hardware Configured”);
class servo extends InputPort
{
name = "Servo position"
type = "number"
function set(value) {
hardware.pin1.write(0.04 + (value * 0.09));
server.show(format("%s = %.2f", name, value));
if(value)
{
hardware.pin9.write(0);
}
else
{
hardware.pin9.write(1);
}
}
}
class TableIn extends InputPort
{
name = "HTTP Data"
type = “array”
function set(value) {
server.show("c: "+value.c+" v: "+value.v);
if (value.c == "s")
{
hardware.pin1.write(0.04 + (value.v.tofloat() * 0.09));
}
else if (value.c == "l")
{
if (value.v == "1")
{
hardware.pin9.write(0);
}
else if (value.v == "0")
{
hardware.pin9.write(1);
}
}
}
};
imp.configure(“Servo Controller”, [servo(), TableIn()], []);
`