// Dip switch pins
const int dipSwitchPin[] = {53};
// First dipswitch's button state (cannot be constant - needs to be changed)
int buttonState[] = {0};
// Row and column pins (rows - cathode, columns, anode)
const int rows[] = {17, 16, 15, 14, 2, 3, 4, 5};
const int cols[] = {6, 7, 8, 9, 10, 11, 12, 13};
// Unsigned to ensure that negative values CANNOT be stored in said array
unsigned int initialArray[8][8] =
{
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0}
};
// This array is basically the character array. Top to bottom 0 - 9, A - F
const unsigned int hexadecimalArray[16][8][8] =
{
{{0,1,1,1,1,1,0,0},{0,1,0,0,0,1,0,0},{0,1,0,0,0,1,0,0},{0,1,0,0,0,1,0,0},{0,1,0,0,0,1,0,0},{0,1,0,0,0,1,0,0},{0,1,0,0,0,1,0,0},{0,1,1,1,1,1,0,0}},
{{0,0,0,1,0,0,0,0},{0,0,1,1,0,0,0,0},{0,1,0,1,0,0,0,0},{0,0,0,1,0,0,0,0},{0,0,0,1,0,0,0,0},{0,0,0,1,0,0,0,0},{0,0,0,1,0,0,0,0},{0,1,1,1,1,1,0,0}},
{{0,1,1,1,1,1,0,0},{0,0,0,0,0,1,0,0},{0,0,0,0,0,1,0,0},{0,1,1,1,1,1,0,0},{0,1,0,0,0,0,0,0},{0,1,0,0,0,0,0,0},{0,1,0,0,0,0,0,0},{0,1,1,1,1,1,0,0}},
{{0,1,1,1,1,1,0,0},{0,0,0,0,0,1,0,0},{0,0,0,0,0,1,0,0},{0,1,1,1,1,1,0,0},{0,0,0,0,0,1,0,0},{0,0,0,0,0,1,0,0},{0,0,0,0,0,1,0,0},{0,1,1,1,1,1,0,0}},
{{0,0,0,0,1,0,0,0},{0,0,0,1,1,0,0,0},{0,0,1,0,1,0,0,0},{0,1,0,0,1,0,0,0},{1,1,1,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1,1,0,0,0}},
{{0,1,1,1,1,1,0,0},{0,1,0,0,0,0,0,0},{0,1,0,0,0,0,0,0},{0,1,0,0,0,0,0,0},{0,1,0,0,0,0,0,0},{0,1,0,0,0,0,0,0},{0,1,0,0,0,0,0,0},{0,1,1,1,1,1,0,0}},
{{0,1,1,1,1,0,0,0},{0,1,0,0,0,1,0,0},{0,1,0,0,0,1,0,0},{0,1,0,0,0,1,0,0},{0,1,0,0,0,1,0,0},{0,1,0,0,0,1,0,0},{0,1,0,0,0,1,0,0},{0,1,1,1,1,0,0,0}},
{{0,1,1,1,1,1,0,0},{0,1,0,0,0,0,0,0},{0,1,0,0,0,0,0,0},{0,1,1,1,1,1,0,0},{0,1,0,0,0,0,0,0},{0,1,0,0,0,0,0,0},{0,1,0,0,0,0,0,0},{0,1,1,1,1,1,0,0}},
{{0,1,1,1,1,1,0,0},{0,1,0,0,0,0,0,0},{0,1,0,0,0,0,0,0},{0,1,1,1,1,1,0,0},{0,1,0,0,0,0,0,0},{0,1,0,0,0,0,0,0},{0,1,0,0,0,0,0,0},{0,1,0,0,0,0,0,0}}
};
void setup()
{
// Initiate dipswitch pin to receive input
pinMode(dipSwitchPin[0], INPUT_PULLUP);
// Cathodes: HIGH voltage, Anodes: LOW voltage With this combination, voltage-
// difference across LEDs is insignificant, higher voltage at anode than cathode-
// is required for forward biasing LEDs to emit light.
for (int j = 0; j < 8; j++)
{
pinMode(rows[j], OUTPUT);
digitalWrite(rows[j], HIGH);
pinMode(cols[j], OUTPUT);
digitalWrite(cols[j], LOW);
}
}
void loop()
{
bool displayFlag = false;
buttonState[0] = digitalRead(dipSwitchPin[0]);
// Verify that first button on dipswitch is turned on, setting display character flag as true
if (buttonState[0] == LOW)
{
displayFlag = !displayFlag;
}
// If first button pressed, every single element in initial array will be replaced by elements in hexadecimal array, to allow for showcasing of character
if (displayFlag)
{
for (int characterNum = 0; characterNum < 16; characterNum++)
{
for (int k = 0; k < 8; k++)
{
for (int l = 0; l < 8; l++)
{
initialArray[k][l] = hexadecimalArray[characterNum][k][l];
}
}
unsigned long startTime = millis();
// Display the current character for 2 seconds
while (millis() - startTime < 2000)
{
// If first button is pressed again (turned off), break while loop to switch off all LEDs
buttonState[0] = digitalRead(dipSwitchPin[0]);
if (buttonState[0] == HIGH)
{
displayFlag = false;
break;
}
for (int m = 0; m < 8; m++)
{
digitalWrite(rows[m], LOW); // Setting cathode rows low to create p.d between cathode and anode to allow current flow
for (int n = 0; n < 8; n++)
{
digitalWrite(cols[n], initialArray[m][n]);
digitalWrite(cols[n], LOW);
}
digitalWrite(rows[m], HIGH); // Turning off row currents to prevent forwarding of lit leds from previous character to next
}
}
}
}
else // displayFlag is false, set current character to 0 and turn off all LEDs
{
for (int o = 0; o < 8; o++)
{
for (int p = 0; p < 8; p++)
{
initialArray[o][p] = hexadecimalArray[1][o][p];
}
}
for (int q = 0; q < 8; q++)
{
digitalWrite(rows[q], HIGH); // Set rows (cathodes) to HIGH
}
for (int r = 0; r < 8; r++)
{
digitalWrite(cols[r], LOW); // Set columns (anodes) to LOW
}
}
}