저번에 올린코드는 제껏도아니고 쓰기가 그래서 제가 한번 만들어본코든데요.
허수 i j를 넣어서 커맨드가 입력될때마다 +한 값이 늘어나게 하고싶은데 잘안되네요
제가 쓴코드에 뭘 첨가해야되는거죠?
#include <SoftwareSerial.h>
#include <Servo.h>
#define moter1EnablePin 13
#define moter1_1 2
#define moter1_2 4
int i=0;
int j=90;
int bluetoothTx = 5;
int bluetoothRx = 6;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
Servo servo;
int angle = 90;
void setup()
{
servo.attach(9);
Serial.begin(9600);
delay(100);
bluetooth.begin(9600);
pinMode(moter1_1, OUTPUT);
pinMode(moter1_2, OUTPUT);
analogWrite(moter1EnablePin, 0);
}
void loop()
{
char cmd;
if(bluetooth.available() )
{ cmd = (char)bluetooth.read();
Serial.print("Command=");
Serial.println(cmd);
if(cmd == '1')
{
digitalWrite(moter1_1, HIGH);
digitalWrite(moter1_2, LOW);
analogWrite(moter1EnablePin, i+300);
}
if(cmd == '2')
{
digitalWrite(moter1_1, HIGH);
digitalWrite(moter1_2, LOW);
analogWrite(moter1EnablePin, i-300);
}
if(cmd == '3')
{
digitalWrite(moter1_1, LOW);
digitalWrite(moter1_2, HIGH);
analogWrite(moter1EnablePin, i+300);
}
if(cmd == '4')
{
digitalWrite(moter1_1, LOW);
digitalWrite(moter1_2, HIGH);
analogWrite(moter1EnablePin, i-300);
}
if(cmd == '0')
{
digitalWrite(moter1_1, LOW);
digitalWrite(moter1_2, LOW);
analogWrite(moter1EnablePin, 0);
delay(1000);
analogWrite(moter1EnablePin, 0);
analogWrite(moter1EnablePin,0);
delay(1000);
}
if(cmd == 'a')
{servo.write(j+10);}
if(cmd == 'b')
{servo.write(j-10);}
if(cmd == 'd')
{servo.write(j);}
}
}
|