나노 보드에 부저 블루투스 서보모터 사용중입니다. 다름이 아니라
컴퓨터로 USB연결 시 정상작동 되는데 반해 9V로 전원을 주고 페어링 후 서보모터를 작동하면 페어링이 끊기는 문제가 있는데,
해결방안이 있는지 여쭈어보고 싶습니다. (부저와 블루투스는 작동과 연결 잘 됩니다.)
#include
#include
SoftwareSerial mySerial(11, 12); // RX, TX
Servo myservo;
int pos = 0;
int piezo = 2;
// 피에조 부저를 2번 핀으로 설정
int numTones = 8; // 톤 배열 수
int tones[] = {2093,2349,2637,2793,3136,3520,3951,4186};
void setup() {
{
myservo.attach (13);
}
pinMode(piezo, OUTPUT);
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Goodnight moon!");
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
mySerial.println("Hello, world?");
}
void loop() {
if (mySerial.available()) //폰 >> PC 출력 ㅇ
{
char a = (char)mySerial.read();
Serial.write(a);
if (a == '1') // 만약에 데이터가 1이면 서브모터 180도
{
for (pos = 0; pos <= 180; pos += 1)
{
myservo.write (pos);
delay (15);
}
}
else if (a == '0')
{
for (pos = 180; pos >= 0; pos -= 1) // 0이 입력되면 180에서 0으로
{
myservo.write (pos);
delay (15);
}
}
else if ( a =='2')
{
myservo.write(pos=0); //각도 0으로 복귀
delay (100);
}
else if (a == '3')
{
for (int i = 0; i < numTones ; i++)
{
tone(piezo, tones[i]);
if( a == '6')
{
noTone(piezo);
}
delay(500);
}
noTone(piezo);
}
else if (a == '4')
{
noTone(piezo);
}
if (Serial.available()) // 시리얼 모니터에서 데이터가 입력되면
mySerial.write (Serial.read());
}
}
|