Hi,
I'm trying to program the following:
I have a DC motor and 3 momentary swithes which are marking a position
when Switch 1 is pushed Motor starts and turns until Switch 2 turn momentary ON
Motor lowers the speed until Switch 3 turns ON then Motor direction changes and
we go back to Switch 2.
I tried with if/else but it doesn't work
I attached my "work", obvously I'm a neubie
regards
Mario
// constants won't change. They're used here to
// set pin numbers:
const int reedPin1 = 4; // the number of the pushbutton pin
const int reedPin2 = 7;
const int reedPin3 = 8;
const int startPin = 2; // the number of the pushbutton pin
const int motorPin = 11; // the number of the motor pin
const int ledPin = 13; // the number of the motor pin
const int dirPin = 12;
// variables will change:
int reed1State = 0; // variable for reading the reedSensor status
int reed2State = 0;
int reed3State = 0;
int startState = 0;
void setup() {
// initialize the motor pin as an output:
pinMode(motorPin, OUTPUT);
// initialize the direction pin as an output:
pinMode(dirPin, OUTPUT);
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(reedPin1, INPUT);
pinMode(reedPin2, INPUT);
pinMode(reedPin3, INPUT);
pinMode(startPin, INPUT);
}
void loop() {
int startState = digitalRead(startPin);
//reed1State = digitalRead(reedPin1);
int reed2State = digitalRead(reedPin2);
int reed3State = digitalRead(reedPin3);
if (startState == LOW && reed2State == LOW && reed3State == LOW){
analogWrite(motorPin, 0);
digitalWrite(dirPin, LOW);
delay(5);
} else {
if (startState == HIGH && reed2State == LOW && reed3State == LOW){
analogWrite(motorPin, 0);
digitalWrite(dirPin, LOW);
delay(5);
analogWrite(motorPin, 50);
delay(200);
} else {
if (startState == HIGH && reed2State == HIGH && reed3State == LOW){
analogWrite(motorPin, 0);
digitalWrite(dirPin, LOW);
delay(5);
analogWrite(motorPin, 100);
delay(200);
} else {
if (startState == HIGH && reed2State == LOW && reed3State == HIGH){
analogWrite(motorPin, 0);
digitalWrite(dirPin, HIGH);
delay(5);
analogWrite(motorPin, 100);
delay(200);
} else {
digitalWrite(ledPin, LOW);
}
}}}}