0% found this document useful (0 votes)
3 views1 page

Arduino Joystick Bluetooth Data Package

The document contains an Arduino sketch that reads joystick and button inputs. It defines a data package structure to send the joystick's X and Y axis values along with the button state to a slave device via Bluetooth. The data is sent every 50 milliseconds using the Serial communication interface.

Uploaded by

bdtarun211
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Arduino Joystick Bluetooth Data Package

The document contains an Arduino sketch that reads joystick and button inputs. It defines a data package structure to send the joystick's X and Y axis values along with the button state to a slave device via Bluetooth. The data is sent every 50 milliseconds using the Serial communication interface.

Uploaded by

bdtarun211
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

const int joystick1X = A0;

const int joystick1Y = A1;

const int button = 2;

// Define data package structure


struct DataPackage {
char startByte;
int xaxis1;
bool buttonState;
int yaxis2;
char endByte;
};

void setup() {
[Link](38400);
pinMode(button, INPUT_PULLUP);

void loop() {
// Read joystick values
int xaxis1 = analogRead(joystick1X);
int yaxis2 = analogRead(joystick1Y);

// Read button state


bool buttonState = digitalRead(button);

// Create data package


DataPackage data;
[Link] = 'S';
data.xaxis1 = xaxis1;
[Link] = buttonState;
data.yaxis2 = yaxis2;
[Link] = 'E';

// Send data package to slave device via Bluetooth


[Link]((char*)&data, sizeof(DataPackage));

delay(50);
}

You might also like