In the example code they have these lines:
#define BUTTON_X 6
#define BUTTON_Y 2
#define BUTTON_A 5
#define BUTTON_B 1
#define BUTTON_SELECT 0
#define BUTTON_START 16
This is definition of bit addressing on a some ports.
#define BUTTON_X 6
#define BUTTON_Y 2
#define BUTTON_A 5
#define BUTTON_B 1
#define BUTTON_SELECT 0
#define BUTTON_START 16
Read a number of ports into a 32bit number called button
This is uses the mask, a shift a value, and, compares the bit for BUTTON_A
if (! (buttons & (1UL << BUTTON_A))) {
Serial.println("Button A pressed");
}
GCBASIC
#define BUTTON_X 6
#define BUTTON_Y 2
#define BUTTON_A 5
#define BUTTON_B 1
#define BUTTON_SELECT 0
#define BUTTON_START 16
Dim button_mask as Long
button_mask = 0b10000000001100111
buttons = Read4BytesViaI2C()
If Not ( buttons & ( FnLSL( 1, BUTTON_A )) Then
HserPrint "A button pressed"
End If
However, the C is very slow. Read the four bytes via I2C to buttons and use...
My assumption is when a bit is low the button is pressed.
#define BUTTON_X 6
#define BUTTON_Y 2
#define BUTTON_A 5
#define BUTTON_B 1
#define BUTTON_SELECT 0
#define BUTTON_START 16
Dim button as Long
buttons = Read4BytesViaI2C( button)
If buttons.BUTTON_A = 0 Then
HserPrint "A button pressed"
End If
How this explains.
Evan
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm using this Game Pad board https://www.adafruit.com/product/5743
In the example code they have these lines:
#define BUTTON_X 6
#define BUTTON_Y 2
#define BUTTON_A 5
#define BUTTON_B 1
#define BUTTON_SELECT 0
#define BUTTON_START 16
uint32_t button_mask = (1UL << BUTTON_X) | (1UL << BUTTON_Y) | (1UL << BUTTON_START) |
(1UL << BUTTON_A) | (1UL << BUTTON_B) | (1UL << BUTTON_SELECT);
Later in the code it says:
uint32_t buttons = ss.digitalReadBulk(button_mask);
This is essentially reading the state of port.
This is definition of bit addressing on a some ports.
#define BUTTON_X 6
#define BUTTON_Y 2
#define BUTTON_A 5
#define BUTTON_B 1
#define BUTTON_SELECT 0
#define BUTTON_START 16
uint32_t button_mask = (1UL << BUTTON_X) | (1UL << BUTTON_Y) | (1UL << BUTTON_START) |
(1UL << BUTTON_A) | (1UL << BUTTON_B) | (1UL << BUTTON_SELECT);
So, button_mask now equals 0b10000000001100111
Read a number of ports into a 32bit number called
button
This is uses the mask, a shift a value, and, compares the bit for BUTTON_A
if (! (buttons & (1UL << BUTTON_A))) {
Serial.println("Button A pressed");
}
GCBASIC
However, the C is very slow. Read the four bytes via I2C to
buttons
and use...My assumption is when a bit is low the button is pressed.
How this explains.
Evan
Thanks!