why I wanted to know BlinkwithoutDelay is for my below mentioned project. The delay() is halting the system and didnot allow the button to respond.. But still I canot figured out how to solve it... Very disappointing.. Here is the code:
const int rightLed=12;
const int leftLed=11;
const int leftButton=8;
const int rightButton=9;
const int blinkerButton=10;
uint8_t brightness = 0; // how bright the LED is
uint8_t fadeAmount = 5;
byte counter = 0;
byte OldCounter = 0;
bool leftButtonState = 1;
bool rightButtonState = 1;
bool blinkerButtonState = 1;
void setup()
{
pinMode(leftLed,OUTPUT);
pinMode(rightLed,OUTPUT);
pinMode(leftButton,INPUT_PULLUP);
pinMode(rightButton,INPUT_PULLUP);
pinMode(blinkerButton,INPUT_PULLUP);
}
void loop()
{
OldCounter = counter;
switch (OldCounter)
{
case 1: Flasher1(); break;
case 2: Flasher2(); break;
case 3: Flasher3(); break;
case 4: Flasher4(); break;
case 5: Flasher5(); break;
case 6: Flasher6(); break;
case 7: Flasher7(); break;
case 8: Flasher8(); break;
case 9: Flasher9(); break;
case 10: Flasher10(); break;
case 11: Flasher11(); break;
case 12: LeftIndicator(); break;
case 13: RightIndicator(); break;
default: Flasher2();
}
//for leftbutton
leftButtonState=digitalRead(leftButton);
if (leftButtonState == 0)
{
counter = 12;
}
//for right button
rightButtonState=digitalRead(rightButton);
if (rightButtonState== 0)
{
counter = 13;
}
//for blinker button
blinkerButtonState=digitalRead(blinkerButton);
if (blinkerButtonState == 0) {
{
counter++;
if (counter > 11)counter = 1;
}
}
}
void Flasher1() {
analogWrite(PB0, brightness);
analogWrite(PB1, brightness);
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
if (brightness == 0) delay(2000) ;
}
// wait for 30 milliseconds to see the dimming effect
delay(50) ;
}
void Flasher2()
{
digitalWrite(leftLed, HIGH); digitalWrite(rightLed, HIGH); delay(500) ;
digitalWrite(leftLed, LOW); digitalWrite(rightLed, LOW); delay(500) ;
}
void Flasher3()
{
LeftLedFlash(); LeftLedFlash(); LeftLedFlash(); LeftLedFlash(); delay(200) ;
RightLedFlash(); RightLedFlash(); RightLedFlash(); RightLedFlash(); delay(200) ;
}
void Flasher4()
{
LeftLedFlash(); LeftLedFlash(); delay(1000) ;
RightLedFlash(); RightLedFlash(); delay(1000) ;
}
void Flasher5()
{
LeftLedFlash(); delay(80);
LeftLedFlash(); delay(1000) ;
RightLedFlash(); delay(80) ;
RightLedFlash(); delay(1000) ;
}
void Flasher6()
{
LeftLedFlash(); RightLedFlash(); delay(60) ;
LeftLedFlash(); RightLedFlash(); delay(500) ;
}
void Flasher7()
{
digitalWrite(rightLed, HIGH); digitalWrite(leftLed, HIGH); delay(50) ;
digitalWrite(rightLed, LOW); digitalWrite(leftLed, LOW); delay(50) ;
digitalWrite(rightLed, HIGH); digitalWrite(leftLed, HIGH); delay(50) ;
digitalWrite(rightLed, LOW); digitalWrite(leftLed, LOW); delay(500) ;
}
void Flasher8()
{
digitalWrite(rightLed, HIGH); delay(50) ;
digitalWrite(rightLed, LOW); digitalWrite(leftLed, HIGH); delay(100) ;
digitalWrite(leftLed, LOW); digitalWrite(rightLed, HIGH); delay(50) ;
digitalWrite(rightLed, LOW); digitalWrite(leftLed, HIGH); delay(100) ;
digitalWrite(leftLed, LOW); digitalWrite(rightLed, HIGH); delay(50) ;
digitalWrite(rightLed, LOW); delay(1500) ;
}
void Flasher9()
{
for ( uint8_t i = 0; i < 3; i++)
{
digitalWrite(leftLed, HIGH); delay(50) ; digitalWrite(leftLed, LOW); delay(50) ;
}
for (uint8_t i = 0; i < 3; i++)
{
digitalWrite(rightLed, HIGH); delay(50) ; digitalWrite(rightLed, LOW); delay(50) ;
}
}
void Flasher10()
{
digitalWrite(leftLed, HIGH); delay(50) ; digitalWrite(leftLed, LOW);
digitalWrite(rightLed, HIGH); delay(50) ; digitalWrite(rightLed, LOW);
delay(2000) ;
}
void Flasher11()
{
digitalWrite(leftLed, HIGH); digitalWrite(rightLed, HIGH); delay(50) ; digitalWrite(leftLed, LOW); digitalWrite(rightLed, LOW);
delay(3000) ;
}
void LeftLedFlash()
{
digitalWrite(leftLed, HIGH); delay(30) ; digitalWrite(leftLed, LOW); delay(30) ;
}
void RightLedFlash()
{
digitalWrite(rightLed, HIGH); delay(30) ;
digitalWrite(rightLed, LOW); delay(30) ;
}
void LeftIndicator()
{
digitalWrite(rightLed, LOW);
digitalWrite(leftLed, HIGH); delay(500) ;
digitalWrite(leftLed, LOW); delay(500) ;
}
void RightIndicator()
{
digitalWrite(leftLed, LOW);
digitalWrite(rightLed, HIGH); delay(500) ;
digitalWrite(rightLed, LOW); delay(500) ;
}