From 0b79c943a640e3d5efd07dc67a027692f3e4928a Mon Sep 17 00:00:00 2001 From: MickGyver Date: Mon, 11 May 2020 07:39:11 +0300 Subject: [PATCH] Small fix to the CD32 controller adapter. --- CD32ControllerUSB/CD32ControllerUSB.ino | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/CD32ControllerUSB/CD32ControllerUSB.ino b/CD32ControllerUSB/CD32ControllerUSB.ino index 13895bd..977e56f 100644 --- a/CD32ControllerUSB/CD32ControllerUSB.ino +++ b/CD32ControllerUSB/CD32ControllerUSB.ino @@ -27,7 +27,7 @@ // Additionally serial number is used to differentiate arduino projects to have different button maps! const char *gp_serial = "CD32/C= to USB"; -#define BUTTON_READ_DELAY 300 // Button read delay in µs +#define BUTTON_READ_DELAY 100 // Button read delay in µs // Controller DB9 pins (looking face-on to the end of the plug): // @@ -71,8 +71,7 @@ uint8_t buttons = 0; uint8_t buttonsPrev = 0; // Timing -long microsNow = 0; -long microsButtons = 0; +uint32_t microsButtons = 0; // CD32 controller detection uint8_t detection = 0; @@ -92,14 +91,11 @@ void setup() void loop() { - // Get current time - microsNow = micros(); - // Read X and Y axes axes = ~(PIND & B00011101); // See if enough time has passed since last button read - if(microsNow > microsButtons+BUTTON_READ_DELAY) + if(micros() - microsButtons > BUTTON_READ_DELAY) { // Set pin 6 (clock, PD7) and pin 5 (latch, PF7) as output low PORTD &= ~B10000000; // low to disable internal pull-up (will become low when set as output) @@ -141,7 +137,7 @@ void loop() if(detection != B0000001) buttons = ~( ((PIND & B10000000) >> 7) | ((PINF & B01000000) >> 5) | B11111100 ); - microsButtons = microsNow+400; + microsButtons = micros(); } // Has any buttons changed state?