int katodaLED[]={22,23,24,25,26,27,28,29};
int anodaLED[]={37,36,35,34,33,32,31,30};
int jeda=10;
void setup() {
// put your setup code here, to run once:
for (int nmr=0;nmr<8;nmr++)
{
pinMode(katodaLED[nmr], OUTPUT);
pinMode(anodaLED[nmr], OUTPUT);
}
}
/*Using a dip switch, create a solution to display the following characters on the 8x8 LED matrix. Characters to be displayed 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
Continuing from the task above for designing LED matrix with a new feature. Use a pushbutton, when it is pressed, the character will move from left to right.
Then continue from designing LED matrix with additional features to be added with the same pushbutton to change up to 3 modes for speed of the moving character including slow, medium and fast.
The codes that I have attempted, please edit and have a look on the day of our lesson.
// Define Arduino pin connections for the rows and columns of the LED matrix
const int PinsRow[8] = {22,23,24,25,26,27,28,29}; // Example row pin numbers
const int PinsColumn[8] = {37,36,35,34,33,32,31,30}; // Example column pin numbers
const int PinsDSwitch[8] = {39, 41, 43, 45, 47, 19, 51, 53}; // Example DIP switch pin numbers
// Pin setup for the LED matrix
const int DIN_PIN = 2;
const int CLK_PIN = 3;
const int CS_PIN = 4;
LedControl lc = LedControl(DIN_PIN, CLK_PIN, CS_PIN, 1);
// Define the characters as byte arrays
byte characters[16][8] = {
{0x3E, 0x51, 0x49, 0x45, 0x3E}, // 0
{0x00, 0x42, 0x7F, 0x40, 0x00}, // 1
{0x42, 0x61, 0x51, 0x49, 0x46}, // 2
{0x21, 0x41, 0x45, 0x4B, 0x31}, // 3
{0x18, 0x14, 0x12, 0x7F, 0x10}, // 4
{0x27, 0x45, 0x45, 0x45, 0x39}, // 5
{0x3C, 0x4A, 0x49, 0x49, 0x30}, // 6
{0x01, 0x71, 0x09, 0x05, 0x03}, // 7
{0x36, 0x49, 0x49, 0x49, 0x36}, // 8
{0x06, 0x49, 0x49, 0x29, 0x1E}, // 9
{0x7F, 0x09, 0x09, 0x09, 0x7F}, // A
{0x7F, 0x49, 0x49, 0x49, 0x36}, // B
{0x3E, 0x41, 0x41, 0x41, 0x22}, // C
{0x7F, 0x41, 0x41, 0x22, 0x1C}, // D
{0x7F, 0x49, 0x49, 0x49, 0x41}, // E
{0x7F, 0x09, 0x09, 0x09, 0x01} // F
};
void setup() {
// Initialize row and column pins
for (int i = 0; i < 8; i++) {
pinMode(rowPins[i], OUTPUT);
pinMode(colPins[i], OUTPUT);
pinMode(dipSwitchPins[i], INPUT);
}
}
void loop() {
int characterIndex = readDipSwitch();
displayCharacter(characters[characterIndex]);
}
int readDipSwitch() {
int value = 0;
for (int i = 0; i < 8; i++) {
if (digitalRead(dipSwitchPins[i]) == HIGH) {
value |= (1 << i);
}
}
return value % 16; // Returns a value between 0 and 15
}
void displayCharacter(byte character[]) {
for (int row = 0; row < 8; row++) {
for (int col = 0; col < 8; col++) {
if (character[row] & (1 << col)) {
turnOnLED(row, col);
delay(1); // Short delay for LED to be visible
}
turnOffLEDs();
}
}
}
void turnOnLED(int row, int col) {
digitalWrite(rowPins[row], HIGH);
digitalWrite(colPins[col], LOW);
}
void turnOffLEDs() {
for (int i = 0; i < 8; i++) {
digitalWrite(rowPins[i], LOW);
digitalWrite(colPins[i], HIGH);
}
}*/