LED Bar Control

Five blue LEDs form an LED bar. They are intended primarily for the indication of the RF signal strength (i.e. of the Wi-Fi signal). These LEDs are controlled through three GPIO lines 46, 47, and 48.

GPIO46 is the reset line of the LED bar. Clearing this line sets all five outputs LOW and this turns all LEDs ON. GPIO47 is a clock line- a positive (LOW-to-HIGH) transition on this line "shifts in" the data on the data line. The LED control circuit is shown below.

tpp_led_barTPP_led_bar_control

If you want to switch an LED ON then set the corresponding data line LOW. In the following example we set the LEDs like this:

LED #5

LED #4

LED #3

LED #2

LED #1

OFF

ON

OFF

ON

ON

Assuming all the LEDs were off previously (shown in gray), these are our steps. Each step represents one cycle of the clock line (HIGH-LOW-HIGH):

Clock

Data

LED #5

LED #4

LED #3

LED #2

LED #1

1

LOW

ON

OFF

OFF

OFF

OFF

2

LOW

ON

ON

OFF

OFF

OFF

3

HIGH

OFF

ON

ON

OFF

OFF

4

LOW

ON

OFF

ON

ON

OFF

5

HIGH

OFF

ON

OFF

ON

ON

The reset line is not really necessary. You can be certain what pattern is displayed by the LEDs for as long as you generate five clock cycles every time you send new data into this circuit.

Here is our library code for controlling the LED bar:

** Tibbo Basic **

sub on_sys_init
...
   'enable the control lines (notice that the use of the RST line is not really necessary)   
   io.num=PL_IO_NUM_46
   io.enabled=YES
   io.num=PL_IO_NUM_47
   io.enabled=YES
   io.num=PL_IO_NUM_48
   io.enabled=YES

   signal_strength_set(0) 'this will turn all 5 LEDs OFF
...
end sub

sub signal_strength_set(strength as byte)
'Bits 0-5 of strength argument correspond to LEDs (bit5 is for the LED #5, bit0 -- for LED #0)   

   dim f,x as byte
   dim s as string(8)

   s=mid(bin(strength),3,8)
   s=strgen(8-len(s),"0")+s   

   'make 5 clocks
   io.num=PL_IO_NUM_47
   for f=0 to 4
      x=1-val(mid(s,f+4,1))
      io.lineset(PL_IO_NUM_48,x)
      io.state=LOW
      io.state=HIGH
   next f
end sub