#include <SoftwareSerial.h>
//#define MIN 0
//#define MAX 359
SoftwareSerial BTSerial(2, 3);
const int xPin = 0;
const int yPin = 1;
const int zPin = 2;
int SensorPin = A3;
int minVal = 265;
int maxVal = 402;
double x;
double y;
double z;
char um;
void setup() {
Serial.begin(9600);
BTSerial.begin(9600);
}
void loop() {
int xRead = analogRead(xPin);
int yRead = analogRead(yPin);
int zRead = analogRead(zPin);
int xAng = map(xRead, minVal, maxVal, -90, 90);
int yAng = map(yRead, minVal, maxVal, -90, 90);
int zAng = map(zRead, minVal, maxVal, -90, 90);
x = RAD_TO_DEG * (atan2(-yAng, -zAng) + PI);
y = RAD_TO_DEG * (atan2(-xAng, -zAng) + PI);
z = RAD_TO_DEG * (atan2(-yAng, -xAng) + PI);
int SensorReading = analogRead(SensorPin);
int p = map(SensorReading, 0, 1024, 0, 255);
// BTSerial.print(" x ");
// BTSerial.print(x);
// BTSerial.print(" y ");
// BTSerial.print(y);
// BTSerial.print(" z ");
// BTSerial.print(z);
// BTSerial.print(" p ");
// BTSerial.print(p);
int stnd = 180;
int q = x - stnd;
int q2 = y - stnd;
int q3 = z - stnd;
if(q>85 && q<105 )
{
um = 'a';
}
else if(q<-85 && q>-105 )
{
um = 'b';
}
else if(q2>85 && q<105 )
{
um = 'c';
}
else if(q2<-85 && q>-105 )
{
um = 'd';
}
else
{
um = 'z';
}
BTSerial.print(um);
delay(100);
}
소리가 계속 겹쳐서 출력되는데 뭐가 문제인가요?
('a' 랑 'd' 가 동시에 출력되요..)
|
다음글 |
if문 빠져나가는것좀 알려주세요 ㅠㅠ
|
2018-09-26 |