#include <Servo.h>
char blueToothVal;
char lastValue;
Servo servo;
int val;
int motorPin = 8;
void setup() {
// put your setup code here, to run once:
Serial1.begin(9600);
servo.attach(6);
servo.write(90);
pinMode(motorPin, OUTPUT);
lastValue = 0;
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial1.available()) {
blueToothVal = Serial1.read();
}
if (blueToothVal != lastValue) {
if (blueToothVal == '0') {
servo.write(90);
delay(abs(lastValue - blueToothVal)*15);
lastValue = blueToothVal;
}
if (blueToothVal == '1') {
servo.write(105);
delay(abs(lastValue - blueToothVal)*15);
lastValue = blueToothVal;
}
if (blueToothVal == '2') {
servo.write(75);
delay(abs(lastValue - blueToothVal)*15);
lastValue = blueToothVal;
}
if (blueToothVal == '3') {
digitalWrite(motorPin, HIGH);
}
if (blueToothVal == '4') {
digitalWrite(motorPin, LOW);
}
}
/* else {
digitalWrite(motorPin, LOW);
}*/
}
Comments