ATMega 328p – Power LEDs

Code:

const int  buttonPin = 7;
const int l1 = 13;
const int l2 = 12;
const int l3 = 11;
const int l4 = 10;
const int l5 = 9;
const int l6 = 6;
const int  buttonPin2 = 8;

int buttonPushCounter = 0;
int buttonState = 0;
int lastButtonState = 0;

int buttonPushCounter2 = 0;
int buttonState2 = 0;
int lastButtonState2 = 0;

int count = 0;
int timer = 30;
int pinArray[] = {
13, 12, 11, 10, 9, 6};

void setup() {

pinMode(buttonPin, INPUT);
pinMode(l1, OUTPUT);
pinMode(l2, OUTPUT);
pinMode(l3, OUTPUT);
pinMode(l4, OUTPUT);
pinMode(l5, OUTPUT);
pinMode(l6, OUTPUT);

for (count=0;count<6;count++) {
pinMode(pinArray[count], OUTPUT);
}

}

void loop() {

buttonState = digitalRead(buttonPin);
if (buttonState != lastButtonState) {
if (buttonState == HIGH) {
buttonPushCounter++;
}
else {
}
}

buttonState2 = digitalRead(buttonPin2);
if (buttonState2 != lastButtonState2) {
if (buttonState2 == HIGH) {
buttonPushCounter2++;
}
else {
}
}

lastButtonState = buttonState;
lastButtonState2 = buttonState2;

if (buttonPushCounter % 2 == 0) {
digitalWrite(l1, HIGH);
digitalWrite(l2, HIGH);
digitalWrite(l3, HIGH);
digitalWrite(l4, HIGH);
digitalWrite(l5, HIGH);
digitalWrite(l6, HIGH);
}
else {
digitalWrite(l1, LOW);
digitalWrite(l2, LOW);
digitalWrite(l3, LOW);
digitalWrite(l4, LOW);
digitalWrite(l5, LOW);
digitalWrite(l6, LOW);
}

if (buttonPushCounter2 % 2 == 0) {
for (count=0;count<5;count++) {
digitalWrite(pinArray[count], HIGH);
delay(timer);
digitalWrite(pinArray[count + 1], HIGH);
delay(timer);
digitalWrite(pinArray[count], LOW);
delay(timer*2);
}
for (count=5;count>0;count–) {
digitalWrite(pinArray[count], HIGH);
delay(timer);
digitalWrite(pinArray[count – 1], HIGH);
delay(timer);
digitalWrite(pinArray[count], LOW);
delay(timer*2);
}
}
else {
for (count=0;count<5;count++) {
digitalWrite(pinArray[count], LOW);
}
}

}

http://youtu.be/ebZC5ZLeTLs

Tags:
Fork me on GitHub