Created
December 1, 2020 10:42
-
-
Save sreeram-venkitesh/785c3a05fbc35b32613da83a8b5b44b7 to your computer and use it in GitHub Desktop.
PWM with Raspberry Pi and Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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