Created
February 2, 2018 12:19
-
-
Save jan-patrick/8b4a50c34b927703b1652f2bf0331aaa to your computer and use it in GitHub Desktop.
reel-withoutMaster
This file contains 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 <Servo.h> | |
Servo shinten; | |
Servo svrechts; | |
Servo svlinks; | |
int incomingByte = 3; | |
int ballda; | |
int ledshooter = 24; | |
int ledtarget = 22; | |
int motorrechts_A=12; | |
int motorrechts_B=9; | |
int motorlinks_A=13; | |
int motorlinks_B=8; | |
int motorrechts_Speed=3; | |
int motorlinks_Speed=11; | |
int senvorne=A3; | |
int senhinten=A2; | |
int sensorWertv=0; | |
int sensorWerth=0; | |
int durchlauf; | |
void setup() { | |
Serial.begin(9600); | |
int ballda = 0; | |
int ballziel = 8; | |
durchlauf = 0; | |
//Setup Motor Rechts | |
pinMode(motorrechts_A, OUTPUT); //Initiates Motor Channel A pin | |
pinMode(motorrechts_B, OUTPUT); //Initiates Brake Channel A pin | |
//Setup Motor Links | |
pinMode(motorlinks_A, OUTPUT); //Initiates Motor Channel A pin | |
pinMode(motorlinks_B, OUTPUT); //Initiates Brake Channel A pin | |
pinMode(ledshooter, OUTPUT); //Initiates Brake Channel A pin | |
pinMode(ledtarget, OUTPUT); //Initiates Brake Channel A pin | |
shinten.attach(10); | |
svrechts.attach(5); | |
svlinks.attach(6); | |
digitalWrite(ledshooter, LOW); | |
digitalWrite(ledtarget, LOW); | |
} | |
void loop(){ | |
if (Serial.available() > 0) { | |
// read the incoming byte: | |
incomingByte = Serial.parseInt(); | |
// say what you got: | |
Serial.print("I received: "); | |
Serial.println(incomingByte, DEC); | |
} | |
int ballziel = incomingByte; | |
if(ballziel==3){ | |
digitalWrite(ledtarget, HIGH); | |
}else{ | |
digitalWrite(ledtarget, LOW); | |
} | |
if(analogRead(senvorne) >= 500 && ballda == 0){ //sichere Erkennung bei Wert 450 | |
//Ball nach hinten | |
digitalWrite(ledshooter, HIGH); | |
ballda = 1; | |
shinten.write(135); | |
delay(250); | |
//Motor A forward @ low speed | |
digitalWrite(motorrechts_A, HIGH); //Establishes forward direction of Channel A | |
digitalWrite(motorrechts_B, LOW); //Disengage the Brake for Channel A | |
analogWrite(motorrechts_Speed, 90); //Spins the motor on Channel A at full speed | |
//Motor B backward @ low speed | |
digitalWrite(motorlinks_A, LOW); //Establishes backward direction of Channel B | |
digitalWrite(motorlinks_B, LOW); //Disengage the Brake for Channel B | |
analogWrite(motorlinks_Speed, 60); //Spins the motor on Channel B at half speed | |
shinten.write(80); | |
delay(2000); | |
analogWrite(motorrechts_Speed, 0); //Spins the motor on Channel A at full speed | |
analogWrite(motorlinks_Speed, 0); //Spins the motor on Channel B at half speed | |
digitalWrite(motorrechts_B, HIGH); //Engage the Brake for Motor Rechts | |
digitalWrite(motorlinks_B, HIGH); //Engage the Brake for Motor Links | |
delay(1000); | |
}else if(analogRead(senhinten)>=500){ | |
digitalWrite(ledshooter, HIGH); | |
ballda = 1; | |
switch (incomingByte) { | |
case 0: //nach links hinten | |
svrechts.write(100); | |
delay(50); | |
//Motor A forward @ low speed | |
digitalWrite(motorrechts_A, LOW); //Establishes forward direction of Channel A | |
digitalWrite(motorrechts_B, LOW); //Disengage the Brake for Channel A | |
analogWrite(motorrechts_Speed, 70); //Spins the motor on Channel A at full speed | |
//Motor B backward @ low speed | |
digitalWrite(motorlinks_A, HIGH); //Establishes backward direction of Channel B | |
digitalWrite(motorlinks_B, LOW); //Disengage the Brake for Channel B | |
analogWrite(motorlinks_Speed, 110); //Spins the motor on Channel B at half speed | |
delay(500); | |
shinten.write(115); | |
delay(1000); | |
incomingByte = 8; | |
delay(1000); | |
break; | |
case 1: //nach rechts hinten | |
svlinks.write(70); | |
delay(50); | |
//Motor A forward @ low speed | |
digitalWrite(motorrechts_A, LOW); //Establishes forward direction of Channel A | |
digitalWrite(motorrechts_B, LOW); //Disengage the Brake for Channel A | |
analogWrite(motorrechts_Speed, 110); //Spins the motor on Channel A at full speed | |
//Motor B backward @ low speed | |
digitalWrite(motorlinks_A, HIGH); //Establishes backward direction of Channel B | |
digitalWrite(motorlinks_B, LOW); //Disengage the Brake for Channel B | |
analogWrite(motorlinks_Speed, 90); //Spins the motor on Channel B at half speed | |
delay(500); | |
shinten.write(115); | |
delay(1000); | |
incomingByte = 8; | |
delay(1000); | |
break; | |
case 2: //nach rechts vorne | |
svlinks.write(70); | |
delay(50); | |
//Motor A forward @ low speed | |
digitalWrite(motorrechts_A, LOW); //Establishes forward direction of Channel A | |
digitalWrite(motorrechts_B, LOW); //Disengage the Brake for Channel A | |
analogWrite(motorrechts_Speed, 70); //Spins the motor on Channel A at full speed | |
//Motor B backward @ low speed | |
digitalWrite(motorlinks_A, HIGH); //Establishes backward direction of Channel B | |
digitalWrite(motorlinks_B, LOW); //Disengage the Brake for Channel B | |
analogWrite(motorlinks_Speed, 55); //Spins the motor on Channel B at half speed | |
delay(500); | |
shinten.write(115); | |
delay(1000); | |
incomingByte = 8; | |
delay(1000); | |
break; | |
case 4: //nach links vorne | |
svrechts.write(100); | |
delay(50); | |
//Motor A forward @ low speed | |
digitalWrite(motorrechts_A, LOW); //Establishes forward direction of Channel A | |
digitalWrite(motorrechts_B, LOW); //Disengage the Brake for Channel A | |
analogWrite(motorrechts_Speed, 60); //Spins the motor on Channel A at full speed | |
//Motor B backward @ low speed | |
digitalWrite(motorlinks_A, HIGH); //Establishes backward direction of Channel B | |
digitalWrite(motorlinks_B, LOW); //Disengage the Brake for Channel B | |
analogWrite(motorlinks_Speed, 70); //Spins the motor on Channel B at half speed | |
delay(500); | |
shinten.write(115); | |
delay(1000); | |
incomingByte = 8; | |
delay(1000); | |
break; | |
default: | |
shinten.write(80); | |
svrechts.write(50); | |
svlinks.write(120); | |
analogWrite(motorrechts_Speed, 0); //Spins the motor on Channel A at full speed | |
analogWrite(motorlinks_Speed, 0); //Spins the motor on Channel B at half speed | |
digitalWrite(motorrechts_B, HIGH); //Engage the Brake for Motor Rechts | |
digitalWrite(motorlinks_B, HIGH); //Engage the Brake for Motor Links | |
delay(1000); | |
break; | |
ballda=1; | |
} | |
}else{ | |
shinten.write(135); | |
svrechts.write(50); | |
svlinks.write(120); | |
analogWrite(motorrechts_Speed, 0); //Spins the motor on Channel A at full speed | |
analogWrite(motorlinks_Speed, 0); //Spins the motor on Channel B at half speed | |
digitalWrite(motorrechts_B, HIGH); //Engage the Brake for Motor Rechts | |
digitalWrite(motorlinks_B, HIGH); //Engage the Brake for Motor Links | |
digitalWrite(ledshooter, LOW); | |
digitalWrite(ledtarget, LOW); | |
if(ballda==1){ | |
delay(1000); | |
ballda = 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment