// // reaction: // Reaction timer using the Raspberry Ladder board // CLS PROC ladderSetup NUMFORMAT (5, 3) PRINT PRINT "Reaction timer - with the Raspberry Ladder board" PRINT "================================================" PRINT PRINT "All LEDs will be ON to start." PRINT PRINT "Press Button A (The bottom one) to start the count down timer." PRINT "At that point the main LEDs will go OFF, leaving the 2 small" PRINT "Red & Green LEDs on." PRINT PRINT "These will go OFF after a short time, then you need to press" PRINT "Button A again." PRINT PRINT "For each 50 milliseconds you don't press the button, one of the" PRINT "big LEDs will light..." PRINT PRINT "Ready when you are..." PRINT // FOR led = 0 TO 9 CYCLE DigitalWrite (led, 1) REPEAT // // Wait for button A, then turn off the main LEDs // WHILE DigitalRead (buttonA) = 1 CYCLE REPEAT // FOR led = 0 TO 7 CYCLE DigitalWrite (led, 0) REPEAT // // Wait for it to be released // WHILE DigitalRead (buttonA) = 0 CYCLE REPEAT // // Now wait a random time and turn off the small LEDs // WAIT (RND (1) * 2 + 1) // // However if we're pushing the button, we've tried to jump the gun, so ... // IF DigitalRead (buttonA) = 0 THEN PRINT "Cheat? Pushed too soon..." END ENDIF // DigitalWrite (rMan, 0) DigitalWrite (gMan, 0) // // Go gadget go! // start = TIME CYCLE IF DigitalRead (buttonA) = 0 THEN BREAK IF TIME > (start + 50) THEN DigitalWrite (ledBlue2, 1) IF TIME > (start + 100) THEN DigitalWrite (ledBlue1, 1) IF TIME > (start + 150) THEN DigitalWrite (ledGreen2, 1) IF TIME > (start + 200) THEN DigitalWrite (ledGreen1, 1) IF TIME > (start + 250) THEN DigitalWrite (ledYellow2, 1) IF TIME > (start + 300) THEN DigitalWrite (ledYellow1, 1) IF TIME > (start + 350) THEN DigitalWrite (ledRed2, 1) IF TIME > (start + 400) THEN DigitalWrite (ledRed1, 1) REPEAT etime = TIME PRINT "OK. Count the LEDs... 50ms for each LED lit..." PRINT PRINT "But I made it: "; (etime - start) / 1000; " seconds." END // // ladderSetup: // This is the setup procedure. We initialise the various // pins into the correct modes and extinbuish all the LEDs // DEF PROC ladderSetup LOCAL i FOR i = 0 TO 9 CYCLE PinMode (i, 1) // Output DigitalWrite (i, 0) // Off REPEAT FOR i = 10 TO 13 CYCLE PinMode (i, 0) // Input PullUpDn (i, 2) // Activate internal pull-up REPEAT // // Make some globals // ledRed1 = 0 ledRed2 = 1 ledYellow1 = 2 ledYellow2 = 3 ledGreen1 = 4 ledGreen2 = 5 ledBlue1 = 6 ledBlue2 = 7 gMan = 8 rMan = 9 // buttonA = 11 buttonB = 10 buttonC = 12 buttonD = 13 // ENDPROC