Advertisement
Guest User

pilot

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