November 21, 2024, 11:59:20 PM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


How do I do this?

Started by Raisin-Toe, August 26, 2008, 10:33:40 PM

Previous topic - Next topic

Raisin-Toe

How do I do this?

My wife wants to have a traffic light in her classroom at school. During a class assignment the light will be on yellow meaning she wants the class to be quiet but that some soft talk is allowed. Red means she expects the class to be completley quiet - like during a test. Green is of coarse - talking is allowed. All three lights will not be on at the same time. When one of the lights is triggered via a manual push button or some kind of switch, the light needs to flash for about 15 seconds and then go steady. It will stay steady until power is removed or a reset.

Jeff

JonnyMac

August 27, 2008, 12:51:35 AM #1 Last Edit: August 28, 2008, 06:11:45 PM by JonnyMac
Assuming you're using an RC-4 with your Prop-1 to control the lights this program should work.  The buttons for the lights will connect to P0 (green), P1 (yellow), and P2.  Use a normally-open push-button across the white and red pins of each IO point.

' =========================================================================
'
'   File...... Class_Stoplight.BS1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2008 EFX-TEK
'              Some Rights Reserved
'              -- see http://creativecommons.org/licenses/by/3.0/
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated...  28 AUG 2008
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN

SYMBOL  RedBtn          = PIN2                  ' P2.W and P2.R
SYMBOL  YelBtn          = PIN1                  ' P1.W and P1.R
SYMBOL  GrnBtn          = PIN0                  ' P0.W and P0.R


' -----[ Constants ]-------------------------------------------------------

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0

SYMBOL  Baud            = OT2400

SYMBOL  GRN             = %001
SYMBOL  YEL             = %010
SYMBOL  RED             = %100


' -----[ Variables ]-------------------------------------------------------

SYMBOL  lamps           = B0
SYMBOL   grnLamp        =  BIT0                 ' RC-4.K0
SYMBOL   yelLamp        =  BIT1                 ' RC-4.K1
SYMBOL   redLamp        =  BIT2                 ' RC-4.K2

SYMBOL  btns            = B2
SYMBOL  idx             = B3
SYMBOL  flasher         = B4
SYMBOL  flashes         = B5
SYMBOL  flashDelay      = B6


' -----[ Initialization ]--------------------------------------------------

Reset:
  SEROUT Sio, Baud, ("!!!!!RC4", %00, "X")      ' reset the RC-4


' -----[ Program Code ]----------------------------------------------------

Main:
  GOSUB Scan_Buttons                            ' check buttons

Check_Green:
  IF btns <> GRN THEN Check_Yellow
    flasher = GRN
    GOTO Flash_Lamp

Check_Yellow:
  IF btns <> YEL THEN Check_Red
    flasher = YEL
    GOTO Flash_Lamp

Check_Red:
  IF btns <> RED THEN Main
    flasher = RED

Flash_Lamp:                                     ' flash and leave lamp on
  lamps = flasher
  FOR flashes = 1 TO 30                         ' flash about 15 seconds
    GOSUB Update_Lamps                          ' 1 x 30ms =  30ms
    FOR flashDelay = 1 TO 8                     ' 8 x 50ms = 400ms
      GOSUB Scan_Buttons
      IF btns <> %000 THEN Check_Green          ' abort on button press
    NEXT
    PAUSE 70                                    ' pad for 500 ms
    lamps = lamps ^ flasher                     ' toggle lamp
  NEXT
  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------

' Scans and debounces button inputs

Scan_Buttons:
  btns = %111                                   ' assume pressed
  FOR idx = 1 TO 10
    btns = btns & PINS                          ' scan buttons
    PAUSE 5
  NEXT
  btns = btns & %00000111                       ' clear unused inputs
  RETURN

' -------------------------------------------------------------------------

Update_Lamps:
  SEROUT Sio, Baud, ("!RC4", %00, "S", lamps)
  RETURN

' -------------------------------------------------------------------------


' -------------------------------------------------------------------------


' -------------------------------------------------------------------------


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office

Raisin-Toe

August 28, 2008, 05:17:38 PM #2 Last Edit: August 28, 2008, 05:45:11 PM by Raisin-Toe
Awesome!

But I'm not sure what position my jumpers should be at.

Also, am I not understanding where the buttons go? because I thought that only the P6, and P7 could be used for input.

JonnyMac

No, in fact any pin can be used as an input, especially active-high inputs; the reason for this is that the ULN acts like a pull-down (which is why we have to remove it for serial communications).  I updated your listing to show that your buttons will connect to P0, P1, and P2.  The easiest way to do this is to cut one end of an extension cable off and solder a normally-open push-button between the White and Red wires.

Like this (you'll need three of these):



Jon McPhalen
EFX-TEK Hollywood Office

Raisin-Toe

Thanks for your help, but I still have more questions :-[.

Could I ask you to give me a full illustration of the Prop1 and the RC-4?

JonnyMac

I'm not as good at doing illustrations as I am at writing code so it will take a bit of time.
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

September 01, 2008, 09:07:04 AM #6 Last Edit: September 01, 2008, 09:10:13 AM by JonnyMac
Okay, here you go.  Now... since you asked for this illustration I am no assuming you have no experience wiring 120 VAC circuits.  Please do not go it alone; get help from someone who has previously worked with 120 VAC wiring.  It can be very dangerous and you could be seriously injured if you make a mistake.  A flashing traffic light is not worth getting hurt for.

For clarity I have only shown the Prop-1 and RC-4 connections.  Of course, you'll need to power the Prop-1 and connect the three button circuits (described above) to P0, P1, and P2.

Jon McPhalen
EFX-TEK Hollywood Office

Raisin-Toe

Thank you very much ;D,

I can take care of the 120 V, I've done a lot of electrical work in the past. But this Prop-1 stuff is all new to me, Thanks for your help.

Raisin-Toe

The Traffic Light program is working good, there was one minor flaw that I fixed, but every thing else is working like it should ;D.

I have added another mode to the program that puts the lights through a normal traffic light sequence. It tiggers through a fourth button that I added, (named sequence). But after I push the "sequence" button, the yellow, and red buttons simply stop sending information ???, What could the problem be?





' =========================================================================
'
'   File...... Class_Stoplight.BS1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2008 EFX-TEK
'              Some Rights Reserved
'              -- see http://creativecommons.org/licenses/by/3.0/
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated...  26 AUG 2008
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN


' -----[ Constants ]-------------------------------------------------------

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0

SYMBOL  Baud            = OT2400

SYMBOL  GRN             = %0001
SYMBOL  YEL             = %0010
SYMBOL  RED             = %0100
SYMBOL  Sequence        = %1000

' -----[ Variables ]-------------------------------------------------------

SYMBOL  lamps           = B0
SYMBOL   grnLamp        =  BIT0                 ' RC-4.K0
SYMBOL   yelLamp        =  BIT1                 ' RC-4.K1
SYMBOL   redLamp        =  BIT2                 ' RC-4.K2

SYMBOL  btns            = B2
SYMBOL  idx             = B3
SYMBOL  flasher         = B4
SYMBOL  flashes         = B5
SYMBOL  flashDelay      = B6


' -----[ Initialization ]--------------------------------------------------

Reset:
  SEROUT Sio, Baud, ("!!!!!RC4", %00, "X")      ' reset the RC-4

' -----[ Program Code ]----------------------------------------------------

Main:
  GOSUB Scan_Buttons                            ' check buttons

Check_Green:
  IF btns <> GRN THEN Check_Yellow              ' IF B2 <> %0001 Then
    flasher = GRN
    GOTO Flash_Lamp

Check_Yellow:
  IF btns <> yel THEN Check_Red                 ' IF B2 <> %0010 Then
    flasher = YEL
    GOTO Flash_Lamp

Check_Red:
  IF btns <> RED THEN Check_Sequence            ' If B2 <> %0100 Then
    flasher = RED
    GOTO Flash_Lamp

Check_Sequence:
  IF btns <> Sequence THEN Main                 ' IF B2 <> %1000 Then
  flasher = Sequence
  GOTO Light_Sequence

Flash_Lamp:                                     ' flash and leave lamp on
  lamps = flasher                               ' Bit0 = Bit4
  FOR flashes = 1 TO 30                         ' For B5 = 1 TO 30 (flash about 15 seconds)
    GOSUB Update_Lamps                          ' (30 ms)
    FOR flashDelay = 1 TO 8                     ' For B6 = 1 TO 8(8 x 50ms = 400 ms
      GOSUB Scan_Buttons
      IF btns <> %0000 THEN Check_Green         ' abort on button press
NEXT
    PAUSE 70                                    ' pad for 500 ms
    lamps = lamps ^ flasher                     ' toggle lamp


    NEXT
    FOR flashes = 1 TO 1
    GOSUB Update_Lamps

    GOTO main

' ----[ Extra Sequence ]---------------------------------------------------


    Light_Sequence:


lamps = 1 ' loop through LEDs
HIGH lamps ' LED on
GOSUB Update_lamps
PAUSE 1000 ' hold
LOW lamps ' LED off


lamps = 2
HIGH lamps
GOSUB Update_lamps
PAUSE 1000
LOW lamps


lamps = 4
HIGH lamps
GOSUB Update_lamps
PAUSE 1000
LOW lamps

GOSUB scan_buttons
IF btns <> 8 THEN check_green
GOTO light_sequence


' -----[ Subroutines ]-----------------------------------------------------

' Scans and debounces button inputs

Scan_Buttons:
  btns = %1111                                  ' assume pressed
  FOR idx = 1 TO 10
    btns = btns & PINS                          ' scan buttons
    PAUSE 5
  NEXT
  btns = btns & %00001111                       ' clear unused inputs
  RETURN

' -------------------------------------------------------------------------

Update_Lamps:
  SEROUT Sio, Baud, ("!RC4", %00, "S", lamps)
  RETURN

' -------------------------------------------------------------------------


' -------------------------------------------------------------------------


' -------------------------------------------------------------------------


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------

JonnyMac

Here you go -- this fixes the "stay on" problem (not sure how that crept in) and adds the simple sequence. 

' =========================================================================
'
'   File...... Class_Stoplight_v2.BS1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2008 EFX-TEK
'              Some Rights Reserved
'              -- see http://creativecommons.org/licenses/by/3.0/
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated...  04 SEP 2008
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN

SYMBOL  SeqBtn          = PIN3                  ' P3.W and P2.R
SYMBOL  RedBtn          = PIN2                  ' P2.W and P2.R
SYMBOL  YelBtn          = PIN1                  ' P1.W and P1.R
SYMBOL  GrnBtn          = PIN0                  ' P0.W and P0.R


' -----[ Constants ]-------------------------------------------------------

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0

SYMBOL  Baud            = OT2400

SYMBOL  GRN             = %0001
SYMBOL  YEL             = %0010
SYMBOL  RED             = %0100
SYMBOL  SEQ             = %1000


' -----[ Variables ]-------------------------------------------------------

SYMBOL  lamps           = B0
SYMBOL   grnLamp        =  BIT0                 ' RC-4.K0
SYMBOL   yelLamp        =  BIT1                 ' RC-4.K1
SYMBOL   redLamp        =  BIT2                 ' RC-4.K2

SYMBOL  btns            = B2
SYMBOL  idx             = B3
SYMBOL  flasher         = B4
SYMBOL  flashes         = B5
SYMBOL  flashDelay      = B6


' -----[ Initialization ]--------------------------------------------------

Reset:
  SEROUT Sio, Baud, ("!!!!!RC4", %00, "X")      ' reset the RC-4


' -----[ Program Code ]----------------------------------------------------

Main:
  GOSUB Scan_Buttons                            ' check buttons

Check_Sequence:
  IF btns <> SEQ THEN Check_Green
    FOR idx = 0 TO 2
      LOOKUP idx, (GRN, YEL, RED), lamps
      GOSUB Update_Lamps
      PAUSE 1000
    NEXT
    lamps = IsOff
    GOSUB Update_Lamps
    GOTO Main

Check_Green:
  IF btns <> GRN THEN Check_Yellow
    flasher = GRN
    GOTO Flash_Lamp

Check_Yellow:
  IF btns <> YEL THEN Check_Red
    flasher = YEL
    GOTO Flash_Lamp

Check_Red:
  IF btns <> RED THEN Main
    flasher = RED

Flash_Lamp:                                     ' flash and leave lamp on
  lamps = flasher
  FOR flashes = 1 TO 29                         ' flash about 15 seconds
    GOSUB Update_Lamps                          ' 1 x 30ms =  30ms
    FOR flashDelay = 1 TO 8                     ' 8 x 50ms = 400ms
      GOSUB Scan_Buttons
      IF btns <> %000 THEN Check_Green          ' abort on button press
    NEXT
    PAUSE 70                                    ' pad for 500 ms
    lamps = lamps ^ flasher                     ' toggle lamp
  NEXT
  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------

' Scans and debounces button inputs

Scan_Buttons:
  btns = %1111                                  ' assume pressed
  FOR idx = 1 TO 10
    btns = btns & PINS                          ' scan buttons
    PAUSE 5
  NEXT
  btns = btns & %00001111                       ' clear unused inputs
  RETURN

' -------------------------------------------------------------------------

Update_Lamps:
  SEROUT Sio, Baud, ("!RC4", %00, "S", lamps)
  RETURN

' -------------------------------------------------------------------------



' -----[ User Data ]-------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office

Raisin-Toe

Thanks ;D ;D, your awsome. I don't know how you figure this stuff out so fast!

JonnyMac

I old and have had lots of practice....  ;)
Jon McPhalen
EFX-TEK Hollywood Office