sarahghp / p5bots

Use your microcontroller with p5.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HelloWorld

totovr opened this issue · comments

Hello! I'm trying to setup the hello world example but the Arduino is not interacting with the browser, also I can not install the p5bots-server, instead of it I'm using http-server of node.

index.html:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>Led</title>
</head>

<body>
  <!-- <script src="https://cdn.socket.io/socket.io-1.3.5.js"></script> -->
  <script src="libraries/socket.io-1.4.5.js" type="text/javascript"></script>
  <script src="libraries/p5.js" type="text/javascript"></script>
  <script src="libraries/p5bots.js" type="text/javascript"></script>
  <script src="sketch.js"></script>
</body>

</html>

sketch.js:

var b = p5.board('/dev/cu.usbmodemFA131', 'arduino');
var led;

function setup() {
  led = b.pin(13, 'LED');
}

function keyPressed() {
  if (keyCode === LEFT_ARROW){
    led.on();
  } else if (keyCode === RIGHT_ARROW) {
    led.off();
  } else if (keyCode === UP_ARROW){
    led.blink();
    console.log('Hello, World!');
  } else if (keyCode === DOWN_ARROW) {
    led.noBlink();
  }
}