Arduino的代码:
array = inputarray[:]
蓝牙接收功能
#include "SoftwareSerial.h"
#define sensorPin A1
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
void setup() {
//configure pins 14,15 of arduino mega to serial TX/RX respectively
SoftwareSerial bluetooth(14, 15);
//configure AD pins for 9600 hz;
sbi(ADCSRA, ADPS2);
sbi(ADCSRA, ADPS1);
sbi(ADCSRA, ADPS0);
Serial1.begin(9600);
}
void loop() {
while (1) {
float vector[400];
int i = 0;
for (int i = 0; i < 400; i++) {
vector[i] = floatMap(analogRead(sensorPin), 0, 1023, 0, 5);
}
for (int i = 0; i < 400; i = i++) {
Serial1.print('#');
Serial1.print(vector[i],2);
delay(30);
}
}
}
float floatMap(float x, float inMin, float inMax, float outMin, float outMax) {
return (x - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
}
int procura_inic(int vector[]) {
for (int i = 0; i < 319; i++) {
if (vector[i] == 0 && (vector[i + 1] > vector[i])) {
return i;
break;
}
}
}
跟踪功能
public void run() {
byte[] buffer = new byte[1024]; // buffer store for the stream
int bytes = 0;
int begin = 0;// bytes returned from read()
while (true) {
try {
bytes += mmInStream.read(buffer, bytes, buffer.length - bytes);
//This loop is responsible for message sending.
for(int i = begin; i < bytes; i++) {
mHandler.obtainMessage(
MESSAGE_READ, begin, i, buffer).sendToTarget();
begin = i + 1;
if(i == bytes - 1) {
bytes = 0;
begin = 0;
}
}
} catch (IOException e) {
break;
}
}
}