简体   繁体   中英

Android Bluetooth using GraphView and Arduino

I currently have a realtime graph (Android GraphView) running smoothly from my arduino's analog sensor to a bluetooth module and then being streamed on the Android with the following code. I was wondering if someone can point me in the right direction to create a function that receives the double s returned in this function and averages every 5 values to return it. The stream is sending a new double every 20 miliseconds from the arduino. I tried adding a loop with counter to store every 5 values in an array and divide the sum by 5, but it's not repeating in realtime.

public static double read() throws IOException
 {
      byte[] buffer = new byte[1024];
      dataInStream = new DataInputStream(mmInStream);
      Scanner scanner = new Scanner(dataInStream);
      double s = scanner.nextDouble();
      }
      return s;
  }

try to add synchronized before double or may be before static. like this public static synchronized double read() throws IOException... hope it will work for you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM