Raspberry Node-js GPIO control

  javascript, node-modules, node.js, raspberry-pi

I want to turn the LED on GPIO4 with the button on. But nothing happens. The log would display nothing. I think i failed to open the function or to write the function.

var http = require('http');
var Gpio = require('onoff').Gpio;

var LED = new Gpio(4, 'out');


var http = require('http');
http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.write('<button onclick="LEDon()">ON</button>');
    res.write('<button onclick="LEDoff()">OFF</button>');
    function LEDon(){
        LED.writeSync(1);
        console.log('1');
    }
    
    function LEDoff(){
        LED.writeSync(0);
        console.log('2');
    }
  res.end();
}).listen(8080);

Source: Ask Javascript Questions

LEAVE A COMMENT