Shop OBEX P1 Docs P2 Docs Learn Events
New to this forum, Have a question. — Parallax Forums

New to this forum, Have a question.

Last~Cell~LeftLast~Cell~Left Posts: 10
edited 2006-08-28 19:16 in BASIC Stamp
Hello,

Brand new to this site, been spending some time here and I have to say the posts I have read, are loaded with great info.

I am working on a project, just to get down the basics,

In the book I have they give you a project for the reaction timer game, one bi-polar led and when it turns green, you release the button for a time reaction read out.

I tweaked the program, so that if the timeout is < 1 i get a debug that tells the user they must wait till the red light turns green, then it loops for them to try again.

I also added 3 leds to the game and a piezo.

so if you fault on red,·· a red led blinks several times and the peizo goes off.

if the user gets a time > 100 ms a yellow led lights before the program loops

and if the user gets a reaction time < 100 ms a green led will light up.


My problem,

Is there a quick code that basicly states

" if timecounter is less then 100 BUT more then·1 THEN ? "


' {$STAMP BS2}
' {$PBASIC 2.5}
timecounter··· VAR··· Word


DEBUG" press and hold pushbutton",CR,
···· " to make light turn red ", CR, CR,
···· " When light turns green, let ",CR,
···· " go as fast as you can", CR, CR

···· DO
···· DO
···· LOOP UNTIL IN3 = 1

····· LOW 14
····· HIGH 15
····· PAUSE 1000
····· HIGH 14
····· LOW 15
····· timecounter = 0
····· DO
····· PAUSE 1
····· timecounter = timecounter + 1
····· LOOP UNTIL IN3 = 0
····· LOW 14
····· IF timecounter = < 1· THEN
····· HIGH 6
····· PAUSE 200
····· LOW 6
····· PAUSE 100
····· FREQOUT 4, 500, 5000
····· PAUSE 100
····· HIGH 6
····· PAUSE 200
····· LOW 6
····· PAUSE 100
····· FREQOUT 4, 500, 5000
····· PAUSE 100
····· HIGH 6
····· PAUSE 200
····· LOW 6
····· PAUSE 100
····· FREQOUT 4, 500, 5000
····· PAUSE 100
····· HIGH 6
····· PAUSE 200
····· LOW 6
····· PAUSE 100
····· FREQOUT 4, 500, 5000
····· PAUSE 100
····· HIGH 6
····· PAUSE 200
····· LOW 6
····· FREQOUT 4, 500, 5000
····· PAUSE 100



····· DEBUG " you must wait till the light turns green, try again, ",CR,CR,CR,
··········· " press and hold pushbutton",CR,
··········· " to make light turn red ", CR, CR,
··········· " When light turns green, let ",CR,
··········· " go as fast as you can", CR, CR
····· PAUSE 200
····· ENDIF
····· IF timecounter = >·100 THEN
····· HIGH 11
····· PAUSE 2000
····· LOW 11
····· PAUSE 100
····· ENDIF
····· IF timecounter = <100··· THEN
····· HIGH 10
····· PAUSE 2000
····· LOW 10
····· PAUSE 100
····· ENDIF




····· IF timecounter > 1 THEN
····· DEBUG " your time was " , DEC timecounter,
····· " ms ", CR, CR,
····· " To play again, hold the " , CR,
····· " button down again ", CR, CR
····· ENDIF

··· LOOP

The highlighted one is the one in question.

It works!· but the bug is, if you fault on red, Red's line of code will run " the red led and peizo " but after it's line, it see's the green led is coded for <·100 as well and triggers the green led before looping to the beginning.


Thanks in advance for your time

Kyle



Post Edited (Last~Cell~Left) : 8/28/2006 9:24:00 AM GMT

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-08-28 09:41
    Kyle -

    IF timecounter < 100 AND timecounter > 1 THEN
    blah. blah, blah

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-08-28 16:54
    Kyle,

    ·· You should try attaching your code in the future...That was very difficult to read being all centered like that.· As an attachment it could be loaded into the editor.· Or you could just paste the section where you're trying to get help and use the CODE button to preserve the formatting.· It looks like a # sign.· Take care,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Last~Cell~LeftLast~Cell~Left Posts: 10
    edited 2006-08-28 19:16
    Bruce, thank you. I was the " and " statment I had not attempted. Pretty much tried anything that only came with an error.

    Chris, Well noted, thanks for the advice, Newbie I am ; need to know as i go.,


    Thanks guys..

    It worked just perfet.,


    Kyle
Sign In or Register to comment.