0

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"

emccracken
  • 839
  • 12
  • 21
  • Executed your code, looks like its working. here is my output: Blink_Led Passou aki, Blink_Led, Passou aki. Request finishes with status 200. msg: Success. What do you expect? – Danizavtz Jul 29 '20 at 02:05
  • when you use an Arduino with led the first string of array (Blink_Led), trigger the Led but from second onwards, don't trigger the Led on Arduino but pass in the Logs. So I would like to active the Led all times that the string Blink_Led pass by Switch – Gabriel Dadalto Jul 31 '20 at 20:32

0 Answers0