Need help with parallelput
Author |
Message |
chroncile
|
Posted: Sun Jan 11, 2009 8:05 pm Post subject: Need help with parallelput |
|
|
Hi, I'm supposed to make a program that has two modes, a test and a quiz mode. When the user is taking the quiz, the LED lights on the breadboard are suppose to turn off every 1 second using parallelput. The quiz is multiple choice and its GUI so there are four boxes from which the user can choose. Also, I have to use mousewhere and not buttonwait for it since buttonwait will it so that the LED lights wont go off. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Laplace's Demon
|
Posted: Sun Jan 11, 2009 8:20 pm Post subject: Re: Need help with parallelput |
|
|
Alright...all you've done here is tell us what your project is. Do you have any code to post for us? Do you have any specific questions? This forum is not to be used to bum code, it is used to answer specific questions pertaining to existing code.
If you have any reasonable specific questions and can provide us with the code you have written so far, we could help out. |
|
|
|
|
|
chroncile
|
Posted: Sun Jan 11, 2009 8:34 pm Post subject: RE:Need help with parallelput |
|
|
yes, how do i make it so when the user is answering the questions, the LED lights go off. Im suppose to use 4 LED lights and one by one, they turn off meaning a second has passed by and when they all turn off, the program goes to the next question, here is my code so far:
code: |
var counter : int := 0
var total : int := 0
var answer1, answer2, answer3, answer4 : string
var result1, result2, result3, result4 : string
var x, y, bnum, bud : int
var button : int
var font1 : int
font1 := Font.New ("serif:12")
put " " : 29, "Welcome to Mind Blaster!"
put "--------------------------------------------------------------------------------"
put skip
put "There are two options to choose from:"
put " - The Test Mode"
put " - The Quiz Mode"
put skip
put "- The test mode will consist of hard questions."
put "- The quiz mode will consist of easy questions with little time"
put " to complete them."
put skip
drawfillbox (250, 50, 120, 125, black)
drawfillbox (450, 50, 320, 125, brightblue)
Font.Draw ("Test Mode", 150, 80, font1, white)
Font.Draw ("Quiz Mode", 350, 80, font1, white)
loop
buttonwait ("down", x, y, bnum, bud)
exit when x >= 120 and x <= 250 and y >= 50 and y <= 125
end loop
cls
put "" : 35, "Test Mode"
put "--------------------------------------------------------------------------------"
put ""
put "Question 1:"
put "What does PC stand for?"
put ""
drawbox (160, 200, 320, 250, black)
drawbox (320, 200, 480, 250, black)
drawbox (160, 200, 320, 150, black)
drawbox (320, 200, 480, 150, black)
Font.Draw ("a) Personal Computer", 170, 220, font1, black)
Font.Draw ("b) Peripheral Computer", 330, 220, font1, black)
Font.Draw ("c) Pseudoroid Computer", 168, 173, font1, black)
Font.Draw ("d) Pentium Centrio", 330, 173, font1, black)
mousewhere (x, y, button)
end loop
delay (1000)
cls
|
|
|
|
|
|
|
Laplace's Demon
|
Posted: Sun Jan 11, 2009 8:47 pm Post subject: Re: Need help with parallelput |
|
|
Are you asking how to use the parallelput procedure?
First of all, don't use the "wait" procedures. They will muck up your program. All you need to do is run a loop in the question section of your program, which is constantly checking for the answers. In this loop you also want to keep a timer of some sort, whether you do that in terms of "frames" in the game or by actual time is up to you. Based on that timer you want to turn off LED 1 after 1 second, turn off LED 2 after 2 second, etc. Then after all four have turned off and four seconds have passed you want to exit the "question loop" and tell the user time has run out. |
|
|
|
|
|
chroncile
|
Posted: Sun Jan 11, 2009 8:54 pm Post subject: RE:Need help with parallelput |
|
|
Nope, what I want is for the LED lights on the breadboard to turn off one by one.
Like, when the user is taking the quiz, they will have only 4 seconds to answer the question and to display how many seconds they have, one of the four LEDs will turn off every second.
Just to clarify; there is a breadboard with 4 LED lights, when a user is doing the quiz, all the LED lights will be on, but as the user is answering the questions, he or she will only have 4 seconds to choose an answer and to display how many seconds are left, one by one the LEDs will turn off each second.
I have to make that using mousewhere and parallelput. How?
Thx |
|
|
|
|
|
Laplace's Demon
|
Posted: Sun Jan 11, 2009 9:08 pm Post subject: Re: Need help with parallelput |
|
|
I edited my previous post with more information.
To use Mouse.Where simply have Mouse.Where at the top of your "question loop" and in your loop check to see if the mouse button is down while the cursor is simultaneously over your button.
Parallelput can be a little finicky. But basically you just want to input a value in the parameter of the procedure which will activate your desired LEDs. For example to light up all four, you might use parallelput (1+2+4+8=15) but to light up only the first three you might use parallelput (1+2+4=7) If you had 8 LEDs and you wanted to light all of them up, you would use 255, etc.
Go check out the turing reference on these subjects, if you take the time to read through a few time it can all click. |
|
|
|
|
|
chroncile
|
Posted: Sun Jan 11, 2009 9:39 pm Post subject: RE:Need help with parallelput |
|
|
Hey, thanks for the help, but I have a bit of a problem, when the program starts, it doesn't display anything
Try it yourself:
code: |
var counter : int := 0
var mode : int
var total : int := 8
var answer1, answer2, answer3, answer4 : string
var result1 : int := 0
var x, y, bnum, bud : int
var button : int
var font1 : int
var timer : int := 0
font1 := Font.New ("serif:12")
% Intro Screen
put " " : 29, "Welcome to Mind Blaster!"
put "--------------------------------------------------------------------------------"
put skip
put "There are two options to choose from:"
put " - The Test Mode"
put " - The Quiz Mode"
put skip
put "- The test mode will consist of hard questions."
put "- The quiz mode will consist of easy questions with little time"
put " to complete them."
put skip
% Draws the GUI buttons
drawfillbox (250, 50, 120, 125, black)
drawfillbox (450, 50, 320, 125, brightblue)
Font.Draw ("Test Mode", 150, 80, font1, white)
Font.Draw ("Quiz Mode", 350, 80, font1, white)
% Waits for the users input
% Does not exit the program when the user clicks outside a button
loop
buttonwait ("down", x, y, bnum, bud)
if x >= 120 and x <= 250 and y >= 50 and y <= 125 then
mode := 1
elsif x >= 320 and x <= 450 and y >= 50 and y <= 125 then
mode := 2
end if
exit when mode = 1 or mode = 2
end loop
% Clears the screen
cls
% Quiz mode
% Question 1 is displayed
% Multiple choice questions are displayed
if mode = 2 then
put "" : 35, "Quiz Mode"
put "--------------------------------------------------------------------------------"
put ""
put "Question 1:"
put "What does PC stand for?"
put ""
drawbox (160, 200, 320, 250, black)
drawbox (320, 200, 480, 250, black)
drawbox (160, 200, 320, 150, black)
drawbox (320, 200, 480, 150, black)
drawfilloval (100, 75, 20, 20, red)
drawfilloval (250, 75, 20, 20, yellow)
drawfilloval (400, 75, 20, 20, green)
drawfilloval (550, 75, 20, 20, red)
Font.Draw ("a) Personal Computer", 170, 220, font1, black)
Font.Draw ("b) Peripheral Computer", 330, 220, font1, black)
Font.Draw ("c) Pseudoroid Computer", 168, 173, font1, black)
Font.Draw ("d) Pentium Centrio", 330, 173, font1, black)
loop
timer := timer + 1
mousewhere (x, y, button)
if x >= 160 and x <= 320 and y >= 200 and y <= 250 then
answer1 := "a) Personal Computer"
counter := counter + 1
elsif x >= 320 and x <= 480 and y >= 200 and y <= 250 then
answer1 := "b) Peripheral Computer"
counter := counter + 1
elsif x >= 160 and x <= 320 and y >= 150 and y <= 200 then
answer1 := "c) Pseudoroid Computer"
counter := counter + 1
elsif x >= 320 and x <= 480 and y >= 150 and y <= 200 then
answer1 := "d) Pentium Centrio"
counter := counter + 1
end if
if timer = 4 then
result1 := 1
end if
exit when timer = 4 or counter = 1
end loop
cls
if result1 = 1 then
put "You have run out of time."
total := total - 1
end if
cls
end if
|
|
|
|
|
|
|
Laplace's Demon
|
Posted: Sun Jan 11, 2009 10:22 pm Post subject: Re: Need help with parallelput |
|
|
It is displaying something, it is just doing it so fast that your program finishes and clears immediately. Try opening the debugger menu and check "trace execution" you will see that it actually does work.
Just stick a delay (1000) right below your "exit when timer = 4 or counter = 1" line and it will work like you want it to (sort of). You will also want to stick delays in the part after the question loop, so that the player has time to read whether or not they got the correct answer. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|