Motor rotation confusing.
Posted: Sat Mar 07, 2015 12:42 am
my coding was regarding about a rain sensor to active the rotation of motor with 2 limit switch connecting to same digital inout , but i facing the problem which 2 condition can interact both condition (if.....else). the motor start confuse , keep reverse and forward. plz someone help me solve this problem for me . i need end the first condition statement before proceed to next statement. Even thou i used while(1), it's didn't working.
- CODE: SELECT_ALL_CODE
int rainsensor=1;
int rainvalue=0;
int rain_sensitivity=800;
int buttonPin0 = 0;
int E1 = 6;
int M1 = 7;
void setup()
{
pinMode(buttonPin0,INPUT);
pinMode(M1, OUTPUT);
}
void loop()
{
buttonPin0 = digitalRead(2);
rainvalue = analogRead(rainsensor);
if (rainvalue < rain_sensitivity && buttonPin0 == HIGH) {
digitalWrite(M1,HIGH );
analogWrite(E1, 225);
delay(100); }
else if (rainvalue < rain_sensitivity && buttonPin0 == LOW) {
analogWrite(E1, 0);
delay(100);
}
// I want end the process above, to avoid interact next statement at below.
if (rainvalue > rain_sensitivity && buttonPin0 ==HIGH) {
digitalWrite(M1,LOW );
analogWrite(E1, 225);
delay(100); }
else if (rainvalue > rain_sensitivity && buttonPin0 == LOW) {
analogWrite(E1, 0);
delay(100);
}
}