ParrallelPut Problem
Author |
Message |
Raditude
|
Posted: Mon Jun 14, 2010 6:26 pm Post subject: ParrallelPut Problem |
|
|
What is it you are trying to achieve?
Have all the lights be able to comeon simultaneously on my model built car (not the program)
What is the problem you are having?
I just dont know how. It lights up on the actual program, but on the car im using, it seems i can only send 1 parallelput "signal" at a time. I dont think this is the case
Describe what you have tried to solve this problem
Getting rid of some of the code, but then like the main functionality is lost
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Sorry in advance if its too long, i just think its easier instead of having to download the file
Turing: |
% This command tells the program that we are making a Graphics User Interface
% and imports the premade module for that
import GUI
% Here, the screen resolution is set.
setscreen ("graphics:640;480")
% The following 2 variables are the 2 background pictures that are used
var vipeback : int := Pic.FileNew ("viper2dash.bmp")
var vipebackON : int := Pic.FileNew ("viper2dashON.bmp")
% These variables control the toggle lights system for the
% left lights, right lights, break lights, and head lights, respectively
var llon : boolean
var rlon : boolean
var blon : boolean
var hlon : boolean
% Here we draw the more "darkened" out background, which represents a not fully on system
Pic.Draw (vipeback, maxx div 650, maxy div 650, 0)
delay (600)
% An altered Image of the car with the main light areas lightened up, as well as the dashboard, to simulate
% light being cast from the lights
Pic.Draw (vipebackON, maxx div 650, maxy div 650, 0)
% These are circles are drawn, to simulate an off position
% if we were to have made the GUI more realistic and changed to a different picture
% for each light, we would have 100's of combinations of lights, and result in a slow program
% Left Turn light
Draw.FillOval (265, 370, 9, 9, white)
Draw.FillOval (320, 312, 6, 6, white)
% Left Turn Light (Angled Model)
Draw.FillOval (614, 157, 3, 3, white)
% Right Turn light
Draw.FillOval (25, 370, 9, 9, white)
Draw.FillOval (600, 312, 6, 6, white)
% Right Turn Light (Angled Model)
Draw.FillOval (495, 111, 6, 6, white)
% Brake Lights
Draw.FillOval (325, 337, 10, 10, white)
Draw.FillOval (600, 337, 10, 10, white)
% Head Lights
Draw.FillOval (45, 365, 11, 11, white)
Draw.FillOval (245, 365, 11, 11, white)
% Head Lights (Angled Model)
Draw.FillOval (610, 148, 5, 5, white)
Draw.FillOval (515, 105, 7, 7, white)
% Backlights are red
% Turn signals are Yellow
% Headlights are orange
% The lefturn procedure begins when button1 is clicked, it reads the buttons current status
% and nots it, which is then "sent" to the GUI.Process.Event loop near the bottom
procedure lefturn
llon := not llon
end lefturn
% The righturn procedure begins when button2 is clicked, the same result as the left turn light occurs
procedure righturn
rlon := not rlon
end righturn
% The breaklight procedure begins when button3 is clicked, here we check if the button is on or not, and if it is, we
% draw the light on, if not, we draw the lights back to the off position
procedure breaklight
blon := not blon
if blon then
Draw.FillOval (325, 337, 10, 10, 40)
Draw.FillOval (600, 337, 10, 10, 40)
%parallelput (2)
else
Draw.FillOval (325, 337, 10, 10, white)
Draw.FillOval (600, 337, 10, 10, white)
%parallelput (0)
end if
end breaklight
% The headlight procedure begins when button4 is clicked, and the same result as the breaklight occurs
procedure headlight
hlon := not hlon
if hlon then
Draw.FillOval (45, 365, 11, 11, 41)
Draw.FillOval (245, 365, 11, 11, 41)
Draw.FillOval (610, 148, 5, 5, 41)
Draw.FillOval (515, 105, 7, 7, 41)
%parallelput (1)
else
Draw.FillOval (45, 365, 11, 11, white)
Draw.FillOval (245, 365, 11, 11, white)
Draw.FillOval (610, 148, 5, 5, white)
Draw.FillOval (515, 105, 7, 7, white)
%parallelput (0)
end if
end headlight
% These are the buttons themselves, all of them are "paired" with a procedure
% that begins when the button is clicked.
var button1 : int := GUI.CreateButton (25, 25, - 10, "", lefturn )
var button2 : int := GUI.CreateButton (25, 50, - 10, "", righturn )
var button3 : int := GUI.CreateButton (240, 25, - 10, "", breaklight )
var button4 : int := GUI.CreateButton (240, 50, - 10, "", headlight )
% Here we set the values for all the lights to false at the beginning,
% To represent them being off
llon := false
rlon := false
blon := false
hlon := false
% In the following loop, the off/on status of the buttons from the lefturn and righturn is processed
% and the lights turn on/off depending on the status of the button
% This loop is also run through out the entire program regardless, as GUI.Process.Event
% is the command that checks for any buttons pressed
loop
if llon then
Draw.FillOval (265, 370, 9, 9, yellow)
Draw.FillOval (320, 312, 6, 6, yellow)
Draw.FillOval (614, 157, 3, 3, yellow)
%parallelput (8)
delay (300)
Draw.FillOval (265, 370, 9, 9, white)
Draw.FillOval (320, 312, 6, 6, white)
Draw.FillOval (614, 157, 3, 3, white)
%parallelput (0)
delay (300)
end if
if rlon then
Draw.FillOval (25, 370, 9, 9, yellow)
Draw.FillOval (600, 312, 6, 6, yellow)
Draw.FillOval (495, 111, 6, 6, yellow)
%parallelput (4)
delay (300)
Draw.FillOval (25, 370, 9, 9, white)
Draw.FillOval (600, 312, 6, 6, white)
Draw.FillOval (495, 111, 6, 6, white)
%parallelput (0)
delay (300)
end if
exit when GUI.ProcessEvent
end loop
|
Please specify what version of Turing you are using
4.1.1A
Description: |
|
Filesize: |
900.05 KB |
Viewed: |
67 Time(s) |
|
Description: |
|
Filesize: |
900.05 KB |
Viewed: |
51 Time(s) |
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
chrisbrown
|
Posted: Mon Jun 14, 2010 8:35 pm Post subject: Re: ParrallelPut Problem |
|
|
First, move all your drawing code to the main loop for consistency and to facilitate the next step.
Now, parallelput outputs to pins valued 1, 2, 4, 8, etc... Keeping in mind that 3 = 1 + 2, what do you think would happen if you tried parallelput(3)?
|
|
|
|
|
|
Raditude
|
Posted: Mon Jun 14, 2010 9:21 pm Post subject: Re: ParrallelPut Problem |
|
|
chrisbrown @ Mon Jun 14, 2010 8:35 pm wrote: First, move all your drawing code to the main loop for consistency and to facilitate the next step.
Now, parallelput outputs to pins valued 1, 2, 4, 8, etc... Keeping in mind that 3 = 1 + 2, what do you think would happen if you tried parallelput(3)?
I understand it would turn both of them on, however, what do you mean by moving all my code to the main loop? is there anyway you could write up a rough outline of how it would ook? i know this is asking much, but possibly? THnaks for the help anyway though.
|
|
|
|
|
|
chrisbrown
|
Posted: Tue Jun 15, 2010 8:09 am Post subject: Re: ParrallelPut Problem |
|
|
Raditude @ Mon Jun 14, 2010 9:21 pm wrote: what do you mean by moving all my code to the main loop
Compare these two procedures: Turing: |
procedure righturn
rlon := not rlon
end righturn
procedure breaklight
blon := not blon
if blon then
Draw.FillOval (325, 337, 10, 10, 40)
Draw.FillOval (600, 337, 10, 10, 40)
%parallelput (2)
else
Draw.FillOval (325, 337, 10, 10, white)
Draw.FillOval (600, 337, 10, 10, white)
%parallelput (0)
end if
end breaklight |
The only thing you should be doing in breaklight is toggling blon, and similarly for headlight. This isn't a rule, but it's much better to keep related code grouped together.
Now, rather than call parallelput a bunch of times to handle each light, calculate (hint: use a variable) the total value that should be parallelput'ed.
You're very close, I'll just say that wherever you have a parallelput now, you should instead be adding a something to a variable, and parallelput'ing that variable once per loop.
|
|
|
|
|
|
|
|