Push buttons being read while other actions are being performed

I'm stuck on a project. I have the streetlights acting as I need them to but I'm having a difficult time trying to get the pushbutton to be read while the lights are performing.

Here are the guidelines

only one pedestrian light will go green at a time and only when the corresponding pushbutton is pushed.When the button is pushed, traffic should stopin that direction only after the completion of that traffic cycle.

b.The corresponding pedestrian light will turn green and will stay on for 30 seconds. During the last 10 seconds, the green light will be flashing to indicate that time is almost up for crossing the street.

c.Each push button can be only pushed once.After that, the pedestrian light will return to red and normal operation will resume for two complete traffic cycles in that specific direction before the same button can cause the traffic light to change.You can ignore any push made during the completion of the two cycles.

d.If traffic is stopped in a particular direction during a red light and the pedestrian light is pushed, the corresponding pedestrian light should turn green immediately.

e.The left turn traffic should yield to pedestrians crossing the N-S street so there is no need to wait for the left turn signal to turn red.

Here is my code. I tried to simplify it by using subroutines for the change from north south to east west back to the all red.

Comments

First of all ... we can only give so much help on school projects ... that said, we can certainly make suggestions. You probably need to break up the PAUSEs into a subroutine that also checks all the pushbuttons and sets variables for the pushbutton states maybe every 100ms like this:

pushed var bit(4)
location var nib
i var nib
temp var bit
button var bit(4)
time var word
CheckButtons:
'
' This subroutine checks to see if a button is pushed. It won't accept another push until the
' button is released and the button push is remembered until it is acted upon by resetting
' button(i) to zero. You set time to the desired cycle time in ms and this returns after that.
'
for i = 0 to 3
temp = INA.bit0(i) ' check IN0,IN1,IN2,IN3
if pushed(i) = 0 and temp = 1 then button(i) = 1 ' was up now down?
pushed(i) = temp ' save previous state for next check
next i
pause 100 ' clock 'tic is 100ms
time = time - 100
if time > 0 then goto CheckButtons ' if time not done, repeat
return

Typically, you'd do some action for a cycle calling CheckButtons for any pauses in the cycle like:

This is when you learn how to use highest common denominator, and time-slice your code for that.
Though you could only use gpio irq + timer irq and hardware pwm for this simple project,
but keeping it to a simple state-machine that runs on 1/4sec ticks is easier to understand.

This is the code I have now. All that I am missing is getting the pedestrian light to go from West to East to North and South if the PBNS as been pressed while the pedestrian light for "WE" is on. I got the code to read that pbns has been pressed while it is on. I just cant figure out why it wont execute the condition I have for the crosswalk to switch after the condition is met.

First of all ... we can only give so much help on school projects ... that said, we can certainly make suggestions. You probably need to break up the PAUSEs into a subroutine that also checks all the pushbuttons and sets variables for the pushbutton states maybe every 100ms like this:

pushed var bit(4)
location var nib
i var nib
temp var bit
button var bit(4)
time var word
CheckButtons:
'
' This subroutine checks to see if a button is pushed. It won't accept another push until the
' button is released and the button push is remembered until it is acted upon by resetting
' button(i) to zero. You set time to the desired cycle time in ms and this returns after that.
'
for i = 0 to 3
temp = INA.bit0(i) ' check IN0,IN1,IN2,IN3
if pushed(i) = 0 and temp = 1 then button(i) = 1 ' was up now down?
pushed(i) = temp ' save previous state for next check
next i
pause 100 ' clock 'tic is 100ms
time = time - 100
if time > 0 then goto CheckButtons ' if time not done, repeat
return

Typically, you'd do some action for a cycle calling CheckButtons for any pauses in the cycle like: