-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblink.js
More file actions
14 lines (13 loc) · 810 Bytes
/
blink.js
File metadata and controls
14 lines (13 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
const Gpio = require('onoff').Gpio; // Importiert die Gpio-Klasse aus der onoff-Bibliothek
const led = new Gpio(17, 'out'); // Erstellt ein neues Gpio-Objekt für Pin 17 als Ausgang
const blinkInterval = setInterval(() => {
const value = (led.readSync() + 1) % 2; // Liest den aktuellen Status, invertiert ihn (0 -> 1, 1 -> 0)
led.writeSync(value); // Schreibt den neuen Status an den Pin
}, 1000); // Wiederholt den Vorgang alle 1000 ms (1 Sekunde)
// Stoppt das Programm, wenn Sie Strg+C drücken
process.on('SIGINT', () => {
clearInterval(blinkInterval); // Stoppt das Blink-Intervall
led.writeSync(0); // Stellt sicher, dass die LED ausgeschaltet wird
led.unexport(); // Gibt den GPIO-Pin frei
process.exit();
});