Skip to content

Commit c616ca5

Browse files
committed
adjusted to allow for much better button latency
1 parent 3dc65cf commit c616ca5

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

Buttons.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,17 @@ void Buttons::init() {
3030
//if (DEBUG) {Serial.print(F("DEBUG,buttons: initialized Gamepad1\r\n"));}
3131
}
3232

33-
void Buttons::readInputs() {
33+
bool Buttons::readInputs() {
3434
unsigned char buttonPushed = 2; //this is set to notify light show that a button press has happened
35+
bool buttonChangedState = false;
3536
// read shift register values
3637
if(buttonReader.update() || numberButtonsPressed > 0) {
3738
//if (DEBUG) {Serial.print(F("DEBUG"));}
3839
for(unsigned char i = 0; i < 24; i++) {
3940
bool currentButtonState = !buttonReader.state(i);
4041
//if (DEBUG) {Serial.print(currentButtonState);}
4142
if (currentButtonState != config.lastButtonState[i]) {
42-
43+
buttonChangedState = true;
4344

4445
if (currentButtonState == 1) {
4546
buttonPushed = 1;
@@ -63,6 +64,7 @@ void Buttons::readInputs() {
6364
config.lightShowState = INPUT_RECEIVED_SET_LIGHTS_LOW;
6465
}
6566
}
67+
return buttonChangedState;
6668
}
6769

6870
bool Buttons::sendButtonPush(unsigned char i, bool currentButtonState) {

Buttons.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Buttons {
99

1010
public:
1111
Buttons();
12-
void readInputs();
12+
bool readInputs();
1313
void init();
1414
void sendButtonState();
1515
bool sendButtonPush(unsigned char i, bool currentButtonState);

PinOne.ino

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ void setup() {
3737

3838

3939
void loop() {
40-
//long int t1 = millis();
41-
buttons.readInputs();
42-
if (!USBDevice.isSuspended()) {
40+
// unsigned long t1 = micros();
41+
if (!buttons.readInputs() && !USBDevice.isSuspended()) {
4342
plunger.plungerRead();
4443
if (config.accelerometerEprom > 0) {
4544
accel.accelerometerRead();
@@ -50,10 +49,15 @@ void loop() {
5049
config.updateUSB = false;
5150
}
5251
comm.communicate();
52+
} else {
53+
Gamepad1.write();
54+
//unsigned long t2 = micros();
55+
// Serial.print(F("DEBUG,Time taken by the task: "));
56+
// Serial.print(t2 - t1);
57+
// Serial.println(F(" microseconds"));
58+
// delay(100);
5359
}
54-
// long int t2 = millis();
55-
// Serial.print(F("DEBUG,Time taken by the task: ")); Serial.print((t2-t1)); Serial.print(F(" milliseconds\r\n"));
56-
// delay(100);
60+
5761
//Serial.println("arduino is running");
5862

5963
}

0 commit comments

Comments
 (0)