/* LED Binary Counter - 5-bit*/
/*============================== CONFIGURAZIONI ==============================*/
// REGISTRY SIZE
#define BIT_NUMBER 5
// PINs
#define BIT_0_PIN 2
#define BIT_1_PIN 4
#define BIT_2_PIN 6
#define BIT_3_PIN 8
#define BIT_4_PIN 10
// DELAY
#define DELAY 1500
/*============================================================================*/
/*============================ VARIABILI GLOBALI =============================*/
int registry[BIT_NUMBER] = {BIT_0_PIN, BIT_1_PIN, BIT_2_PIN, BIT_3_PIN, BIT_4_PIN};
// Counter
int i;
/*============================================================================*/
/*=========================== FUNZIONI PRINCIPALI ============================*/
void setup() {
for(i=0; i<5; i++) {
pinMode(registry[i], OUTPUT);
}
}
void loop() {
binary00();
binary01();
binary02();
binary03();
binary04();
binary05();
binary06();
binary07();
binary08();
binary09();
binary0A();
binary0B();
binary0C();
binary0D();
binary0E();
binary0F();
binary10();
binary11();
binary12();
binary13();
binary14();
binary15();
binary16();
binary17();
binary18();
binary19();
binary1A();
binary1B();
binary1C();
binary1D();
binary1E();
binary1F();
}
/*============================================================================*/
/*============================== ALTRE FUNZIONI ==============================*/
void binary00() {
// 00000 (0x0)
digitalWrite(BIT_0_PIN, LOW);
digitalWrite(BIT_1_PIN, LOW);
digitalWrite(BIT_2_PIN, LOW);
digitalWrite(BIT_3_PIN, LOW);
digitalWrite(BIT_4_PIN, LOW);
delay(DELAY);
}
void binary01() {
// 00001 (0x1)
digitalWrite(BIT_0_PIN, HIGH);
digitalWrite(BIT_1_PIN, LOW);
digitalWrite(BIT_2_PIN, LOW);
digitalWrite(BIT_3_PIN, LOW);
digitalWrite(BIT_4_PIN, LOW);
delay(DELAY);
}
void binary02() {
// 00010 (0x2)
digitalWrite(BIT_0_PIN, LOW);
digitalWrite(BIT_1_PIN, HIGH);
digitalWrite(BIT_2_PIN, LOW);
digitalWrite(BIT_3_PIN, LOW);
digitalWrite(BIT_4_PIN, LOW);
delay(DELAY);
}
void binary03() {
// 00011 (0x3)
digitalWrite(BIT_0_PIN, HIGH);
digitalWrite(BIT_1_PIN, HIGH);
digitalWrite(BIT_2_PIN, LOW);
digitalWrite(BIT_3_PIN, LOW);
digitalWrite(BIT_4_PIN, LOW);
delay(DELAY);
}
void binary04() {
// 00100 (0x4)
digitalWrite(BIT_0_PIN, LOW);
digitalWrite(BIT_1_PIN, LOW);
digitalWrite(BIT_2_PIN, HIGH);
digitalWrite(BIT_3_PIN, LOW);
digitalWrite(BIT_4_PIN, LOW);
delay(DELAY);
}
void binary05() {
// 00101 (0x5)
digitalWrite(BIT_0_PIN, HIGH);
digitalWrite(BIT_1_PIN, LOW);
digitalWrite(BIT_2_PIN, HIGH);
digitalWrite(BIT_3_PIN, LOW);
digitalWrite(BIT_4_PIN, LOW);
delay(DELAY);
}
void binary06() {
// 00110 (0x6)
digitalWrite(BIT_0_PIN, LOW);
digitalWrite(BIT_1_PIN, HIGH);
digitalWrite(BIT_2_PIN, HIGH);
digitalWrite(BIT_3_PIN, LOW);
digitalWrite(BIT_4_PIN, LOW);
delay(DELAY);
}
void binary07() {
// 00111 (0x7)
digitalWrite(BIT_0_PIN, HIGH);
digitalWrite(BIT_1_PIN, HIGH);
digitalWrite(BIT_2_PIN, HIGH);
digitalWrite(BIT_3_PIN, LOW);
digitalWrite(BIT_4_PIN, LOW);
delay(DELAY);
}
void binary08() {
// 01000 (0x8)
digitalWrite(BIT_0_PIN, LOW);
digitalWrite(BIT_1_PIN, LOW);
digitalWrite(BIT_2_PIN, LOW);
digitalWrite(BIT_3_PIN, HIGH);
digitalWrite(BIT_4_PIN, LOW);
delay(DELAY);
}
void binary09() {
// 01001 (0x9)
digitalWrite(BIT_0_PIN, HIGH);
digitalWrite(BIT_1_PIN, LOW);
digitalWrite(BIT_2_PIN, LOW);
digitalWrite(BIT_3_PIN, HIGH);
digitalWrite(BIT_4_PIN, LOW);
delay(DELAY);
}
void binary0A() {
// 01010 (0xA)
digitalWrite(BIT_0_PIN, LOW);
digitalWrite(BIT_1_PIN, HIGH);
digitalWrite(BIT_2_PIN, LOW);
digitalWrite(BIT_3_PIN, HIGH);
digitalWrite(BIT_4_PIN, LOW);
delay(DELAY);
}
void binary0B() {
// 01011 (0xB)
digitalWrite(BIT_0_PIN, HIGH);
digitalWrite(BIT_1_PIN, HIGH);
digitalWrite(BIT_2_PIN, LOW);
digitalWrite(BIT_3_PIN, HIGH);
digitalWrite(BIT_4_PIN, LOW);
delay(DELAY);
}
void binary0C() {
// 01100 (0xC)
digitalWrite(BIT_0_PIN, LOW);
digitalWrite(BIT_1_PIN, LOW);
digitalWrite(BIT_2_PIN, HIGH);
digitalWrite(BIT_3_PIN, HIGH);
digitalWrite(BIT_4_PIN, LOW);
delay(DELAY);
}
void binary0D() {
// 01101 (0xD)
digitalWrite(BIT_0_PIN, HIGH);
digitalWrite(BIT_1_PIN, LOW);
digitalWrite(BIT_2_PIN, HIGH);
digitalWrite(BIT_3_PIN, HIGH);
digitalWrite(BIT_4_PIN, LOW);
delay(DELAY);
}
void binary0E() {
// 01110 (0xE)
digitalWrite(BIT_0_PIN, LOW);
digitalWrite(BIT_1_PIN, HIGH);
digitalWrite(BIT_2_PIN, HIGH);
digitalWrite(BIT_3_PIN, HIGH);
digitalWrite(BIT_4_PIN, LOW);
delay(DELAY);
}
void binary0F() {
// 01111 (0xF)
digitalWrite(BIT_0_PIN, HIGH);
digitalWrite(BIT_1_PIN, HIGH);
digitalWrite(BIT_2_PIN, HIGH);
digitalWrite(BIT_3_PIN, HIGH);
digitalWrite(BIT_4_PIN, LOW);
delay(DELAY);
}
void binary10() {
// 10000 (0x0)
digitalWrite(BIT_0_PIN, LOW);
digitalWrite(BIT_1_PIN, LOW);
digitalWrite(BIT_2_PIN, LOW);
digitalWrite(BIT_3_PIN, LOW);
digitalWrite(BIT_4_PIN, HIGH);
delay(DELAY);
}
void binary11() {
// 10001 (0x1)
digitalWrite(BIT_0_PIN, HIGH);
digitalWrite(BIT_1_PIN, LOW);
digitalWrite(BIT_2_PIN, LOW);
digitalWrite(BIT_3_PIN, LOW);
digitalWrite(BIT_4_PIN, HIGH);
delay(DELAY);
}
void binary12() {
// 10010 (0x2)
digitalWrite(BIT_0_PIN, LOW);
digitalWrite(BIT_1_PIN, HIGH);
digitalWrite(BIT_2_PIN, LOW);
digitalWrite(BIT_3_PIN, LOW);
digitalWrite(BIT_4_PIN, HIGH);
delay(DELAY);
}
void binary13() {
// 10011 (0x3)
digitalWrite(BIT_0_PIN, HIGH);
digitalWrite(BIT_1_PIN, HIGH);
digitalWrite(BIT_2_PIN, LOW);
digitalWrite(BIT_3_PIN, LOW);
digitalWrite(BIT_4_PIN, HIGH);
delay(DELAY);
}
void binary14() {
// 10100 (0x4)
digitalWrite(BIT_0_PIN, LOW);
digitalWrite(BIT_1_PIN, LOW);
digitalWrite(BIT_2_PIN, HIGH);
digitalWrite(BIT_3_PIN, LOW);
digitalWrite(BIT_4_PIN, HIGH);
delay(DELAY);
}
void binary15() {
// 10101 (0x5)
digitalWrite(BIT_0_PIN, HIGH);
digitalWrite(BIT_1_PIN, LOW);
digitalWrite(BIT_2_PIN, HIGH);
digitalWrite(BIT_3_PIN, LOW);
digitalWrite(BIT_4_PIN, HIGH);
delay(DELAY);
}
void binary16() {
// 10110 (0x6)
digitalWrite(BIT_0_PIN, LOW);
digitalWrite(BIT_1_PIN, HIGH);
digitalWrite(BIT_2_PIN, HIGH);
digitalWrite(BIT_3_PIN, LOW);
digitalWrite(BIT_4_PIN, HIGH);
delay(DELAY);
}
void binary17() {
// 10111 (0x7)
digitalWrite(BIT_0_PIN, HIGH);
digitalWrite(BIT_1_PIN, HIGH);
digitalWrite(BIT_2_PIN, HIGH);
digitalWrite(BIT_3_PIN, LOW);
digitalWrite(BIT_4_PIN, HIGH);
delay(DELAY);
}
void binary18() {
// 11000 (0x8)
digitalWrite(BIT_0_PIN, LOW);
digitalWrite(BIT_1_PIN, LOW);
digitalWrite(BIT_2_PIN, LOW);
digitalWrite(BIT_3_PIN, HIGH);
digitalWrite(BIT_4_PIN, HIGH);
delay(DELAY);
}
void binary19() {
// 11001 (0x9)
digitalWrite(BIT_0_PIN, HIGH);
digitalWrite(BIT_1_PIN, LOW);
digitalWrite(BIT_2_PIN, LOW);
digitalWrite(BIT_3_PIN, HIGH);
digitalWrite(BIT_4_PIN, HIGH);
delay(DELAY);
}
void binary1A() {
// 11010 (0xA)
digitalWrite(BIT_0_PIN, LOW);
digitalWrite(BIT_1_PIN, HIGH);
digitalWrite(BIT_2_PIN, LOW);
digitalWrite(BIT_3_PIN, HIGH);
digitalWrite(BIT_4_PIN, HIGH);
delay(DELAY);
}
void binary1B() {
// 11011 (0xB)
digitalWrite(BIT_0_PIN, HIGH);
digitalWrite(BIT_1_PIN, HIGH);
digitalWrite(BIT_2_PIN, LOW);
digitalWrite(BIT_3_PIN, HIGH);
digitalWrite(BIT_4_PIN, HIGH);
delay(DELAY);
}
void binary1C() {
// 11100 (0xC)
digitalWrite(BIT_0_PIN, LOW);
digitalWrite(BIT_1_PIN, LOW);
digitalWrite(BIT_2_PIN, HIGH);
digitalWrite(BIT_3_PIN, HIGH);
digitalWrite(BIT_4_PIN, HIGH);
delay(DELAY);
}
void binary1D() {
// 11101 (0xD)
digitalWrite(BIT_0_PIN, HIGH);
digitalWrite(BIT_1_PIN, LOW);
digitalWrite(BIT_2_PIN, HIGH);
digitalWrite(BIT_3_PIN, HIGH);
digitalWrite(BIT_4_PIN, HIGH);
delay(DELAY);
}
void binary1E() {
// 11110 (0xE)
digitalWrite(BIT_0_PIN, LOW);
digitalWrite(BIT_1_PIN, HIGH);
digitalWrite(BIT_2_PIN, HIGH);
digitalWrite(BIT_3_PIN, HIGH);
digitalWrite(BIT_4_PIN, HIGH);
delay(DELAY);
}
void binary1F() {
// 11111 (0xF)
digitalWrite(BIT_0_PIN, HIGH);
digitalWrite(BIT_1_PIN, HIGH);
digitalWrite(BIT_2_PIN, HIGH);
digitalWrite(BIT_3_PIN, HIGH);
digitalWrite(BIT_4_PIN, HIGH);
delay(DELAY);
}
/*============================================================================*/