Skip to content

Instantly share code, notes, and snippets.

@sreeram-venkitesh
Created December 1, 2020 10:42
Show Gist options
  • Save sreeram-venkitesh/785c3a05fbc35b32613da83a8b5b44b7 to your computer and use it in GitHub Desktop.
Save sreeram-venkitesh/785c3a05fbc35b32613da83a8b5b44b7 to your computer and use it in GitHub Desktop.
PWM with Raspberry Pi and Node.js
const Gpio = require('pigpio').Gpio;
const led = new Gpio(17, {mode: Gpio.OUTPUT});
let dutyCycle = 0;
let interval = setInterval(() => {
led.pwmWrite(dutyCycle);
dutyCycle += 5;
if (dutyCycle > 255) {
dutyCycle = 0;
}
}, 20);
setTimeout(()=> {
clearInterval(interval);
},5000);
led.pwmWrite(255);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment