Example Code for Arduino-Check Button A Press
Last revision 2025/12/26
This article provides example code for Arduino to check button A press, detailing hardware and software preparations including using Bluno and BLE gamepad, and explains the code execution process for detecting button press.
Hardware Preparation
Software Preparation
- Download Arduino IDE: Click to download Arduino IDE
- BLE Wireless Gamepad library (Gitbub)
Other Preparation Work
Set the receiver end to peripheral mode, turn on the gamepad and put both less than 10 cm to establish Kiss connection.
Sample Code
int str[14]={'\0'};
void setup()
{
Serial.begin(57600);
}
void loop()
{
if(Serial.available())
{
for(int i=0;i<14;++i)
{
str[i] = Serial.read();
delay(2);
}
if(str[6] & 0x01)
{
//Press button A
}
}
}
Result
When button "A" is pressed, the condition str[6] & 0x01 becomes true, and the code inside the conditional block (commented as "Press button A") executes.
Was this article helpful?
