Disability Aid

RNovember

Well-known member
So I just want to to get everything right.

1. All that needs to happen is that if one button is pushed, its LED comes on, and all the other LEDs are switched off, regardless of the order that the buttons are pressed.

2. There needs to be three inputs, one from each button.

3. There needs to be three outputs, one to each LED.

4. It needs to work! :)

Am I right in suspecting this, if so, let us know.
 

hippy

Technical Support
Staff member
doesn’t matter if the wrong button is pushed the same corresponding single LED lights. The teacher notes that the student didn’t copy the number pattern that she did
That makes sense. So it really is a case of push any button, light the corresponding LED.

The following code will work in simulation and should on an actual chip. It turns the LED on which corresponds to the button pushed, turns them all off after two seconds of no push, for when the teacher has entered her sequence, and after the child has repeated it.
Code:
#Picaxe 08M2
#No_Data

Symbol LED1       = C.2
Symbol LED2       = C.1
Symbol LED3       = C.0

Symbol BUTTON1    = pinC.3
Symbol BUTTON2    = pinC.4
Symbol BUTTON3    = pinC.5

Symbol PUSHED     = 1  ; Active high buttons

Symbol timeout    = w1 ; b3:b2
Symbol buttonPush = b4
Symbol wanted     = b5

Symbol NONE       = 0  ; No button pushed

Symbol TIMEOUT_MS = 2000

Disconnect ; Because we are using C.5 as an input
Gosub TurnAllLedsOff
Do
  Gosub WaitForNoButtonsPushed
  Gosub WaitForButtonPushOrTimeout
  Gosub IndicatePushed
Loop

TurnLed1On:
  High LED1
  Return

TurnLed1Off:
  Low LED1
  Return

TurnLed2On:
  High LED2
  Return

TurnLed2Off:
  Low LED2
  Return

TurnLed3On:
  High LED3
  Return

TurnLed3Off:
  Low LED3
  Return

TurnAllLedsOff:
  Gosub TurnLed1Off
  Gosub TurnLed2Off
  Gosub TurnLed3Off
  Return

IndicatePushed:
  Gosub TurnAllLedsOff
  Pause 100
  Select Case buttonPush
    Case 1 : Gosub TurnLed1On
    Case 2 : Gosub TurnLed2On
    Case 3 : Gosub TurnLed3On
  End Select
  Return

WaitForNoButtonsPushed:
  Do : Loop While BUTTON1 Is PUSHED _
               Or BUTTON2 Is PUSHED _
               Or BUTTON3 Is PUSHED
  Return

WaitForButtonPushOrTimeout:
  buttonPush = NONE
  timeout = 0
  Do
    If BUTTON1 Is PUSHED Then : buttonPush = 1 : End If
    If BUTTON2 Is PUSHED Then : buttonPush = 2 : End If
    If BUTTON3 Is PUSHED Then : buttonPush = 3 : End If
    Pause 100 
    timeout = timeout + 100  
  Loop Until buttonPush <> NONE Or timeout >= TIMEOUT_MS
  Return
 

Desert Dan

New Member
Just thought i’d check how the switch on output 2 should be connected. The usual way of 10K resistor from output 2 (pin 5) to ground and then the normally open switch from the same pin 5 to supply? Or is it different because output 2 is not normally used as an input. Circuit drawing attached, cheers DanFFB3C0B5-4D6E-4E1A-85F2-948808F2B921.jpegFFB3C0B5-4D6E-4E1A-85F2-948808F2B921.jpegFFB3C0B5-4D6E-4E1A-85F2-948808F2B921.jpegFFB3C0B5-4D6E-4E1A-85F2-948808F2B921.jpegFFB3C0B5-4D6E-4E1A-85F2-948808F2B921.jpegFFB3C0B5-4D6E-4E1A-85F2-948808F2B921.jpeg
 

Desert Dan

New Member
So I just want to to get everything right.

1. All that needs to happen is that if one button is pushed, its LED comes on, and all the other LEDs are switched off, regardless of the order that the buttons are pressed.

2. There needs to be three inputs, one from each button.

3. There needs to be three outputs, one to each LED.

4. It needs to work! :)

Am I right in suspecting this, if so, let us know.
Terrific RN you got it !!!!!! What the teacher does with the result is up to them. Thank you Thank you
Many double happy’s Dan 🤗😋👍
 

Desert Dan

New Member
Just thought i’d check how the switch on output 2 should be connected. The usual way of 10K resistor from output 2 (pin 5) to ground and then the normally open switch from the same pin 5 to supply? Or is it different because output 2 is not normally used as an input. Circuit drawing attached, cheers DanView attachment 22839View attachment 22839View attachment 22839View attachment 22839View attachment 22839View attachment 22839
Small error, the capacitor (100nf) from pin 1 does go to ground not supply, drawing error 😞
 

RNovember

Well-known member
I think that your schematic wants to look like this:
Code:
  ^        Power     ^
resistor         ____|___
  |_____________|c.5  c.0|__LED_______
    |    _______|c.4  c.1|__LED____   |
    |   |   ____|c.3  c.2|__LED_   |  |
    |   |  |    |        |      |  |  |
    |   |  |    '--------'      |  |  |
    |   |  |                    |  |  |
    \/  \/ \/                   \/ \/ \/
                                Ground
Then put some pullup resistors after the second line of Hippy's code like this: pullup %00000011
 
Last edited:

Desert Dan

New Member
So I just want to to get everything right.

1. All that needs to happen is that if one button is pushed, its LED comes on, and all the other LEDs are switched off, regardless of the order that the buttons are pressed.

2. There needs to be three inputs, one from each button.

3. There needs to be three outputs, one to each LED.

4. It needs to work! :)

Am I right in suspecting this, if so, let us know.
 

hippy

Technical Support
Staff member
This is how I would wire things -
Code:
      .--------------------------------------.
      |         .----.----.---.----------.---|--------------.-- V+
      |         |    |    |   |          |   |              |
      |       _|O  _|O  _|O   |         _|_  |              |
      |      |_|  |_|  |_|    |   100nF -.-  |              |
      |        |O   |O   |O   |          |   |              |
SO <--'         |    |    |   |  .-__-.  |   |              |
          ___   |    |    |   `--|    |--{   |   ___        |
SI >--.--|___|--^----|----|------|    |--|---^--|___|--|<|--{
      |   22K        }----|------|    |--|------|___|--|<|--{
      |              |    }------|    |--|------|___|--|<|--'
     .|.            .|.  .|.     `----'  |
     | |            | |  | |      08M2   |     3 x R + LED
     |_| 10K    10K |_|  |_| 10K         |
      |              |    |              |
0V ---^--------------^----^--------------^--------------------- 0V
Note the LED anodes go to V+. This will make them active low; they will light when the output is set LOW, will be off when set HIGH.

This allows the wiring to the buttons, each of which will contain a LED, to be more easily done. Each will only need three wires ( V+, button signal, LED signal ) rather than four which would be the case if the LED cathodes went to 0V -
Code:
     .------------.
     |       _    |
     |     _|_|_  | 
V+ --|--.--O   O--|--> Button input
     |  |         |
     |  `---|>|---|--< LED output
     |            |
     `------------'
 
Last edited:

AllyCat

Senior Member
Hi,

A "minimalist" solution needs only three PICaxe I/O pins and one resistor (if the LEDs are the same colour). ;)

Each grounded push-switch (i.e. Active Low) illuminates its respective LED directly, with the junction (LED cathode) connected to a PICaxe pin. The PICaxe pin (configured as an input) detects the Low level, switches off any other LED and pulls its own LED Low (so that it stays illuminated when the button is released). If all the LEDs are the same colour their anodes can be commoned and a single resistor from the supply rail feeds current to whichever is active. If the LEDs are different colours then separate series resistors would allow their brightness to be optimised/balanced.

Code:
#picaxe 08m2
pullup  %10110    ; Pull input pins High
do
  if pinc.1 = 0 then LED1on
  if pinc.2 = 0 then LED2on
  if pinc.4 = 0 then LED3on
loop
LED1on:
  input c.2 , c.4 : Low c.1
do  
  if pinc.2 = 0 then LED2on
  if pinc.4 = 0 then LED3on
loop    
LED2on:
  input c.1 : input c.4  : Low c.2
do  
  if pinc.1 = 0 then LED1on
  if pinc.4 = 0 then LED3on
loop 
LED3on:
  input c.1 : input c.2 : Low c.4
do  
  if pinc.1 = 0 then LED1on
  if pinc.2 = 0 then LED2on
loop
The main problem is that the Simulator can't really handle this code. I'm not particularly surprised that it doesn't recognise the PULLUP command (so assumes the inputs are all Low). But even a PINSC = %10110 doesn't seem to fix it, so it's necessary to pause the simulation at the start and manually toggle the inputs to High. Even then, PE5 can't handle the simulation at all, but PE6 can be patched with a few extra lines of code, e.g. :
Code:
#picaxe 08m2
pullup  %10110
pinsc = %10110       ; Doesn't seem to work in simulator, so......
pause 10000            ; For Simulation, manually toggle the inputs to High (Yellow)
do
  if pinc.1 = 0 then LED1on
  if pinc.2 = 0 then LED2on
  if pinc.4 = 0 then LED3on
loop
LED1on:
  input c.2 , c.4 : Low c.1
  pinsc = %10110            ; Only required for simulator patch
do  
  if pinc.2 = 0 then LED2on
  if pinc.4 = 0 then LED3on
loop    
LED2on:
  input c.1 : input c.4  : Low c.2
  pinsc = %10110            ; Only required for simulator patch
do  
  if pinc.1 = 0 then LED1on
  if pinc.4 = 0 then LED3on
loop 
LED3on:
  input c.1 : input c.2 : Low c.4
  pinsc = %10110            ; Only required for simulator patch
do  
  if pinc.1 = 0 then LED1on
  if pinc.2 = 0 then LED2on
loop
Cheers, Alan.
 

Desert Dan

New Member
This is how I would wire things -
Code:
      .--------------------------------------.
      |         .----.----.---.----------.---|--------------.-- V+
      |         |    |    |   |          |   |              |
      |       _|O  _|O  _|O   |         _|_  |              |
      |      |_|  |_|  |_|    |   100nF -.-  |              |
      |        |O   |O   |O   |          |   |              |
SO <--'         |    |    |   |  .-__-.  |   |              |
          ___   |    |    |   `--|    |--{   |   ___        |
SI >--.--|___|--^----|----|------|    |--|---^--|___|--|<|--{
      |   22K        }----|------|    |--|------|___|--|<|--{
      |              |    }------|    |--|------|___|--|<|--'
     .|.            .|.  .|.     `----'  |
     | |            | |  | |      08M2   |     3 x R + LED
     |_| 10K    10K |_|  |_| 10K         |
      |              |    |              |
0V ---^--------------^----^--------------^--------------------- 0V
Note the LED anodes go to V+. This will make them active low; they will light when the output is set LOW, will be off when set HIGH.

This allows the wiring to the buttons, each of which will contain a LED, to be more easily done. Each will only need three wires ( V+, button signal, LED signal ) rather than four which would be the case if the LED cathodes went to 0V -
Code:
     .------------.
     |       _    |
     |     _|_|_  |
V+ --|--.--O   O--|--> Button input
     |  |         |
     |  `---|>|---|--< LED output
     |            |
     `------------'
Hi Hippy,
Ah the third switch should be connected to pin 2! now it works!!!! I assumed it went on pin 5, it’s the novice confusion of output numbers versus pin numbers. Thanks to all those that replied to my request, all very much appreciated. I’ll put it all into a box and get back to you with the result.
Cheers Desert Dan
 
Top