제가 음성인식과 어플로 서보모터를 제어하려고 하는 중입니다.
아래 소스로 하면
음성인식으로는 서보모터가 돌아가는데
어플로는 ON를 한 번 누르면 0.1초 돌아가다 마네요.
OFF는 먹지도 않아요..
#include<Servo.h>
#include<SoftwareSerial.h>
#include<DHT.h>
SoftwareSerial my(3,2);
DHT dht(8,DHT11);
Servo myServo;
int threshold = 200; //Change This
int volume;
String s = "";
int btem=0,bhum=0;
void setup() {
// put your setup code here, to run once:
myServo.write(0);
Serial.begin(9600);
my.begin(9600);
}
void loop() {
char data;
if(my.available()){
data = my.read();
Serial.write(data);
if(data=='a'){
}
else if(data=='b'){
}
else if(data=='c'){
myServo.attach(9);
}
else if(data=='d'){
myServo.detach();
}
}
Serial.println(volume);
delay(100);
int tem = dht.readTemperature();
int hum = dht.readHumidity();
if(btem!=tem || bhum!=hum){
String t = "";
t = tem;
String h = "";
h = hum;
Serial.println(t+h);
my.println(t+h);
btem = tem;
bhum = hum;
}
volume = analogRead(A0); // Reads the value from the Analog PIN A0
//Debug mode
if(volume>=threshold){
myServo.attach(9);
delay(100);
}
else{
myServo.detach();
}
// put your main code here, to run repeatedly:
}
도대체 뭐가 문제죠..????
|