RE duration.
The duration is variable as the pot runs the dolly from 5mins to 4hours.
I was looking for a calculation that could tell me how long the track would run based on the pot reading.
So maybe this is sort of what id be needing help with
Number of Steps (full track length) calculated with pot reading = duration
So lets assume a number for steps in total at 160000 and a pot reading of 516 - how could I resolve this into hour mins and secs?
Here is my full sketch so far
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(10, 9, 8, 7, 6, 5);
/////// button //////////////////////////////////////
const int buttonPin = 12; // the number of the pushbutton pin
const int ledBTNPin = 11; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
/////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
#define DIR_PIN 2
#define STEP_PIN 3
#define switchPin 4
// show me steps and delay
int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
int fwdstepCount = 0; // number of steps the motor has taken forward
int revstepCount = 0; // number of steps the motor has taken forward
const int stepsPerRevolution = 1600;
int stepcount = 3200;
int spd;
int Scount = 0; // count seconds
int Mcount = 0; // count minutes
int Hcount =0; // count hours
int Dcount = 0; // count days
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
pinMode(DIR_PIN, OUTPUT);
pinMode(STEP_PIN, OUTPUT);
pinMode (switchPin, INPUT);
// Show me power on LED
pinMode(ledPin, OUTPUT);
}
void loop(){
// rotate();//will rotate 2 times, with Pot control
BTN();
}
void rotate(){
/// LED lights with 9volt power on
digitalWrite(ledPin, HIGH);
if (digitalRead(switchPin)){ //if the switch is HIGH, rotate clockwise
digitalWrite(DIR_PIN,HIGH);
lcd.setCursor(15, 0);
lcd.print("R");
}
else { // if the swtich is LOW, rotate counter clockiwise
digitalWrite(DIR_PIN,LOW);
lcd.setCursor(15, 0);
lcd.print("F");
}
//duration();
for(int i=0; i < 1600 * .0125; i++){
int usDelay = map(analogRead(A0), 10, 1000, 10, 7000);
usDelay = constrain(usDelay, 10, 7000);
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(usDelay);
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(usDelay);
spd=usDelay/10; // how do I conver this to hours mins and secs?
// need a step amount to calculate spd by steps = duration
}
}
void duration(){
int usDelay = map(analogRead(A0), 10, 1000, 10, 7000);
usDelay = constrain(usDelay, 10, 7000);
spd=usDelay/10;
lcd.setCursor(0,0); // sets cursor to 3rd line
lcd.print ("SPD:");
lcd.setCursor(5,0);
lcd.print(spd);
}
void BTN(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on: POT
digitalWrite(ledBTNPin, LOW);
// pot();
duration();
//rotate();
}
else {
// turn LED off: RAMP
digitalWrite(ledBTNPin, HIGH);
LCD();
rotate();//will rotate a 1/2 turn, with Pot control
// ramp();
// stepper.run();
}
}
void LCD(){
if (digitalRead(switchPin)){ //if the switch is HIGH, rotate clockwise
lcd.setCursor(0,0); // sets cursor to 3rd line
lcd.print ("SPD:");
lcd.setCursor(5,0);
lcd.print(spd);
// lcd.setCursor(15, 0);
// lcd.print("R");
lcd.setCursor(0, 1);
lcd.print("S>");
lcd.setCursor(2, 1);
lcd.print(stepsPerRevolution);
lcd.setCursor(8, 1);
lcd.print("A>");
lcd.setCursor(10, 1);
lcd.print("ON");
}
else { // if the swtich is LOW, rotate counter clockiwise
lcd.setCursor(0,0); // sets cursor to 3rd line
lcd.print ("SPD:");
lcd.setCursor(5,0);
lcd.print(spd);
// lcd.setCursor(15, 0);
// lcd.print("R");
lcd.setCursor(0, 1);
lcd.print("S>");
lcd.setCursor(2, 1);
lcd.print(stepsPerRevolution);
lcd.setCursor(8, 1);
lcd.print("A>");
lcd.setCursor(10, 1);
lcd.print("OFF");
}
}
As for this code, I am not sure why I have this. I had help with this. All I have deduced is that 1600 is steps per rev, .0125 is amout of rotation before driection chenge with the switch.
The idea of this code was to get the largest step range for fast and slow stepping
for(int i=0; i < 1600 * .0125; i++){
int usDelay = map(analogRead(A0), 10, 1000, 10, 7000);
usDelay = constrain(usDelay, 10, 7000);