我们正在制作带有五个传感器的键盘,而mojibake存在问题
如果我们单击传感器'a'五次,则应该有五个'ㄱ'
但是有像附件一样的mojibake。
我们认为此问题与unicode有关,但找不到确切的探针
请回答什么问题。谢谢
#include <SoftwareSerial.h>
#include<Wire.h>
#define BT_RXD 8
#define BT_TXD 7
SoftwareSerial bluetooth(BT_RXD, BT_TXD);
int SensorPin1 = A0;
int SensorPin2 = A1;
int SensorPin3 = A2;
int SensorPin4 = A3;
int SensorPin5 = A4;
const int MPU_addr=0x68;
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
void setup()
{
Wire.begin();
Wire.beginTransmission(MPU_addr);
Wire.write(0x6B);
Wire.write(0);
Wire.endTransmission(true);
Serial.begin(9600);
bluetooth.begin(9600);
}
void loop()
{
int SensorReading1 = analogRead(SensorPin1);
int SensorReading2 = analogRead(SensorPin2);
int SensorReading3 = analogRead(SensorPin3);
int SensorReading4 = analogRead(SensorPin4);
int SensorReading5 = analogRead(SensorPin5);
int FSR1 = map(SensorReading1, 0, 1024, 0, 255);
int FSR2 = map(SensorReading2, 0, 1024, 0, 255);
int FSR3 = map(SensorReading3, 0, 1024, 0, 255);
int FSR4 = map(SensorReading4, 0, 1024, 0, 255);
int FSR5 = map(SensorReading5, 0, 1024, 0, 255);
Wire.beginTransmission(MPU_addr); //-32768~32767
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPU_addr,14,true); // request a total of 14 registers
AcX=Wire.read() << 8|Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
AcY=Wire.read() << 8|Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
AcZ=Wire.read() << 8|Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
Tmp=Wire.read() << 8|Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
GyX=Wire.read() << 8|Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
GyY=Wire.read() << 8|Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
GyZ=Wire.read() << 8|Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
Serial.print("AcX = "); Serial.print(AcX);
Serial.print(" | AcY = "); Serial.print(AcY);
Serial.print(" | AcZ = "); Serial.println(AcZ);
//Serial.print(" | Tmp = "); Serial.print(Tmp/340.00+36.53); //equation for temperature in degrees C from datasheet
//Serial.print(" | GyX = "); Serial.print(GyX);
//Serial.print(" | GyY = "); Serial.print(GyY);
//Serial.print(" | GyZ = "); Serial.println(GyZ);
if(FSR1 > 100)
{
//Serial.println("ㄱ");
bluetooth.write("ㄱ");
}
if(FSR2 > 100)
{
//Serial.println("ㄱ");
bluetooth.write(FSR2);
}
if(FSR3 > 100)
{
//Serial.println("ㄱ");
}
if(FSR4 > 100)
{
//Serial.println("2");
}
if(FSR5 > 100)
{
//Serial.println("ㄱ");
bluetooth.write("ㄱ");
}
if (bluetooth.available())
{
//Serial.write(bluetooth.read());
}
if (Serial.available())
{
//bluetooth.write(FSR);
}
delay(333);
}
答案 0 :(得分:0)
您要发送的是字节,要发送的确切字节取决于编辑器的编码。当您的capston应用程序接收到这些字节时,它将尝试根据capston的编码来解释它们。不知道可能是什么。无论如何,您需要做的是从arduino发送utf-8数据,并确保capston应用程序解码utf-8数据。