Reply To: problem with Phonegap connect breakout js
About › Forums › Forum › problem with Phonegap connect breakout js › Reply To: problem with Phonegap connect breakout js
December 4, 2015 at 1:51 AM
#1029
soundanalogous
Member
You don’t need to use Phonegap to control the LED from your phone. Your phone needs to be on the same network as the computer the Arduino is connected to.
Here is the code for the simple_led.html example. See the note above the host variable declaration. You can then serve this page either using the web server built into BreakoutServer or from a separate web server.
$(document).ready(function() {
// Declare these variables so you don't have
// to type the full namespace
var IOBoard = BO.IOBoard;
var IOBoardEvent = BO.IOBoardEvent;
var LED = BO.io.LED;
// attach fastclick to avoid 300ms click delay on mobile devices
FastClick.attach(document.body);
// update this to the IP address of the computer the Arduino is connected to
var host = "192.168.0.10";
var arduino = new IOBoard(host, 8887);
// Listen for the IOBoard READY event which indicates the IOBoard
// is ready to send and receive data
arduino.addEventListener(IOBoardEvent.READY, onReady);
function onReady(event) {
// Remove the event listener because it is no longer needed
arduino.removeEventListener(IOBoardEvent.READY, onReady);
// Create an LED object to interface with the LED wired
// to the I/O board
var led = new LED(arduino, arduino.getDigitalPin(13));
// jQuery part for the button
$('#button').click(function () {
var btn = $(this);
if (btn.text() === "LED On") {
btn.text("LED Off");
} else {
btn.text("LED On");
}
led.toggle();
});
}
});