简体   繁体   English

使用 GraphView 和 Arduino 的 Android 蓝牙

[英]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.我目前有一个实时图形(Android GraphView)从我的 arduino 模拟传感器平稳运行到蓝牙模块,然后使用以下代码在 Android 上流式传输。 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.我想知道是否有人可以指出我正确的方向来创建一个函数,该函数接收此函数中返回的 double s,并每 5 个值取平均值以返回它。 The stream is sending a new double every 20 miliseconds from the arduino.该流每 20 毫秒从 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.我尝试添加一个带计数器的循环,将每 5 个值存储在一个数组中,并将总和除以 5,但它并没有实时重复。

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像这个 public static synchronized double read() 抛出 IOException ......希望它对你有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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