Hi everyone, I'm working on a project where i need to switch the delay with four variables with a pushbutton. (2ms,3ms,4ms,5ms)...can anyone guide how to do that? here is my code
int count = 0;
int newcount = 0;
void setup()
{
Serial.begin(9600);
pinMode(2,INPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,INPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
}
void loop()
{
if(digitalRead(9)==HIGH)
{
newcount=count+1;
if(newcount!=count)
{
Serial.println(newcount);
switch (newcount)
{
case 1: onepole();
digitalWrite(10,HIGH);
digitalWrite(11,LOW);
digitalWrite(12,LOW);
break;
case 2: twopole();
digitalWrite(11,HIGH);
digitalWrite(10,LOW);
digitalWrite(12,LOW);
break;
case 3: fourpole();
digitalWrite(12,HIGH);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
break;
default: digitalWrite(10,LOW);
digitalWrite(11,LOW);
digitalWrite(12,LOW);
newcount=0;
break;
}
count=newcount;
}
}
delay(100);
}
void onepole()
{
digitalWrite(7,LOW);
digitalWrite(8,LOW);
if(digitalRead(2)==HIGH)
{
delayMicroseconds(2000);
digitalWrite(3,HIGH);
if(digitalRead(3)==HIGH)
digitalWrite(7,HIGH);
else
digitalWrite(8,HIGH);
delay(3000);
}
else
digitalWrite(7,LOW);
digitalWrite(8,LOW);
}
void twopole()
{
digitalWrite(7,LOW);
digitalWrite(8,LOW);
if(digitalRead(2)==HIGH)
{
delayMicroseconds(2000);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
if((digitalRead(3)==HIGH) && (digitalRead(4)==HIGH))
digitalWrite(7,HIGH);
else
digitalWrite(8,HIGH);
delay(3000);
}
else
digitalWrite(7,LOW);
digitalWrite(8,LOW);
}
void fourpole()
{
digitalWrite(7,LOW);
digitalWrite(8,LOW);
if(digitalRead(2)==HIGH)
{
delayMicroseconds(2000);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
if((digitalRead(3)==HIGH) && (digitalRead(4)==HIGH) && (digitalRead(5)==HIGH) && (digitalRead(6)==HIGH))
digitalWrite(7,HIGH);
else
digitalWrite(8,HIGH);
delay(3000);
}
else
digitalWrite(7,LOW);
digitalWrite(8,LOW);
}