Airsoft Sniper - Power Up light

Here is the code

 

const int buttonPin = 4;
int ledPins[] = {0,1,2,3};
int mode = 0;


void setup() {

for (int i = 0; i < sizeof(ledPins); i++)
{
pinMode(ledPins[i], OUTPUT);
}

pinMode(buttonPin, INPUT);

delay(20);

if(digitalRead(buttonPin) == HIGH)
{
mode = 1;
}
}

void loop() {
if(mode == 0)
{
while(digitalRead(buttonPin) == LOW){}
delay(1000);
if(digitalRead(buttonPin) == HIGH){
powerUp();

}
else{
forwardBackward(70);

delay(50);
}
}
else {
forwardOnly(200);
}
}


void powerUp(){
for(int i=500; i>=100; i=i - 100)
{
forwardOnly(i);
}
for(int i=20; i>=0; i--){ forwardOnly(50); }
for(int i=20; i>=0; i--){ forwardOnly(20); }
for(int i=10; i>=0; i--){ allOn(200); }
for(int i=20; i>=0; i--){ allOn(50); }
for(int i=45; i>=0; i--){ allOn(20); }
allOn(4000);
}


void forwardBackward(int Speed){
forwardOnly(Speed);
backwardOnly(Speed);
}

void backwardOnly(int Speed){

for (int i = 0; i < sizeof(ledPins); i++)
{
digitalWrite(ledPins[i], HIGH);

delay(Speed);

digitalWrite(ledPins[i], LOW);
}
delay(200);

}

void forwardOnly(int Speed){

for (int i = sizeof(ledPins)-1; i >= 0; i--)
{
digitalWrite(ledPins[i], HIGH);

delay(Speed);

digitalWrite(ledPins[i], LOW);
}
delay(200);

}

void allOn(int Speed){

for (int i = 0; i < sizeof(ledPins); i++)
{
digitalWrite(ledPins[i], HIGH);
}
delay(Speed);

for (int i = 0; i < sizeof(ledPins); i++)
{
digitalWrite(ledPins[i], LOW);
}

delay(Speed);
}

Posted on: Friday 13 January 2017