08. Fading LED
The first example of analog output uses a LED to realize a fading LED. It can be managed from the Internet via start and stop commands.
Figure 1 - LED 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.
Write a sketch K to define:
- the output connection: led::d2
- the commands to control the LED: start, stop
led :: d2
d = 50
start = [led=led+d *,led=0]
stop = [led=0]
led==0 -> d=50
led==1000 -> d=-50
or simply load the sketch with the command
] load e08_fading_led
3. Try and learn
Try the following commands now:
the brightness of the LED grows (fade in) and decreases (fade out)
the fading of the led stops
the fading of the led resumes
--- Periodic commands
shows the periodic commands running
# led==0 -> d=50
# led==1000 -> d=-50
traces the commands running
ends the tracing
turns off the led and stops the fading of the led
stop command also clears the commands running.
Try replacing the LED with a BUZZER connected to d2. What happens?
In this lesson you learned:
- how to use a LED
- the commands: load, start, pause, play, ??, trace, stop.