BLINKING LED


01. Blinking LED

The first example of digital output uses a LED to realize a blinking LED. It can be managed from the Internet via start and stop commands.

Figure 1 - LED circuit

1. Circuit

Connect the LED as shown in figure 1:

  • positive PIN to the PIN d2
  • negative PIN to the PIN GND (Ground).

The long PIN is positive as shown in Figure 2.

2. Sketch

Write a sketch K to define:

  • the output connection: led::d2
  • the commands to control the LED: start, stop
led :: d2   
start = [led=!led #1]   
stop = [led=0]  

or simply load the sketch with the command

] load e01_blink

Figure 2 - positive and negative PIN of a LED

3. Try and learn

Try the following commands now:

  • ] ?
--- Pin connections
led :: d2   
--- Commands
start = [led=!led#1]   
stop = [led=0] 

shows the loaded sketch

  • ] start

the led starts blinking

  • ] pause

the flashing of the led stops

  • ] play

the flashing of the led resumes

  • ] ??
--- Periodic commands
led=!led #1

shows the periodic commands running

  • ] trace=1
ok
] 
# led=!led
] 
# led=!led
...

traces the commands running

  • ] trace=0

ends the tracing

  • ] stop

turns off the led and stops the flashing of the led

  • ] ??
null

stop command also clears the commands running.

4. Summarizing

In this lesson you learned:

  • how to use a LED
  • the commands: load, ?, start, pause, play, ??, trace, stop.