Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define button 8
- int xAxis, yAxis, buttonState;
- void setup() {
- pinMode(button, INPUT);
- Serial.begin(38400); // Default communication rate of the Bluetooth module
- }
- void loop() {
- xAxis = analogRead(A0); // Read Joysticks X-axis
- yAxis = analogRead(A1); // Read Joysticks Y-axis
- buttonState = digitalRead(button);
- // Send the values via the serial port to the slave HC-05 Bluetooth device
- Serial.write(xAxis/4); // Dividing by 4 for converting from 0 - 1023 to 0 - 256, (1 byte) range
- Serial.write(yAxis/4);
- if (buttonState == HIGH) {
- Serial.write('1'); // Sends '1' to the master to turn on LED
- }
- else {
- Serial.write('0');
- }
- delay(20);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement