LED PATTERN SELECTOR

Push button selector

#include <EEPROM.h>
#define BUTTON_PIN 2 //harus di pin 2
volatile byte ledState = LOW;
byte sta;
int buttonPushCounter;

//deklarasi pola no.0-3
const int numLED = 14;
const int pinLED[numLED] = {3,4,5,6,7,8,9,10,11,12,13,14,15,16};

//deklarasi pola no.4-9
#define LED_PIN1 3
#define LED_PIN2 4
#define LED_PIN3 5
#define LED_PIN4 6
#define LED_PIN5 7
#define LED_PIN6 8
#define LED_PIN7 9
#define LED_PIN8 10
#define LED_PIN9 11
#define LED_PIN10 12
#define LED_PIN11 13
#define LED_PIN12 14
#define LED_PIN13 15
#define LED_PIN14 16

void setup() {
Serial.begin(9600);
//===setup pola no.0-3
for(int i=0; i<14; i++){
pinMode(pinLED[i], OUTPUT);
}
//===setup pola no.4-9
pinMode(LED_PIN1, OUTPUT);
pinMode(LED_PIN2, OUTPUT);
pinMode(LED_PIN3, OUTPUT);
pinMode(LED_PIN4, OUTPUT);
pinMode(LED_PIN5, OUTPUT);
pinMode(LED_PIN6, OUTPUT);
pinMode(LED_PIN7, OUTPUT);
pinMode(LED_PIN8, OUTPUT);
pinMode(LED_PIN9, OUTPUT);
pinMode(LED_PIN10, OUTPUT);
pinMode(LED_PIN11, OUTPUT);
pinMode(LED_PIN12, OUTPUT);
pinMode(LED_PIN13, OUTPUT);
pinMode(LED_PIN14, OUTPUT);

pinMode(BUTTON_PIN, INPUT);
attachInterrupt(0, blinkLed, CHANGE);
}
unsigned long last = millis();
int on = 0;

void loop() {
sta = EEPROM.read(2);
Serial.println(sta);
if(sta==0){// pilihan pola no.0
for(int i=0; i<15; i++){
digitalWrite(pinLED[i], LOW);
}
delay(100);
for(int i=0; i<15; i++){
digitalWrite(pinLED[i], HIGH);
delay(100);
}
}
if(sta==1){//pilihan pola no.1
for(int i=0; i<13; i++){
digitalWrite(pinLED[i], HIGH);
delay(100);
digitalWrite(pinLED[i], LOW);
}
for(int i=13; i>0; i–){
digitalWrite(pinLED[i], HIGH);
delay(100);
digitalWrite(pinLED[i], LOW);
}
}

if(sta==2){//pilihan pola no.2
for(int i=0; i<14; i++){
digitalWrite(pinLED[i], LOW);
}
delay(100);
// Hidupkan semua LED bertahap dg jeda 1 detik
for(int i=0; i<14; i++){
digitalWrite(pinLED[i], HIGH);
delay(100);
}
for(int i=13; i>0; i–){
digitalWrite(pinLED[i], LOW);
delay(100);
}
}
if(sta==3){//pilihan pola no.3
for(int i=0; i<14; i++){
digitalWrite(pinLED[i], HIGH);
}
delay(100);
for(int i=0; i<14; i++){
digitalWrite(pinLED[i], LOW);
delay(100);
}
for(int i=14; i>0; i–){
digitalWrite(pinLED[i], HIGH);
delay(100);
}

for(int i=0; i<14; i++){
digitalWrite(pinLED[i], LOW);
}
delay(100);
for(int i=0; i<14; i++){
digitalWrite(pinLED[i], HIGH);
delay(100);
}
for(int i=13; i>0; i–){
digitalWrite(pinLED[i], LOW);
delay(100);
}
}
if(sta==4){//pilihan pola no.4
digitalWrite(LED_PIN1, LOW);
digitalWrite(LED_PIN2, LOW);
digitalWrite(LED_PIN3, LOW);
digitalWrite(LED_PIN4, LOW);
digitalWrite(LED_PIN5, LOW);
digitalWrite(LED_PIN6, LOW);
digitalWrite(LED_PIN7, LOW);
digitalWrite(LED_PIN8, LOW);
digitalWrite(LED_PIN9, LOW);
digitalWrite(LED_PIN10, LOW);
digitalWrite(LED_PIN11, LOW);
digitalWrite(LED_PIN12, LOW);
digitalWrite(LED_PIN13, LOW);
digitalWrite(LED_PIN14, LOW);
delay(100);
digitalWrite(LED_PIN1, HIGH);
delay(100);
digitalWrite(LED_PIN2, HIGH);
delay(100);
digitalWrite(LED_PIN3, HIGH);
delay(100);
digitalWrite(LED_PIN4, HIGH);
delay(100);
digitalWrite(LED_PIN5, HIGH);
delay(100);
digitalWrite(LED_PIN6, HIGH);
delay(100);
digitalWrite(LED_PIN7, HIGH);
delay(100);
digitalWrite(LED_PIN8, HIGH);
delay(100);
digitalWrite(LED_PIN9, HIGH);
delay(100);
digitalWrite(LED_PIN10, HIGH);
delay(100);
digitalWrite(LED_PIN11, HIGH);
delay(100);
digitalWrite(LED_PIN12, HIGH);
delay(100);
digitalWrite(LED_PIN13, HIGH);
delay(100);
digitalWrite(LED_PIN14, HIGH);
delay(100);
}
if(sta==5){//pilihan pola no.5
digitalWrite(LED_PIN1, HIGH);
digitalWrite(LED_PIN2, HIGH);
digitalWrite(LED_PIN3, HIGH);
digitalWrite(LED_PIN4, HIGH);
digitalWrite(LED_PIN5, HIGH);
digitalWrite(LED_PIN6, HIGH);
digitalWrite(LED_PIN7, HIGH);
digitalWrite(LED_PIN8, HIGH);
digitalWrite(LED_PIN9, HIGH);
digitalWrite(LED_PIN10, HIGH);
digitalWrite(LED_PIN11, HIGH);
digitalWrite(LED_PIN12, HIGH);
digitalWrite(LED_PIN13, HIGH);
digitalWrite(LED_PIN14, HIGH);
delay(1000);
digitalWrite(LED_PIN1, LOW);
digitalWrite(LED_PIN2, LOW);
digitalWrite(LED_PIN3, LOW);
digitalWrite(LED_PIN4, LOW);
digitalWrite(LED_PIN5, LOW);
digitalWrite(LED_PIN6, LOW);
digitalWrite(LED_PIN7, LOW);
digitalWrite(LED_PIN8, LOW);
digitalWrite(LED_PIN9, LOW);
digitalWrite(LED_PIN10, LOW);
digitalWrite(LED_PIN11, LOW);
digitalWrite(LED_PIN12, LOW);
digitalWrite(LED_PIN13, LOW);
digitalWrite(LED_PIN14, LOW);
delay(1000);
}
if(sta==6){//pilihan pola no.6
digitalWrite(LED_PIN1, LOW);
digitalWrite(LED_PIN2, LOW);
digitalWrite(LED_PIN3, LOW);
digitalWrite(LED_PIN4, LOW);
digitalWrite(LED_PIN5, LOW);
digitalWrite(LED_PIN6, LOW);
digitalWrite(LED_PIN7, LOW);
digitalWrite(LED_PIN8, LOW);
digitalWrite(LED_PIN9, LOW);
digitalWrite(LED_PIN10, LOW);
digitalWrite(LED_PIN11, LOW);
digitalWrite(LED_PIN12, LOW);
digitalWrite(LED_PIN13, LOW);
digitalWrite(LED_PIN14, LOW);
delay(100);
digitalWrite(LED_PIN1, HIGH);
digitalWrite(LED_PIN14, HIGH);
delay(100);
digitalWrite(LED_PIN2, HIGH);
digitalWrite(LED_PIN13, HIGH);
delay(100);
digitalWrite(LED_PIN3, HIGH);
digitalWrite(LED_PIN12, HIGH);
delay(100);
digitalWrite(LED_PIN4, HIGH);
digitalWrite(LED_PIN11, HIGH);
delay(100);
digitalWrite(LED_PIN5, HIGH);
digitalWrite(LED_PIN10, HIGH);
delay(100);
digitalWrite(LED_PIN6, HIGH);
digitalWrite(LED_PIN9, HIGH);
delay(100);
digitalWrite(LED_PIN7, HIGH);
digitalWrite(LED_PIN8, HIGH);
delay(100);
digitalWrite(LED_PIN9, HIGH);
delay(100);
}
if(sta==7){//pilihan pola no.7
digitalWrite(LED_PIN1, HIGH);
digitalWrite(LED_PIN2, HIGH);
digitalWrite(LED_PIN3, HIGH);
digitalWrite(LED_PIN4, HIGH);
digitalWrite(LED_PIN5, HIGH);
digitalWrite(LED_PIN6, HIGH);
digitalWrite(LED_PIN7, HIGH);
digitalWrite(LED_PIN8, HIGH);
digitalWrite(LED_PIN9, HIGH);
digitalWrite(LED_PIN10, HIGH);
digitalWrite(LED_PIN11, HIGH);
digitalWrite(LED_PIN12, HIGH);
digitalWrite(LED_PIN13, HIGH);
digitalWrite(LED_PIN14, HIGH);
delay(100);
digitalWrite(LED_PIN1, LOW);
digitalWrite(LED_PIN14, LOW);
delay(100);
digitalWrite(LED_PIN2, LOW);
digitalWrite(LED_PIN13, LOW);
delay(100);
digitalWrite(LED_PIN3, LOW);
digitalWrite(LED_PIN12, LOW);
delay(100);
digitalWrite(LED_PIN4, LOW);
digitalWrite(LED_PIN11, LOW);
delay(100);
digitalWrite(LED_PIN5, LOW);
digitalWrite(LED_PIN10, LOW);
delay(100);
digitalWrite(LED_PIN6, LOW);
digitalWrite(LED_PIN9, LOW);
delay(100);
digitalWrite(LED_PIN7, LOW);
digitalWrite(LED_PIN8, LOW);
delay(100);
digitalWrite(LED_PIN9, LOW);
delay(100);
}
if(sta==8){//pilihan pola no.8
digitalWrite(LED_PIN1, LOW);
digitalWrite(LED_PIN2, LOW);
digitalWrite(LED_PIN3, LOW);
digitalWrite(LED_PIN4, LOW);
digitalWrite(LED_PIN5, LOW);
digitalWrite(LED_PIN6, LOW);
digitalWrite(LED_PIN7, LOW);
digitalWrite(LED_PIN8, LOW);
digitalWrite(LED_PIN9, LOW);
digitalWrite(LED_PIN10, LOW);
digitalWrite(LED_PIN11, LOW);
digitalWrite(LED_PIN12, LOW);
digitalWrite(LED_PIN13, LOW);
digitalWrite(LED_PIN14, LOW);
delay(100);
digitalWrite(LED_PIN1, HIGH);
digitalWrite(LED_PIN14, HIGH);
delay(100);
digitalWrite(LED_PIN2, HIGH);
digitalWrite(LED_PIN13, HIGH);
delay(100);
digitalWrite(LED_PIN3, HIGH);
digitalWrite(LED_PIN12, HIGH);
delay(100);
digitalWrite(LED_PIN4, HIGH);
digitalWrite(LED_PIN11, HIGH);
delay(100);
digitalWrite(LED_PIN5, HIGH);
digitalWrite(LED_PIN10, HIGH);
delay(100);
digitalWrite(LED_PIN6, HIGH);
digitalWrite(LED_PIN9, HIGH);
delay(100);
digitalWrite(LED_PIN7, HIGH);
digitalWrite(LED_PIN8, HIGH);
delay(100);
digitalWrite(LED_PIN9, HIGH);
delay(100);

digitalWrite(LED_PIN1, HIGH);
digitalWrite(LED_PIN2, HIGH);
digitalWrite(LED_PIN3, HIGH);
digitalWrite(LED_PIN4, HIGH);
digitalWrite(LED_PIN5, HIGH);
digitalWrite(LED_PIN6, HIGH);
digitalWrite(LED_PIN7, HIGH);
digitalWrite(LED_PIN8, HIGH);
digitalWrite(LED_PIN9, HIGH);
digitalWrite(LED_PIN10, HIGH);
digitalWrite(LED_PIN11, HIGH);
digitalWrite(LED_PIN12, HIGH);
digitalWrite(LED_PIN13, HIGH);
digitalWrite(LED_PIN14, HIGH);
delay(100);
digitalWrite(LED_PIN1, LOW);
digitalWrite(LED_PIN14, LOW);
delay(100);
digitalWrite(LED_PIN2, LOW);
digitalWrite(LED_PIN13, LOW);
delay(100);
digitalWrite(LED_PIN3, LOW);
digitalWrite(LED_PIN12, LOW);
delay(100);
digitalWrite(LED_PIN4, LOW);
digitalWrite(LED_PIN11, LOW);
delay(100);
digitalWrite(LED_PIN5, LOW);
digitalWrite(LED_PIN10, LOW);
delay(100);
digitalWrite(LED_PIN6, LOW);
digitalWrite(LED_PIN9, LOW);
delay(100);
digitalWrite(LED_PIN7, LOW);
digitalWrite(LED_PIN8, LOW);
delay(100);
digitalWrite(LED_PIN9, LOW);
delay(100);
}
if(sta==9){//pilihan pola no.9
digitalWrite(LED_PIN1, LOW);
digitalWrite(LED_PIN2, LOW);
digitalWrite(LED_PIN3, LOW);
digitalWrite(LED_PIN4, LOW);
digitalWrite(LED_PIN5, LOW);
digitalWrite(LED_PIN6, LOW);
digitalWrite(LED_PIN7, LOW);
digitalWrite(LED_PIN8, LOW);
digitalWrite(LED_PIN9, LOW);
digitalWrite(LED_PIN10, LOW);
digitalWrite(LED_PIN11, LOW);
digitalWrite(LED_PIN12, LOW);
digitalWrite(LED_PIN13, LOW);
digitalWrite(LED_PIN14, LOW);
delay(100);
digitalWrite(LED_PIN1, HIGH);
digitalWrite(LED_PIN14, HIGH);
delay(100);
digitalWrite(LED_PIN2, HIGH);
digitalWrite(LED_PIN13, HIGH);
delay(100);
digitalWrite(LED_PIN3, HIGH);
digitalWrite(LED_PIN12, HIGH);
delay(100);
digitalWrite(LED_PIN4, HIGH);
digitalWrite(LED_PIN11, HIGH);
delay(100);
digitalWrite(LED_PIN5, HIGH);
digitalWrite(LED_PIN10, HIGH);
delay(100);
digitalWrite(LED_PIN6, HIGH);
digitalWrite(LED_PIN9, HIGH);
delay(100);
digitalWrite(LED_PIN7, HIGH);
digitalWrite(LED_PIN8, HIGH);
delay(100);
digitalWrite(LED_PIN9, HIGH);
delay(100);

digitalWrite(LED_PIN1, HIGH);
digitalWrite(LED_PIN2, HIGH);
digitalWrite(LED_PIN3, HIGH);
digitalWrite(LED_PIN4, HIGH);
digitalWrite(LED_PIN5, HIGH);
digitalWrite(LED_PIN6, HIGH);
digitalWrite(LED_PIN7, HIGH);
digitalWrite(LED_PIN8, HIGH);
digitalWrite(LED_PIN9, HIGH);
digitalWrite(LED_PIN10, HIGH);
digitalWrite(LED_PIN11, HIGH);
digitalWrite(LED_PIN12, HIGH);
digitalWrite(LED_PIN13, HIGH);
digitalWrite(LED_PIN14, HIGH);
delay(100);
digitalWrite(LED_PIN1, LOW);
digitalWrite(LED_PIN14, LOW);
delay(100);
digitalWrite(LED_PIN2, LOW);
digitalWrite(LED_PIN13, LOW);
delay(100);
digitalWrite(LED_PIN3, LOW);
digitalWrite(LED_PIN12, LOW);
delay(100);
digitalWrite(LED_PIN4, LOW);
digitalWrite(LED_PIN11, LOW);
delay(100);
digitalWrite(LED_PIN5, LOW);
digitalWrite(LED_PIN10, LOW);
delay(100);
digitalWrite(LED_PIN6, LOW);
digitalWrite(LED_PIN9, LOW);
delay(100);
digitalWrite(LED_PIN7, LOW);
digitalWrite(LED_PIN8, LOW);
delay(100);
digitalWrite(LED_PIN9, LOW);
delay(100);

digitalWrite(LED_PIN1, HIGH);
digitalWrite(LED_PIN14, HIGH);
delay(100);
digitalWrite(LED_PIN1, LOW);
digitalWrite(LED_PIN14, LOW);
digitalWrite(LED_PIN2, HIGH);
digitalWrite(LED_PIN13, HIGH);
delay(100);
digitalWrite(LED_PIN2, LOW);
digitalWrite(LED_PIN13, LOW);
digitalWrite(LED_PIN3, HIGH);
digitalWrite(LED_PIN12, HIGH);
delay(100);
digitalWrite(LED_PIN3, LOW);
digitalWrite(LED_PIN12, LOW);
digitalWrite(LED_PIN4, HIGH);
digitalWrite(LED_PIN11, HIGH);
delay(100);
digitalWrite(LED_PIN4, LOW);
digitalWrite(LED_PIN11, LOW);
digitalWrite(LED_PIN5, HIGH);
digitalWrite(LED_PIN10, HIGH);
delay(100);
digitalWrite(LED_PIN5, LOW);
digitalWrite(LED_PIN10, LOW);
digitalWrite(LED_PIN6, HIGH);
digitalWrite(LED_PIN9, HIGH);
delay(100);
digitalWrite(LED_PIN6, LOW);
digitalWrite(LED_PIN9, LOW);
digitalWrite(LED_PIN7, HIGH);
digitalWrite(LED_PIN8, HIGH);
delay(100);
digitalWrite(LED_PIN7, LOW);
digitalWrite(LED_PIN8, LOW);
digitalWrite(LED_PIN9, HIGH);
delay(100);
}
}

void blinkLed() {
if (millis() – last > 250) {
buttonPushCounter++;

if (buttonPushCounter % 10 == 0) {
EEPROM.write(2, 0);
}
if (buttonPushCounter % 10 == 1) {
EEPROM.write(2, 1);
}
if (buttonPushCounter % 10 == 2){
EEPROM.write(2, 2);
}
if (buttonPushCounter % 10 == 3) {
EEPROM.write(2, 3);
}
if (buttonPushCounter % 10 == 4) {
EEPROM.write(2, 4);
}
if (buttonPushCounter % 10 == 5) {
EEPROM.write(2, 5);
}
if (buttonPushCounter % 10 == 6) {
EEPROM.write(2, 6);
}
if (buttonPushCounter % 10 == 7){
EEPROM.write(2, 7);
}
if (buttonPushCounter % 10 == 8) {
EEPROM.write(2, 8);
}
if (buttonPushCounter % 10 == 9) {
EEPROM.write(2, 9);
}
}
last = millis();
}