In this guide, we'll create a simple script that outputs ordinal numbers with a delay and learn how to run it on Flipper Zero in different ways. All you need is your Flipper Zero, a PC, and a USB cable.
Create a new text file first_app.js
. Paste the code below into it and save the file:
What the code does:
The print()
function is used to output text. The string to be output is in the brackets. This is a built-in function, so you don't need to include additional JS modules. You can use this function anywhere in your application.
Another built-in function, delay()
, implements delay. The delay time in milliseconds is given in the brackets. Since 1000 milliseconds equals 1 second, a 1-second delay is written as 1000, and a 0.5-second delay as 500.
To copy the JavaScript file to Flipper Zero, follow these steps:
SD Card/apps/Scripts/
.Your script is now ready to run on Flipper Zero.
You can launch your app in two ways:
Let's explore them both.
SD Card/apps/Scripts/
folder.The Flipper Zero screen will display the strings with the specified delay, as defined by the print()
and delay()
functions.
The command-line interface (CLI) is a text-based interface that lets you control your Flipper Zero from your computer, including running scripts. Running JavaScript apps via CLI is useful for debugging, as it lets you write and test code remotely, without switching between your PC and the device.
To run the script via CLI:
js path
command, replacing path
with the path to the script file on your Flipper Zero:As you can see, unlike running JavaScript apps from the Flipper Zero UI, all output from the print()
function is sent to the CLI, not the device screen.
Next step: Developing apps using JavaScript SDK