I've got this public art project deadline looming and trouble figuring out this code. If anyone could help me out I'd be incredibly grateful!!!
Basically I have a couple motors that watch for a button press which turns them on. They then watch for another button press to turn off BUT I'd like for them to also turn off if 5 seconds have passed and not need to wait for the second button press.
I've got everything working fine besides figuring out where/how to put in a millis code to do this.
Again, I REALLY appreciate any help on this!
int trigger = 2; ///coming from mother board
int spiral1 = 3; //spiral 1
int spiral2 = 4; //spiral 2
int micro1 = 9; //micro switch on spiral 1
int micro2 = 10; //micro switch on spiral 2
unsigned long startMillis;
unsigned long currentMillis;
const unsigned long period = 5000;
void setup() {
pinMode(trigger, INPUT);
pinMode(spiral1, OUTPUT);
pinMode(spiral2, OUTPUT);
pinMode(micro1, INPUT_PULLUP);
pinMode(micro2, INPUT_PULLUP);
}
void loop() {
///////spiral1 code starts////////
/////////////////////////////////
if (digitalRead(micro1)==1)
{
{
while (digitalRead(trigger)==0)
{
delay(10);
}
}
digitalWrite(spiral1, HIGH);
delay(2000); //lets micro switch 1 get a chance to release
if (digitalRead(micro1)==0)
{
{
while (digitalRead(micro1)==0)
{
delay(10);
//////// IF 5 SCEONDS HAS PASSED THOUGH DIGITALWRITE(SPIRAL1, LOW)///////
}
}
digitalWrite(spiral1, LOW);
}
}
///////spiral2 code starts////////
/////////////////////////////////
if (digitalRead(micro2)==1)
{
{
while (digitalRead(trigger)==0)
{
delay(10);
}
}
digitalWrite(spiral2, HIGH);
delay(2000); //lets micro switch 1 get a chance to release
if (digitalRead(micro2)==0)
{
while (digitalRead(micro2)==0)
{
delay(10);
}
}
digitalWrite(spiral2, LOW);
}
}