Created
August 24, 2015 10:52
-
-
Save michaelsarduino/bd3646d9706c13c4c099 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SoftwareSerial.h> | |
SoftwareSerial bluetooth(8, 9); | |
int motor1_A = 4; | |
int motor1_B = 2; | |
int motor1_speed = 3; | |
int motor2_A = 5; | |
int motor2_B = 7; | |
int motor2_speed = 6; | |
String richtung; | |
void setup() { | |
pinMode(motor1_A, OUTPUT); | |
pinMode(motor1_B, OUTPUT); | |
pinMode(motor1_speed, OUTPUT); | |
pinMode(motor2_A, OUTPUT); | |
pinMode(motor2_B, OUTPUT); | |
pinMode(motor2_speed, OUTPUT); | |
Serial.begin(9600); | |
bluetooth.begin(9600); | |
} | |
void loop() { | |
if(bluetooth.available() > 0) | |
{ | |
int motor1 = bluetooth.read(); | |
delay(200); | |
int motor2 = bluetooth.read(); | |
Serial.print(motor1); | |
Serial.println(motor2); | |
if(motor1 == 48) | |
{ | |
digitalWrite(motor1_A, HIGH); | |
digitalWrite(motor1_B, LOW); | |
digitalWrite(motor1_speed, HIGH); | |
} | |
if(motor1 == 49) | |
{ | |
digitalWrite(motor1_A, LOW); | |
digitalWrite(motor1_B, LOW); | |
digitalWrite(motor1_speed, LOW); | |
} | |
if(motor1 == 50) | |
{ | |
digitalWrite(motor1_A, LOW); | |
digitalWrite(motor1_B, HIGH); | |
digitalWrite(motor1_speed, HIGH); | |
} | |
if(motor2 == 48) | |
{ | |
digitalWrite(motor2_A, HIGH); | |
digitalWrite(motor2_B, LOW); | |
digitalWrite(motor2_speed, HIGH); | |
richtung = "links"; | |
} | |
if(motor2 == 49) | |
{ | |
if(richtung == "links") | |
{ | |
digitalWrite(motor2_A, LOW); | |
digitalWrite(motor2_B, HIGH); | |
digitalWrite(motor2_speed, HIGH); | |
delay(50); | |
} | |
if(richtung == "rechts") | |
{ | |
digitalWrite(motor2_A, HIGH); | |
digitalWrite(motor2_B, LOW); | |
digitalWrite(motor2_speed, HIGH); | |
delay(50); | |
} | |
digitalWrite(motor2_A, LOW); | |
digitalWrite(motor2_B, LOW); | |
digitalWrite(motor2_speed, LOW); | |
} | |
if(motor2 == 50) | |
{ | |
digitalWrite(motor2_A, LOW); | |
digitalWrite(motor2_B, HIGH); | |
digitalWrite(motor2_speed, HIGH); | |
richtung = "rechts"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment