Traffic Light problem
mad295
Posts: 1
This program I’m having trouble programming and making it work. I would like to change the program and have it hooked up to a timer. At a set time I would like to change the sequence to a four-way flashing red light. Help!!!!!!!!!!!!!
·
' STOPLITE.BS2
'
' {$STAMP BS2}
' {$PBASIC 2.5}
·
'====Input/Output===========================================
·
'·· P5·· EW/red····· P2·· NS/red
'·· P4·· EW/yellow·· P1·· NS/yellow
'·· P3·· EW/green··· P0·· NS/green
·
'====Constants==============================================
·
NSgrn···· CON %00100001·· ' Make NS green, EW red.
NSyel···· CON %00100010·· ' Make NS yellow, EW red.
allRed··· CON %00100100·· ' Make both lights red.
EWgrn···· CON %00001100·· ' Make EW green, NS red.
EWyel···· CON %00010100·· ' Make EW yellow, NS red.
NsgoTime·· CON 8000······ ' Set NS green duration (in milliseconds).
YelTime··· CON 2000······ ' Set duration of any yellow.
EWgoTime·· CON 8000······ ' Set EW green duration.
redOverlap·· CON 1000····· ' Set red/red overlap time.
top10···· CON %1111111111000000·········· ' Mask off lower 6 bits.
btm6···· CON %0000000000111111··········· ' Mask off upper 10 bits.
NSgo···· CON NSgoTime & top10 | NSgrn···· ' 16-bit time/bit pat.
NSwarn···· CON yelTime & top10 | NSyel···· ' 16-bit time/bit pat.
allStop·· CON RedOverlap & top10 | allRed·· ' 16-bit time/bit pat.
EWgo···· CON EWgoTime & top10 | EWgrn···· ' 16-bit time/bit pat.
EWwarn···· CON yelTime & top10 | EWyel···· ' 16-bit time/bit pat.
·
'====Variables===================================================
·
seq·· VAR·· Nib·· ' Current state (0-5) of stoplight sequence.
lkup·· VAR·· Word·· ' Number from lookup table.
·
'====Program=====================================================
·
DIRS = %00111111······ ' Set lower six pins to output.
again:················ ' Endless loop.
FOR seq = 0 TO 5······ ' For each of six stored patterns/times..
· LOOKUP seq,[noparse][[/noparse]NSgo,NSwarn,allStop,EWgo,EWwarn,allStop],lkup ' Get bits.
· OUTS = lkup & btm6·· ' Copy lower 6 bits to pins.
· PAUSE lkup & top10·· ' Set delay to upper 10 bits.
NEXT·················· ' ..and get the next entry from the table.
GOTO again············ ' Repeat endlessly.
·
' STOPLITE.BS2
'
' {$STAMP BS2}
' {$PBASIC 2.5}
·
'====Input/Output===========================================
·
'·· P5·· EW/red····· P2·· NS/red
'·· P4·· EW/yellow·· P1·· NS/yellow
'·· P3·· EW/green··· P0·· NS/green
·
'====Constants==============================================
·
NSgrn···· CON %00100001·· ' Make NS green, EW red.
NSyel···· CON %00100010·· ' Make NS yellow, EW red.
allRed··· CON %00100100·· ' Make both lights red.
EWgrn···· CON %00001100·· ' Make EW green, NS red.
EWyel···· CON %00010100·· ' Make EW yellow, NS red.
NsgoTime·· CON 8000······ ' Set NS green duration (in milliseconds).
YelTime··· CON 2000······ ' Set duration of any yellow.
EWgoTime·· CON 8000······ ' Set EW green duration.
redOverlap·· CON 1000····· ' Set red/red overlap time.
top10···· CON %1111111111000000·········· ' Mask off lower 6 bits.
btm6···· CON %0000000000111111··········· ' Mask off upper 10 bits.
NSgo···· CON NSgoTime & top10 | NSgrn···· ' 16-bit time/bit pat.
NSwarn···· CON yelTime & top10 | NSyel···· ' 16-bit time/bit pat.
allStop·· CON RedOverlap & top10 | allRed·· ' 16-bit time/bit pat.
EWgo···· CON EWgoTime & top10 | EWgrn···· ' 16-bit time/bit pat.
EWwarn···· CON yelTime & top10 | EWyel···· ' 16-bit time/bit pat.
·
'====Variables===================================================
·
seq·· VAR·· Nib·· ' Current state (0-5) of stoplight sequence.
lkup·· VAR·· Word·· ' Number from lookup table.
·
'====Program=====================================================
·
DIRS = %00111111······ ' Set lower six pins to output.
again:················ ' Endless loop.
FOR seq = 0 TO 5······ ' For each of six stored patterns/times..
· LOOKUP seq,[noparse][[/noparse]NSgo,NSwarn,allStop,EWgo,EWwarn,allStop],lkup ' Get bits.
· OUTS = lkup & btm6·· ' Copy lower 6 bits to pins.
· PAUSE lkup & top10·· ' Set delay to upper 10 bits.
NEXT·················· ' ..and get the next entry from the table.
GOTO again············ ' Repeat endlessly.
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Who are you, and why are you reading my signature?
I think the program should work really well especially if you used another lookup table for the pause time (which could be modified to include the "flash time" for the red lights.
Heres what I mean, it's not working code·just·an illustration
.I don't want to distract you from your original thoughts too much but only suggest an alternative.
Jeff T.