Shop OBEX P1 Docs P2 Docs Learn Events
railway level crossing — Parallax Forums

railway level crossing

johan93johan93 Posts: 1
edited 2011-04-19 17:05 in Learn with BlocklyProp
hello,

My name is Johan and i'm from the Netherlands.
I am making a railway level crossing as a schoolproject but i have some problems with it.
You have to see it as a 2 track railway.

this is my program:

' {$STAMP BS2}
' {$PBASIC 2.5}
'overwegschakeling'
'
'
time VAR Word
tijd VAR Word
open1 VAR Word
open2 VAR Word
counter VAR Word
teller VAR Word
DO
'---zet alle variabelen op 0---'
time = 0
tijd = 0
teller = 0
counter = 0
open1 = 0
open2 = 0
DEBUG "meet lichtwaarde d.m.v. LDR op PIN 0 en 1", CR
DO
HIGH 0
PAUSE 100
RCTIME 0, 1, tijd
DEBUG HOME, "tijd = ", DEC5 tijd, CR, "time = ", DEC5 time, CR, "open1 = ", DEC5 open1, CR, "open2 = ", DEC5 open2, CR
HIGH 1
PAUSE 100
RCTIME 1, 1, time
LOOP UNTIL time > 250 OR tijd > 250
DEBUG "knipperen van de LED's en geluid uit piezospeaker", CR
IF time > 250 OR tijd > 250 THEN
DO UNTIL teller = 5
FREQOUT 14, 100, 2000
HIGH 10
PAUSE 150
LOW 10
PAUSE 50
FREQOUT 14, 100, 2000
HIGH 11
PAUSE 150
LOW 11
PAUSE 50
teller = teller + 1
LOOP
ENDIF
DEBUG "slagbomen(servo's) draaien dicht", CR
FOR counter = 1 TO 10
PULSOUT 12, 1000
PAUSE 20
NEXT
FOR counter = 1 TO 10
PULSOUT 13, 1000
PAUSE 20
NEXT
DEBUG "lichtjes blijven knipperen", CR
DEBUG "lichtwaarde meten d.m.v. LDR op PIN 2 en 3", CR
DO
FREQOUT 14, 100, 2000
HIGH 10
PAUSE 150
LOW 10
PAUSE 50
HIGH 2
PAUSE 10
RCTIME 2, 1, open1
FREQOUT 14, 100, 2000
HIGH 11
PAUSE 150
LOW 11
PAUSE 50
HIGH 3
PAUSE 100
RCTIME 3, 1, open2
LOOP UNTIL open1 > 20 OR open2 > 20
DEBUG "servo's draaien open", CR
IF open1 > 20 OR open2 > 20 THEN
FOR counter = 1 TO 10
PULSOUT 12, 600
PAUSE 20
NEXT
FOR counter = 1 TO 10
PULSOUT 13, 600
PAUSE 20
NEXT
ENDIF
LOOP

i will translate the debugs for you:

1. put all VAR to 0
2. measure light on pin 0 & 1( time & tijd)
3. when time or tijd = 250 then 2 LED blink and some sound comes out of the piezo
3. when teller = 5 then close the servo's
4. when open1 or open2 = 20 then open the servo's and stop blinking and making sound.

here is my problem:

when a train comes over pin 0 it has to be opened with pin 3 and only pin 3.
when a train comes over pin 1 it has to be opened with pin 2 and only pin 2.
so it has to be but it ins't yet.

it now can be opened with pin 2 & 3 no matter what

how to make that it can be opened with only pin 2 or 3?

Johan

Comments

Sign In or Register to comment.