First off, just want to say I am really new to all this, please bare with me.
So what I want to do it have a motor turn on immediately when arduino starts, the motor would run for just under 60 sec, then a button is pushed to stop motor. Then a delay for a total of 60 sec including run time, so delay would be the difference between run time and 60 sec. My end goal it to have a wheel on a motor that I want to be for a clock, but getting motors to be precisely 1 rpm is had to find, so I will use either a motor or servo and control speed just under 1 minute and us a button on the wheel when it makes 1 rpm, then delay until 60 sec is up and repeat. Hope that clear, here is what I have tried. I found code and I am trying to modify it. The original code turning motor ona nd off with a button, so I added all the millis() code to try and create the timer.
Any help greatly appriciated
thanks
int buttonPin = 2;
boolean buttonState = LOW;
int motorPin = 6;
int motorEnabled = 0;
boolean previousButtonState = LOW;
int AMillis; //start of motor
int BMillis; //stop motor
int CMillis; //diff of A & B in millisec
int DMillis; //delay time
//This will run only one time.
void setup(){
pinMode(buttonPin,INPUT);
pinMode(motorPin, OUTPUT);
}
void loop(){
Serial.begin(9600);
//delay(100);
//unsigned long AMillis = millis();
//Serial.println();
//Serial.println(AMillis);
//Serial.println();
buttonState = digitalRead(buttonPin);
if(previousButtonState != buttonState && buttonState == HIGH)
{
motorEnabled = !motorEnabled;
}
if(motorEnabled == 0){
digitalWrite (motorPin,HIGH);
AMillis = millis();
Serial.println(AMillis);
}
else{
digitalWrite (motorPin,LOW);
BMillis = millis();
}
previousButtonState = buttonState;
CMillis = BMillis - AMillis;
DMillis = 60000 - CMillis;
delay(DMillis);
}