I need help setting up 5 positions and loop it 3 times, at every position the servo has to fire once.
I use 2 potentiometers and 2 DC 24V motors.
Kind regards.
I/O
volatile unsigned int potentiometer_value = 0;
volatile unsigned int potentiometer_value2 = 0;
#include <Servo.h>
Servo myservo;
const char TAB = '\t';
int pos3 = 0;
int pos4 = 180;
int MotorCW = 7;
int MotorCCW = 8;
int MotorUP = 10;
int MotorDOWN = 11;
int potentiometer_pin = A2;
int potentiometer_pin2 = A5;
int pulse_value = 1;
int pulse_value2 = 0;
int Start_button= 4;
int Stop_button= 5;
int Reset_button= 6;
void setup() {
Serial.begin (9600);
pinMode(MotorCW, OUTPUT);
pinMode(MotorCCW, OUTPUT);
pinMode(MotorUP, OUTPUT);
pinMode(MotorDOWN, OUTPUT);
pinMode(Start_button, INPUT_PULLUP);
pinMode(Reset_button, INPUT_PULLUP);
myservo.attach(9);
}
Relays
void setPositionX(int pos1){
if(pos1 <= potentiometer_value2){
digitalWrite(MotorCW, HIGH);
digitalWrite(MotorCCW, LOW);
//Serial.println("Turn Motor Clockwise");
} else if (pos1 >= potentiometer_value2){
digitalWrite(MotorCCW, HIGH);
digitalWrite(MotorCW, LOW);
//Serial.println("Turn Motor Counter Clockwise");
} else {
return;
}
while (pos1 == potentiometer_value2){
digitalWrite(MotorCW, LOW);
digitalWrite(MotorCCW, LOW);
delay(2000);
}
{
return;
}
}
void setPositionY(int pos2){
if(pos2 <= potentiometer_value){
digitalWrite(MotorUP, HIGH);
digitalWrite(MotorDOWN, LOW);
//Serial.println("Turn Motor Up");
} else if (pos2 >= potentiometer_value){
digitalWrite(MotorUP, LOW);
digitalWrite(MotorDOWN, HIGH);
//Serial.println("Turn Motor Down");
} else {
return;
}
while (pos2 == potentiometer_value){
digitalWrite(MotorUP, LOW);
digitalWrite(MotorDOWN, LOW);
}
{
return;
}
}
Loop
void loop()
{
{
Serial.println (potentiometer_value2);
Serial.print (TAB);
Serial.print (TAB);
Serial.print (TAB);
Serial.print (TAB);
Serial.println (potentiometer_value);
}
{
potentiometer_value = analogRead(potentiometer_pin);
potentiometer_value2 = analogRead(potentiometer_pin2);
pulse_value = potentiometer_value ;
pulse_value2 = potentiometer_value2;
}
else if (potentiometer_value2 == 632)
{
setPositionY(580);
setPositionX(600);
Serial.println ("Start");
}
else if(potentiometer_value2 == 580 && potentiometer_value == 600){
setPositionX(400);
setPositionY(550);
//}
}}
paintball.ino (736 Bytes)
Relay.ino (1.15 KB)
Void_Loop.ino (697 Bytes)