BUTTON

05. Button

This digital input example uses a Button to turn on and off a led.

Figure 1 - button circuit

1. Circuit

Connect the Button and the led as shown in Figure 1:

  • led positive PIN to d7
  • led negative PIN to d8
  • Button to PINs D3 and GND.

Notes:

The longer LED PIN is the positive.

Button PINs can also be inverted.

2. Sketch

Write a sketch K to define:

  • the output connections: led :: d7, gnd :: d8
  • the input connections: Button :: !D3
  • the command to initialize the system: start
Button :: !D3
gnd :: d8
led :: d7
start = [gnd=0,led=Button #]

or simply load the sketch in the workspace with the command

] load e05_button

3. Try and learn

Initialize the system with the command:

  • ] start

the LED is off.

If you press the button the LED lights up and if it is released the LED goes out.

4. Summarizing

In this lesson you learned or repeated:

  • how to use a Button
  • the command: start.