/* LED Binary Counter - 4-bit*/
/*============================== CONFIGURAZIONI ==============================*/
// PINs
#define BIT_0_PIN 2
#define BIT_1_PIN 4
#define BIT_2_PIN 6
#define BIT_3_PIN 8
// DELAY
#define DELAY 1500
/*============================================================================*/
/*============================ VARIABILI GLOBALI =============================*/
int nibble[4] = {BIT_0_PIN, BIT_1_PIN, BIT_2_PIN, BIT_3_PIN};
// Counter
int i;
/*============================================================================*/
/*=========================== FUNZIONI PRINCIPALI ============================*/
void setup() {
for(i=0; i<4; i++) {
pinMode(nibble[i], OUTPUT);
}
}
void loop() {
binary0();
binary1();
binary2();
binary3();
binary4();
binary5();
binary6();
binary7();
binary8();
binary9();
binaryA();
binaryB();
binaryC();
binaryD();
binaryE();
binaryF();
}
/*============================================================================*/
/*============================== ALTRE FUNZIONI ==============================*/
void binary0() {
// 0000 (0x0)
digitalWrite(BIT_0_PIN, LOW);
digitalWrite(BIT_1_PIN, LOW);
digitalWrite(BIT_2_PIN, LOW);
digitalWrite(BIT_3_PIN, LOW);
delay(DELAY);
}
void binary1() {
// 0001 (0x1)
digitalWrite(BIT_0_PIN, HIGH);
digitalWrite(BIT_1_PIN, LOW);
digitalWrite(BIT_2_PIN, LOW);
digitalWrite(BIT_3_PIN, LOW);
delay(DELAY);
}
void binary2() {
// 0010 (0x2)
digitalWrite(BIT_0_PIN, LOW);
digitalWrite(BIT_1_PIN, HIGH);
digitalWrite(BIT_2_PIN, LOW);
digitalWrite(BIT_3_PIN, LOW);
delay(DELAY);
}
void binary3() {
// 0011 (0x3)
digitalWrite(BIT_0_PIN, HIGH);
digitalWrite(BIT_1_PIN, HIGH);
digitalWrite(BIT_2_PIN, LOW);
digitalWrite(BIT_3_PIN, LOW);
delay(DELAY);
}
void binary4() {
// 0100 (0x4)
digitalWrite(BIT_0_PIN, LOW);
digitalWrite(BIT_1_PIN, LOW);
digitalWrite(BIT_2_PIN, HIGH);
digitalWrite(BIT_3_PIN, LOW);
delay(DELAY);
}
void binary5() {
// 0101 (0x5)
digitalWrite(BIT_0_PIN, HIGH);
digitalWrite(BIT_1_PIN, LOW);
digitalWrite(BIT_2_PIN, HIGH);
digitalWrite(BIT_3_PIN, LOW);
delay(DELAY);
}
void binary6() {
// 0110 (0x6)
digitalWrite(BIT_0_PIN, LOW);
digitalWrite(BIT_1_PIN, HIGH);
digitalWrite(BIT_2_PIN, HIGH);
digitalWrite(BIT_3_PIN, LOW);
delay(DELAY);
}
void binary7() {
// 0111 (0x7)
digitalWrite(BIT_0_PIN, HIGH);
digitalWrite(BIT_1_PIN, HIGH);
digitalWrite(BIT_2_PIN, HIGH);
digitalWrite(BIT_3_PIN, LOW);
delay(DELAY);
}
void binary8() {
// 1000 (0x8)
digitalWrite(BIT_0_PIN, LOW);
digitalWrite(BIT_1_PIN, LOW);
digitalWrite(BIT_2_PIN, LOW);
digitalWrite(BIT_3_PIN, HIGH);
delay(DELAY);
}
void binary9() {
// 1001 (0x9)
digitalWrite(BIT_0_PIN, HIGH);
digitalWrite(BIT_1_PIN, LOW);
digitalWrite(BIT_2_PIN, LOW);
digitalWrite(BIT_3_PIN, HIGH);
delay(DELAY);
}
void binaryA() {
// 1010 (0xA)
digitalWrite(BIT_0_PIN, LOW);
digitalWrite(BIT_1_PIN, HIGH);
digitalWrite(BIT_2_PIN, LOW);
digitalWrite(BIT_3_PIN, HIGH);
delay(DELAY);
}
void binaryB() {
// 1011 (0xB)
digitalWrite(BIT_0_PIN, HIGH);
digitalWrite(BIT_1_PIN, HIGH);
digitalWrite(BIT_2_PIN, LOW);
digitalWrite(BIT_3_PIN, HIGH);
delay(DELAY);
}
void binaryC() {
// 1100 (0xC)
digitalWrite(BIT_0_PIN, LOW);
digitalWrite(BIT_1_PIN, LOW);
digitalWrite(BIT_2_PIN, HIGH);
digitalWrite(BIT_3_PIN, HIGH);
delay(DELAY);
}
void binaryD() {
// 1101 (0xD)
digitalWrite(BIT_0_PIN, HIGH);
digitalWrite(BIT_1_PIN, LOW);
digitalWrite(BIT_2_PIN, HIGH);
digitalWrite(BIT_3_PIN, HIGH);
delay(DELAY);
}
void binaryE() {
// 1110 (0xE)
digitalWrite(BIT_0_PIN, LOW);
digitalWrite(BIT_1_PIN, HIGH);
digitalWrite(BIT_2_PIN, HIGH);
digitalWrite(BIT_3_PIN, HIGH);
delay(DELAY);
}
void binaryF() {
// 1111 (0xF)
digitalWrite(BIT_0_PIN, HIGH);
digitalWrite(BIT_1_PIN, HIGH);
digitalWrite(BIT_2_PIN, HIGH);
digitalWrite(BIT_3_PIN, HIGH);
delay(DELAY);
}
/*============================================================================*/