아두이노 블루투스 RC카 를 만들려고하는데
소스는 완성을 했는데
회로 구성을 어떻게 해야될지 모르겠습니다.
IC는 L293B 쓰는데 IC에 몇번을 몰꼽아야하는지 모르겠습니다. 소스 보고 좀 도와주세요
#include <Servo.h>
#include <SoftwareSerial.h>
int relayPin = 12;
SoftwareSerial bluetooth(2,3);
int servoPin = 9;
Servo servo;
int angle=60;
int speedR=0;
int speedL=0;
void setup()
{
servo.attach(servoPin);
Serial.begin(9600);
bluetooth.begin(9600);
pinMode(relayPin,OUTPUT);
digitalWrite(relayPin,HIGH);
}
void loop()
{
if(bluetooth.available())
{
char data = bluetooth.read();
if(data == 'X')
{
Serial.write("x");
speedR=0;
speedL=0;
digitalWrite(4, HIGH);
digitalWrite(7, LOW);
analogWrite(6, 0);
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
analogWrite(11, 0);
}
if(data == '1')
{
Serial.write("x");
speedR=0;
speedL=0;
digitalWrite(4, HIGH);
digitalWrite(7, LOW);
analogWrite(6, 255);
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
analogWrite(11, 175);
}
if(data == '2')
{
Serial.write("x");
speedR=0;
speedL=0;
digitalWrite(4, HIGH);
digitalWrite(7, LOW);
analogWrite(6, 255);
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
analogWrite(11, 255);
}
if(data == '3')
{
Serial.write("x");
speedR=0;
speedL=0;
digitalWrite(4, HIGH);
digitalWrite(7, LOW);
analogWrite(6, 175);
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
analogWrite(11, 255);
}
if(data == '4')
{
Serial.write("x");
speedR=0;
speedL=0;
digitalWrite(4, HIGH);
digitalWrite(7, LOW);
analogWrite(6, 255);
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
analogWrite(11, 0);
}
if(data == '5')
{
Serial.write("x");
speedR=0;
speedL=0;
digitalWrite(4, HIGH);
digitalWrite(7, LOW);
analogWrite(6, 0);
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
analogWrite(11, 0);
}
if(data == '6')
{
Serial.write("x");
speedR=0;
speedL=0;
digitalWrite(4, HIGH);
digitalWrite(7, LOW);
analogWrite(6, 0);
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
analogWrite(11, 255);
}
if(data == '7')
{
Serial.write("x");
speedR=0;
speedL=0;
digitalWrite(4, HIGH);
digitalWrite(7, HIGH);
analogWrite(6, 0);
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
analogWrite(11, 0);
}
if(data == '8')
{
Serial.write("x");
speedR=0;
speedL=0;
digitalWrite(4, HIGH);
digitalWrite(7, HIGH);
analogWrite(6, 0);
digitalWrite(13, HIGH);
digitalWrite(12, HIGH);
analogWrite(11, 0);
}
if(data == '9')
{
Serial.write("x");
speedR=0;
speedL=0;
digitalWrite(4, HIGH);
digitalWrite(7, LOW);
analogWrite(6, 0);
digitalWrite(13, HIGH);
digitalWrite(12, HIGH);
analogWrite(11, 0);
}
//servo
if(data=='R')
{
if(angle<100)
{
angle = angle+15;
servo.write(angle);
}
}
if(data=='L')
{
if(angle>20)
{
angle = angle-15;
servo.write(angle);
}
}
}
}
|