Hi everyone.
I am working on a final project for a control systems class in college. I've had some programming experience, but am fairly new to arduino. For this part of my project, I am using a potentiometer to control a stepper motor. The analog values from the pot are converted to a value between 0 and 1023.
What I want:
-To keep track of the pot's last location by writing the value to EEPROM at the end of my code.
-When the program loops to the beginning, i read the pot's value and subtract it's last location from the value I stored in EEPROM.
-Take the absolute value of the difference, and use the difference in a while loop to control the number of steps.
(This makes sense to me, but if my logic is off, please let me know!)
MY PROBLEM:
-My program compiles fine, however, when I test it with the hardware...nothing happens!!
Any and all help is appreciated!!
MY CODE
int setpoint = A0; // Set point potentiometer.
int setpointValue = 0; // Variable for set point potenetiometer value.
int Step = 8; //Pin 8 is step
int diff; //The difference between the set point and value in memory.
#include <EEPROM.h>
int storedValue = 0;
int addr = 0;
void setup() {
pinMode(Step, OUTPUT);
}
void loop() {
setpointValue = analogRead(setpoint); // Read values from setpoint potentiometer.
storedValue = EEPROM.read(addr); // Read addr in EEPROM and put value in storedValue.
storedValue *4; // Multiply by 4
diff = setpointValue - storedValue; // Take difference.
abs(diff); // Take absoulute value of the difference.
if (diff > 0) {
while(diff>0);
{
digitalWrite(Step, HIGH);
delay(500);
digitalWrite(Step, LOW);
delay(500);
diff--;
}
}
else;
{ //Do nothing if difference = 0.
}
storedValue = analogRead(setpoint) / 4; //Read the setpoint potentiometer
EEPROM.write(addr, storedValue); //Store this value in EEPROM.
}