RELAY EFFECT

06. Relay effect

This digital input example uses a Button to switch the status of a LED every time it is pushed.

Figure 1 - relay effect circuit

1. Circuit

The circuit is the same as in the previous example.

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 start and stop the system: start, stop
  • the rules to implement the automaton (Figure 2).

When the automa has 2 states use led as a status variable.

Button :: !D3
gnd :: d8
led :: d7
Click = Button==1
start = [gnd=0,led=0]
stop = [led=0]
!led & Click -> led=1 ##
 led & Click -> led=0 ##

or simply load the sketch in the workspace with the command

] load e06_relay_effect

Figure 2 - relay effect automaton

3. Try and learn

Initialize the system with the command:

  • ] start

the LED is off.

Press and release the button

  • > Click

the LED turns on and the Click event is sent to the Internet

Press and release the button

  • > Click

the LED turns off and the Click event is sent to the Internet

4. Summarizing

In this lesson you learned or repeated:

  • how to use a Button
  • the commands: start, stop, ##
  • use led as a status variable.