#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);
}*/
}
int count = 0;
char x = '0';
char y = '0';
void setup() {
Serial.begin(9600);
delay(1000);
}
void loop() {
// Your computer will receive these characters from a USB keyboard.
if (analogRead(A0) > 580) {
x = '4';
}
else if (analogRead(A0) < 500) {
x = '3';
}
if (analogRead(A1) > 580) { //right
y = '2';
}
else if (analogRead(A1) < 470) { //left
y = '1';
}
else {
y = '0';
}
//Keyboard.println(x);
Keyboard.println(y);
//Keyboard.println(count);
// increment the count
count = count + 1;
// typing too rapidly can overwhelm a PC
delay(25);
}
Thanks to My mom.
Comments