Reputation: 1
I'm with a problem in my code and I don't know how to solve. My code has a function to blink a led using an Arduino Uno and Johnny-Five library in Nodejs. I'm passing this array from my front-end to my back-end:
[ 'Blink_Led', 'Blink_Led', '' ]
and when it reaches my back-end this array is passed for another list like in the code below:
app.post("/led-blink", async (req, res) =>{
let i = 0
try{
for (i=0 ; i< (req.body.length-1); i++){
console.log(req.body[i]);
switch (req.body[i]) {
case 'Blink_Led':
const led = new five.Led(13);
await led.blink(1000);
//res.json({message: 'sucess!!'});
console.log('Passou aki')
await board.wait(2000, async () => {
await led.off().stop();
res.writeContinue();
});
break;
default:
res.json('NÃO PASSOU NENHUM PARAMETRO VALIDO');
}
}
} catch (error) {
res.status(400).json({message: error.message});
}
res.json({message: 'Sucess!!!'});
});
BUTTTTTTT when entering inside of the loop and goes to the switch
-statement, it's pass and executes the first string of the array and the led blink the first time however it doesn't blink more and finish the loop passing by the other iterations.
I would like to be capable to execute all lines of code, blinking the led on each iteration the loop that appears the string "Blink_Led"
Upvotes: 0
Views: 81