led pwm

parent 5ee2a199
Showing with 12 additions and 45 deletions
......@@ -2,59 +2,26 @@ var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io')(server);
var isPi = require('detect-rpi');
var Gpio = require('pigpio').Gpio;
/*
GPIO
*/
var Gpio;
var blinkInterval;
var RED;
var RED;
var GREEN;
var BLUE;
if(isPi()){
// Init GPIO
Gpio = require('onoff').Gpio;
// Set port
RED = new Gpio(4, 'out');
GREEN = new Gpio(17, 'out');
BLUE = new Gpio(27, 'out');
blinkInterval = setInterval(blinkRED, 250);
function blinkRED() {
if(RED.readSync() === 1){
RED.writeSync(0);
GREEN.writeSync(1);
}else if(GREEN.readSync() === 1){
GREEN.writeSync(0);
BLUE.writeSync(1);
}else if(BLUE.readSync() === 1){
BLUE.writeSync(0);
RED.writeSync(1);
}else{
RED.writeSync(0);
GREEN.writeSync(0);
BLUE.writeSync(0);
RED.writeSync(1);
}
}
function endBlink() {
clearInterval(blinkInterval);
RED.writeSync(0);
RED.unexport();
}
var RED = new Gpio(4, {mode: Gpio.OUTPUT});
var GREEN = new Gpio(17, 'out');
var BLUE = new Gpio(27, 'out');
setTimeout(endBlink, 15000);
}
var dutyCycle = 0;
setInterval(function () {
RED.pwmWrite(dutyCycle);
dutyCycle += 5;
if (dutyCycle > 255) {
dutyCycle = 0;
}
}, 20);
/*
WEB SERVER
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment