TimpZ

TimingTest

Apr 15th, 2017
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 KB | None | 0 0
  1. #include "Nintendo.h"
  2. /* This code uses the Nicohood Library
  3.  * Original code by Simple Controllers
  4.  * Code edited by TimpZ
  5.  * Use this code at your own risk
  6.  */
  7. //This makes the controller bidirection data line on pin number8
  8. CGamecubeConsole gcConsole(8);      //Defines a "Gamecube Console" sending data to the console on pin 8
  9. Gamecube_Data_t d = defaultGamecubeData;   //Structure for data to be sent to console
  10.  
  11. //This is needed but you don't need a controller on pin 7
  12. CGamecubeController gcController(7);
  13.  
  14. const int X = 22;
  15.  
  16. unsigned long pMic = 0;
  17. const long interval = 116669;
  18. const long firstPress = 0;
  19. const long secPress = 66668;
  20. bool btnPressOld = 0;
  21.  
  22.  
  23. void setup()
  24. {
  25.   //This is establishing the pin assignments up there to input pins
  26.   pinMode(X, INPUT_PULLUP);
  27.  
  28.   //This is needed to run the code.
  29.   gcController.read();
  30.  
  31.  
  32.   pinMode(LED_BUILTIN, OUTPUT);
  33. }
  34.  
  35. void loop()
  36. {
  37.   //This resets and establishes all the values after the controller sends them to the console and helps with initial "zeroing"
  38.   int pinX = 0;
  39.   unsigned long cMic = micros();
  40.   bool btnPress = 0;
  41.  
  42.   if (digitalRead(X) == LOW){
  43.     btnPress = 1;
  44.     if (btnPress != btnPressOld && btnPressOld == 0){
  45.       btnPressOld = btnPress;
  46.       pMic = cMic;
  47.     }
  48.     if(cMic - pMic >= interval){
  49.       pMic = cMic;
  50.     }
  51.     if (cMic - pMic >= firstPress && cMic - pMic < secPress){
  52.       digitalWrite(LED_BUILTIN, LOW);
  53.     }
  54.     else if (cMic - pMic >= secPress && cMic - pMic < interval){
  55.       digitalWrite(LED_BUILTIN, HIGH);
  56.     }
  57.   }
  58.  
  59.   if (btnPress != btnPressOld && btnPressOld == 1){
  60.     btnPressOld = btnPress;
  61.   }
  62.  
  63.  
  64.   // Enable the line below to see the issue
  65.   //gcConsole.write(d);
  66. }
Advertisement
Add Comment
Please, Sign In to add comment