-1

I'm a beginner with the javascript language, I wanted to create a project where by pressing a button on an HTML page I could turn on a connected LED on an arduino board. I have seen that it is possible to use arduino functions through a javascript library called "johnny-five". The problem is that when I've wrote in the javascript code included in the HTML file: var five = require("Johnny-five"); an error occurs in the web page console: require is not defined .... I've read something on the internet, but I didn't understand much. I'd be happy to know how to fix it, thanks!`

VyLo
  • 1
  • Does this answer your question? [Client on node: Uncaught ReferenceError: require is not defined](https://stackoverflow.com/questions/19059580/client-on-node-uncaught-referenceerror-require-is-not-defined) – Dylan Jun 17 '20 at 16:59

1 Answers1

0

Your johnny-five library import and all the LED logic will go into a .js file, not into HTML. The first step is to have Nodejs and the johnny-five npm package installed. This is an easy way to get started: http://johnny-five.io/#hello-world

Next, the HTML file with the button will need to call a function on its onclick event,which connects to your johnny-five logic via event-listeners/sockets. You may find this useful

I put together a quick project that does exactly what you want: Clicking on a button in a HTML page triggers LED blinking. Check it out here. I've given detailed instructions on how to run it as well.

Meera
  • 88
  • 9
  • I tried to copy all the code that is written in the link that you sent me. But even copying and correcting the example thanks to the comment below, it doesn't work. So I don't know where to take a good example to understand how to apply it in mine. :) – VyLo Jun 24 '20 at 18:30
  • @VyLo I put together a quick project that does exactly what you want: Clicking on a button in a HTML page triggers LED blinking. Check it out here: https://github.com/meerasndr/arduino-webcontrolled-led . I've given detailed instructions on how to run it as well. Let me know if you have any questions. – Meera Jun 25 '20 at 09:42