Greetings, Im having a play running a stepper motor from a potentiometer to control speed, and a switch to control direction. The code is designed to vary PWM frequency as the value of the pot changes. I have wired pins 9 and 8 to STEP and DIR on the board, along with GND to GND.
The direction change is working fine, however the pot is being unusual. The output values coming back from the serial.print are spot on what i would expect, however: at either end of the pot there is no movment at all, in the middle i get a constant speed. I dont get this at all.
Here is the code:
const int PotSignal = A0;
const int SwitchSignal = 0;
const int StepOut = 9;
const int Direction = 8;
int PotValue = 0;
int SwitchValue = 0;
int PulseSpeed = 0;
void setup() {
Serial.begin(9600);
pinMode (PotSignal, INPUT);
pinMode (SwitchSignal, INPUT);
pinMode (Direction, OUTPUT);
}
void loop() {
PotValue = analogRead(PotSignal);
SwitchValue = digitalRead(SwitchSignal);
if (SwitchValue == HIGH) {
digitalWrite (Direction, LOW);
} else {
digitalWrite (Direction, HIGH);
}
PulseSpeed = map(PotValue, 0, 1023, 0, 255);
analogWrite(StepOut, PulseSpeed);
Serial.println(PotValue, DEC);
Serial.println(SwitchValue, DEC);
Serial.println(PulseSpeed, DEC);
delay (10);
}
Anyone have any ideas why I'm only getting one pulse width from this thing?
Many thanks!