I have been using my Arduino to control motor polarity with a Cytron MD-10 motor driver shield, and I had it working.
Then when I came back to work it seemed as though the digital read pins were not differentiating between high and low voltage and one of the lights was powered on continuously.
The outputs function as set up with a continuous supply of measured 4.84 volts and then the switch is closed the voltage drops to 0 and the corresponding loop should be entered. Is my board fried?
Anything I should try?
const int outSwitch = 13;
const int inSwitch = 12;
const int pinPWM = 3;
const int pinDir = 2;
int lightOne = 11;
int lightTwo = 10;
static int Dir = 1;
static int cycleCounter = 0;
void setup() {
// Set Pin Out/Inputs:
pinMode(pinPWM, OUTPUT);
pinMode(pinDir, OUTPUT);
pinMode(outSwitch, INPUT);
pinMode(inSwitch, INPUT);
pinMode(lightOne, OUTPUT);
pinMode(lightTwo, OUTPUT);
analogWrite(pinPWM, LOW);
}
void loop() {
// Both read a low input value from the switch and then makes
// direction the opposite causing it to travel backwards:
if(digitalRead(inSwitch == LOW)){
analogWrite(pinPWM, HIGH);
digitalWrite(pinDir, Dir);
digitalWrite(lightOne, LOW);
digitalWrite(lightTwo, HIGH);
}
else if(digitalRead(outSwitch == LOW)){
analogWrite(pinPWM, HIGH);
digitalWrite(pinDir, -Dir);
digitalWrite(lightOne, LOW);
digitalWrite(lightTwo, HIGH);
}
}
if
andelse if
conditions, brackets are bit wrong. They should beif(digitalRead(inSwitch) == LOW)
andelse if(digitalRead(outSwitch) == LOW)
– svtag