%Project: Traffic Light
 
%Purpose - to create an interface between the computer and the (light) box
 
%Question 1 - 130 points
 
 
% VARIABLE TABLE
 
% x - int - the x coordinate that the user clicked on
 
% y - int - the y coordinate that the user clicked on
 
% bnum - int - the button that you select on the mouse
 
% bud - int - whether the button is pressed (1) or released (0)
 
setscreen ("graphics:vga")
 
%var for the button's coordinates
 
var x, y, bnum, bud : int
 
%var for the traffic buttons
 
var rb, yb, gb : int := 0
 
%var for the of the words. size and type
 
var font : int
 
%var for the number of flashs
 
var flash : int := 0
 
%var for the number of rotates
 
var rotate : int := 0
 
%var for the number of patterns
 
var pattern : int := 0
 
%var for the output of the parallel put for the on an off swtich
 
var swt : int := 0
 
var fp : int
 
%color of background
 
colorback (gray)
 
%font size and type
 
font := Font.New ("Arial:14")
 
Font.Draw ("WELCOME  TO  MY  TRAFFIC  LIGHT  PROGRAM", 80, 305, font, 7)
 
%loop command, keeps the program going
 
loop
 
    drawfillbox (390, 110, 560, 230, brown)
 
    drawfillbox (100, 110, 270, 230, brown)
 
    Font.Draw ("Test Mode", 141, 166, font, white)
 
    Font.Draw ("Scenerio Mode", 413, 166, font, white)
 
    drawfillbox (0, 35, 700, 0, 7)
 
    drawfillbox (0, 800, 700, 355, 7)
 
    locate (21, 25)
 
    put "please slect a mode"
 
    buttonwait ("down", x, y, bnum, bud)
 
    if (x >= 50 and x <= 260) and (y >= 110 and y <= 240) then
 
        %clears the program
 
        cls
 
        %loop command, keeps the program going
 
        loop
 
 
            %Traffic ligth buttons
 
            drawfillbox (25, 25, 110, 65, 12)
 
            drawbox (24, 24, 111, 66, black)
 
 
            drawfillbox (25, 125, 110, 165, yellow)
 
            drawbox (24, 124, 111, 166, black)
 
 
            drawfillbox (25, 225, 110, 265, brightgreen)
 
            drawbox (24, 224, 111, 266, black)
 
 
            %traffic light body
 
            drawfillbox (200, 25, 321, 275, 7)
 
            drawbox (199, 24, 322, 276, black)
 
 
 
            %traffic lights
 
            drawfilloval (261, 75, 30, 30, 12)
 
            drawfilloval (261, 75, 28, 28, white)
 
            drawfilloval (261, 150, 30, 30, yellow)
 
            drawfilloval (261, 150, 28, 28, white)
 
            drawfilloval (261, 225, 30, 30, brightgreen)
 
            drawfilloval (261, 225, 28, 28, white)
 
 
            %Special switches
 
            drawfillbox (25, 300, 100, 340, 7)
 
            drawbox (24, 299, 101, 341, black)
 
            drawfillbox (125, 300, 200, 340, 7)
 
            drawbox (124, 299, 201, 341, black)
 
            drawfillbox (225, 300, 300, 340, 7)
 
            drawbox (224, 299, 301, 341, black)
 
            drawfillbox (325, 300, 400, 340, 7)
 
            drawbox (324, 299, 401, 341, black)
 
            %the font infomation for the words inside my special buttons
 
            Font.Draw ("Flash", 40, 315, font, white)
 
            Font.Draw ("Rotate", 135, 315, font, white)
 
            Font.Draw ("Pattern", 235, 315, font, white)
 
            Font.Draw ("Stop", 344, 315, font, white)
 
            drawfilloval (557, 360, 35, 35, blue)
 
            colorback (0)
 
            color (7)
 
            locate (6, 66)
 
            put "   BACK   " ..
 
            % waits for the user to use the mouse and obtains the x,y location where the
 
            %loop command, keeps the program going
 
            loop
 
                %tells the button when to activate: when the button is pressed "down"
 
                buttonwait ("down", x, y, bnum, bud)
 
                %red button
 
                %the red button's coordinates
 
                if x >= 25 and x <= 110 and y >= 25 and y <= 65 then
 
                    %this shows that the buttons is low
 
                    if rb = 0 then
 
                        %what will happen if user clicks inside the coordinates
 
                        drawfilloval (261, 75, 30, 30, 12)
 
                        %if the button is clicked the button is turns high (on)
 
                        rb := 1
 
                        %turns the red light high(on), while the other lights are high(on)
 
                        swt := swt + 4
 
                        %turns the command (on), and by showing it on the real lights
 
                        parallelput (swt)
 
                    else
 
                        %what will happen if user clicks inside the coordinates again
 
                        drawfilloval (261, 75, 28, 28, white)
 
                        %the red button is turned off again
 
                        rb := 0
 
                        %turns the red light low(off), while the of=ther buttons are high(on)
 
                        swt := swt - 4
 
                        parallelput (swt)
 
                        %end the if command for this button
 
                    end if
 
                    %yellow button
 
                elsif x >= 25 and x <= 110 and y >= 125 and y <= 165 then
 
                    if yb = 0 then
 
                        drawfilloval (261, 150, 30, 30, yellow)
 
                        yb := 1
 
                        swt := swt + 2
 
                        parallelput (swt)
 
                    else
 
                        drawfilloval (261, 150, 28, 28, white)
 
 
                        yb := 0
 
                        swt := swt - 2
 
                        parallelput (swt)
 
                    end if
 
                    %green button
 
                elsif x >= 25 and x <= 110 and y >= 225 and y <= 265 then
 
                    if gb = 0 then
 
                        drawfilloval (261, 225, 30, 30, brightgreen)
 
                        gb := 1
 
                        swt := swt + 1
 
                        parallelput (swt)
 
                    else
 
 
                        drawfilloval (261, 225, 28, 28, white)
 
 
                        gb := 0
 
                        swt := swt - 1
 
                        parallelput (swt)
 
                    end if
 
 
                    %Flash button
 
                    %flash button's coordinates
 
                elsif x >= 25 and x <= 100 and y >= 300 and y <= 340 then
 
                    %this will keep the sentence in the same position, so it won't over lap the program
 
                    locate (1, 1)
 
                    put "Enter the number of times you would like the the lights to flash: " ..
 
                    %gets the flash var from the user
 
                    get flash
 
                    %for command. used to count from the number 1 to the flash var entered by the user
 
                    for num : 1 .. flash
 
                        %the pattern that the traffic lights are going to flash in
 
                        %parallel put: using binary codes it tells the box what light to show
 
                        %puts all the three real lights (LED) on
 
                        parallelput (7)
 
                        drawfilloval (261, 75, 30, 30, 12)
 
                        drawfilloval (261, 150, 30, 30, yellow)
 
                        drawfilloval (261, 225, 30, 30, brightgreen)
 
                        %the time it will take the program to wait until it shows the next pattern/light
 
                        delay (500)
 
                        %puts all three real lights off
 
                        parallelput (0)
 
                        drawfilloval (261, 75, 28, 28, white)
 
                        drawfilloval (261, 150, 28, 28, white)
 
                        drawfilloval (261, 225, 28, 28, white)
 
                        delay (500)
 
                        %ends the for command for this button
 
                    end for
 
 
                    %Rotate button
 
                    %rotate button's coordinates
 
                elsif x >= 125 and x <= 200 and y >= 300 and y <= 340 then
 
                    %leaves a line of space on top of the pervious lines so that they won'y overlap each other
 
                    locate (1, 1)
 
                    put " "
 
                    put "Enter the number of time you would like the lights to rotate: " ..
 
                    %get the rotate var from the user
 
                    get rotate
 
                    %for command for the rotate button
 
                    for num1 : 1 .. rotate
 
                        %puts the red light on
 
                        parallelput (1)
 
                        drawfilloval (261, 75, 30, 30, 12)
 
                        delay (500)
 
                        %turns the red light off and the yellow light on
 
                        parallelput (2)
 
                        drawfilloval (261, 75, 28, 28, white)
 
                        drawfilloval (261, 150, 30, 30, yellow)
 
                        delay (500)
 
                        %turns the red and yellow lights off and the green light on
 
                        parallelput (4)
 
                        drawfilloval (261, 150, 28, 28, white)
 
                        drawfilloval (261, 225, 30, 30, brightgreen)
 
                        delay (500)
 
                        %turns all three lights off
 
                        parallelput (0)
 
                        drawfilloval (261, 225, 28, 28, white)
 
                        delay (500)
 
                        %ends the for command for this button
 
                    end for
 
                    %pattern button
 
                    %the pattern button's coordintate
 
                elsif x >= 225 and x <= 300 and y >= 300 and y <= 340 then
 
                    locate (1, 1)
 
                    %leaves two lines of space so that it won't over lap the pervious two line on top
 
                    locate (1, 1)
 
                    put " "
 
                    put " "
 
                    put "Enter the number of time you would like the lights to run the pattern: " ..
 
                    get pattern
 
                    for num2 : 1 .. pattern
 
                        parallelput (1)
 
                        drawfilloval (261, 75, 30, 30, 12)
 
                        delay (500)
 
                        parallelput (4)
 
                        drawfilloval (261, 225, 30, 30, brightgreen)
 
                        delay (500)
 
                        parallelput (2)
 
                        drawfilloval (261, 150, 30, 30, yellow)
 
                        delay (500)
 
                        parallelput (0)
 
                        drawfilloval (261, 75, 28, 28, white)
 
                        drawfilloval (261, 150, 28, 28, white)
 
                        drawfilloval (261, 225, 28, 28, white)
 
                        delay (500)
 
                    end for
 
                    %ends the if
 
                elsif (x >= 325 and x <= 400) and (y >= 300 and y <= 340) then
 
                    exit
 
                end if
 
                exit when (x >= 325 and x <= 400) and (y >= 300 and y <= 340)
 
            end loop
 
            exit when (x >= 325 and x <= 400) and (y >= 300 and y <= 340)
 
        end loop
 
    end if
 
    loop
 
        exit when fp = 1
 
    end loop
 
    exit when fp = 1
 
end loop
 
 
% Senerio Mode
 
buttonwait ("down", x, y, bnum, bud)
 
if (x >= 370 and x <= 580) and (y >= 110 and y <= 240) then
 
    cls
 
    loop
 
        %traffic lights
 
        drawfillbox (200, 25, 321, 275, 7)
 
        drawbox (199, 24, 322, 276, black)
 
        Font.Draw ("THE CAR IS AT REST", 160, 350, font, 7)
 
        drawfilloval (261, 225, 30, 30, 12)
 
        parallelput (9)
 
        delay (5000)
 
        cls
 
 
        drawfillbox (200, 25, 321, 275, 7)
 
        drawbox (199, 24, 322, 276, black)
 
        Font.Draw ("THE CAR IS ABOUT TO MOVE", 135, 350, font, 7)
 
        drawfilloval (261, 225, 30, 30, 12)
 
        parallelput (0)
 
        delay (2000)
 
        cls
 
 
        drawfillbox (200, 25, 321, 275, 7)
 
        drawbox (199, 24, 322, 276, black)
 
        Font.Draw ("THE CAR IS MOVING", 172, 350, font, 7)
 
        drawfilloval (261, 75, 30, 30, brightgreen)
 
        parallelput (12)
 
        delay (5000)
 
        cls
 
 
        parallelput (2)
 
 
        drawfillbox (200, 25, 321, 275, 7)
 
        drawbox (199, 24, 322, 276, black)
 
        Font.Draw ("THE CAR IS GOING TO STOP", 130, 350, font, 7)
 
        drawfilloval (261, 150, 30, 30, yellow)
 
        drawfilloval (261, 75, 30, 30, brightgreen)
 
        parallelput (12)
 
        parallelput (1)
 
        delay (5000)
 
        cls
 
 
        drawfillbox (200, 25, 321, 275, 7)
 
        drawbox (199, 24, 322, 276, black)
 
        Font.Draw ("THE CAR HAS STOPPED", 150, 350, font, 7)
 
        drawfilloval (261, 225, 30, 30, 12)
 
        parallelput (9)
 
        %loop command, keeps the program going
 
        loop
 
            %ends loop
 
        end loop
 
    end loop
 
    %ends if statement
 
end if
 
%ends loop
 
 
  |