SHARE
TWEET

reaction for r0ket

a guest Jan 3rd, 2012 109 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <sysinit.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5.  
  6. #include "basic/basic.h"
  7. #include "basic/config.h"
  8. #include "basic/random.h"
  9.  
  10. #include "lcd/render.h"
  11. #include "lcd/print.h"
  12.  
  13. #include "usetable.h"
  14. /** reaction.c
  15.  *  First l0dable for my r0ket
  16.  *  Improvement is welcome
  17.  *
  18.  * AUTHOR: hubba
  19. */
  20. void ram(void)
  21. {
  22.     char x = gpioGetValue(RB_LED1);
  23.     int rand_wait = 0;
  24.     int react_time=0;
  25.     int start_time = 0;
  26.     int end_time = 0;
  27.  
  28.     gpioSetValue (RB_LED1,0);           //upperleft LED off
  29.     lcdClear();
  30.     lcdPrintln("Hello");
  31.     lcdPrintln(GLOBAL(nickname));
  32.     lcdPrintln("ReACTION");
  33.     lcdRefresh();
  34.     delayms(500);
  35.     while(1)
  36.     {
  37.         react_time = 0;
  38.         lcdPrintln("Press ENTER if ");
  39.         lcdPrintln("LED is on!");
  40.         lcdRefresh();
  41.         rand_wait = getRandom();
  42.         rand_wait = rand_wait%50;
  43.         rand_wait = 40 + rand_wait*4;        // Minimum pause time is 400ms
  44.         for(int i =0; i<=rand_wait; i++)     //directly calling delayms(rand_wait) didn't work
  45.         {
  46.             delayms(10);
  47.         }
  48.         gpioSetValue (RB_LED1, 1);          //upperleft LED ON
  49.         getInputWaitRelease();
  50.         start_time = getTimer()*(SYSTICKSPEED);
  51.         while (getInputWait() != BTN_ENTER);    //wait for user input
  52.         {
  53.  
  54.         }
  55.         end_time =  getTimer()*(SYSTICKSPEED);
  56.         react_time = end_time - start_time;     //measure  used time
  57.         lcdClear();
  58.         lcdPrint("Needed ");
  59.         lcdPrintInt(react_time);
  60.         lcdPrintln(" ms");
  61.         lcdPrintln("DOWN: Exit");
  62.         lcdPrintln("0ther: New game");
  63.         lcdRefresh();
  64.         gpioSetValue (RB_LED1,0);           //upperleft LED off
  65.  
  66.         getInputWaitRelease();
  67.         if(getInputWait() ==  BTN_DOWN)     //Check for Exit/new game
  68.         {
  69.             gpioSetValue (RB_LED1, x);      //upperleft LED as before l0dable executed
  70.             return;
  71.         }
  72.     }
  73.     /* NEVER LAND HERE */
  74.     lcdPrintln("Flow-Error");
  75.     lcdRefresh();
  76.     return;
  77. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top