Blog Forum Contact Us

low.js Tutorial: Blink LED

With microcontroller boards, getting the on-board LED to blink is one of the simplest tasks you can do. In this example, we are doing exactly this.

For neonious one owners:

This example works with any ESP32-WROVER board. As the neonious one has an IDE, you can get to the same result a whole lot easier without using lowsync:

See the neonious one documentation for more information on the IDE.

Please make sure you have lowsync installed and low.js flashed. If not, please read Getting Started.

Step 1: Connect to the microcontroller's Wifi

The Wifi SSID and password to use should have been outputted by the flash command.

Step 2: Create a new project directory

In the new directory, initialize the project by entering the following command in the terminal:

my_project_directory> lowsync init

If lowsync asks questions, you can just skip them by pressing Enter. The default values will work.

Step 3: Write program code

Figure out what pin the on-board LED is connected to. For neonious one, the red LED is connected to pin 1.

Enter the following code into a new file index.js:

Is the example not working as expected?

Try checking the status with lowsync status.

To start or restart the program call lowsync start.

You can also check for any (error-) output by calling lowsync monitor and then fix any errors you find in your editor.

Remember to call lowsync sync after any changes you make.

let gpio = require('gpio');

let val = 0, dir = 0;
setInterval(() => {
    val += dir ? 0.03 : -0.03;
    if(val < 0) { val = 0; dir = 1; }
    if(val > 1) { val = 1; dir = 0; }

}, 30);

For fun, this program does not simply blink the LED, it fades the LED in and out with PWM.

Step 4: Sync and run

For syncing with the file system, enter

my_project_directory> lowsync

On this first run, lowsync will ask you if you want to delete the preinstalled example program, which you will want to do. After this syncing works both ways: If your low.js application writes log files, the sync command would sync them back to the PC, too.

If the program already ran, lowsync will ask you if you wish to restart the program. Enter yes here. If it did not ask, you can start the program by entering

my_project_directory> lowsync start

Next tutorial: Control LED via Website