2024-08-17 00:41:12 +00:00
|
|
|
const { exec } = require('child_process');
|
|
|
|
|
|
|
|
// List of pins to toggle
|
|
|
|
const pins = [7, 13, 15, 16, 18, 22];
|
|
|
|
|
|
|
|
// Function to toggle a pin
|
|
|
|
function togglePin(pin, callback) {
|
|
|
|
exec(`python3 src/python/gpio_interface.py toggle ${pin}`, (error, stdout, stderr) => {
|
|
|
|
if (error) {
|
|
|
|
console.error(`Error toggling pin ${pin}: ${error.message}`);
|
|
|
|
return callback(error);
|
|
|
|
}
|
|
|
|
if (stderr) {
|
|
|
|
console.error(`Stderr while toggling pin ${pin}: ${stderr}`);
|
|
|
|
return callback(new Error(stderr));
|
|
|
|
}
|
|
|
|
console.log(`Successfully toggled pin ${pin}`);
|
|
|
|
callback(null);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Toggle all pins
|
|
|
|
function toggleAllPins(pins, index = 0) {
|
|
|
|
if (index >= pins.length) {
|
|
|
|
console.log('All pins toggled.');
|
|
|
|
process.exit(0); // Exit successfully
|
|
|
|
} else {
|
|
|
|
togglePin(pins[index], (err) => {
|
|
|
|
if (err) {
|
|
|
|
process.exit(1); // Exit with error
|
|
|
|
} else {
|
|
|
|
setTimeout(() => toggleAllPins(pins, index + 1), 1000); // 1-second delay between toggles
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start toggling pins
|
|
|
|
toggleAllPins(pins);
|