2

I want the Led's in a 5 * 5 Led-Matrix to light up in the shape of a square. If the corresponding buttons in the 5*5 Push-button matrix are pressed, the led turns off. The buttons are pressed in the clockwise direction starting from the first button on the top left side. I am using Arduino-Uno as programmer and Arduino-Mega2560 as target and the 5*5 Led-Matrix and 5 *5 push-Buttons matrix are connected to Arduino-Mega2560. I have the code for 5*5 Led-Matrix code which lights up in the shape of a square as separate code and 5*5 Push-Button Matrix as separate code, where to input the codes of 5*5 push-button matrix to control the 5*5 Led-Matrix, as discussed above. Thanks

The code for 5*5 Led-Matrix to light up in the shape of a square

#define MAXLEDS 5
int states[MAXLEDS][MAXLEDS] = {
    { 1, 1, 1 ,1 ,1 },
    { 1, 0, 0 ,0 ,1 },
    { 1, 0, 0, 0 ,1 },
    { 1, 0, 0, 0 ,1 },
    { 1, 1, 1, 1 ,1 },

};
int Led_Row_Pins[] = { 2 , 3 , 4 , 5 , 6 } ;             //   Anode pins are shorted in row_wise_manner
int Led_Column_Pins[] = {7 , 8 , 9 , 10 , 11 } ;          //   Column Pins are shorted in column_wise_manner   
int Loop_Count = 5 ;
int i = 0 ;
int j = 0 ;
int state = 1 ;

void setup() {
  for( i = 0 ; i < Loop_Count ; i++ ){     // Anode Pins are connected in row_wise manner and are made LOW so that they dont conduct       
    pinMode(Led_Row_Pins[i],OUTPUT);
    digitalWrite(Led_Row_Pins[i],LOW);
    pinMode(Led_Column_Pins[i],OUTPUT);    // Cathode Pins are connected in column_wise manner and are made HIGH so that they dont conduct
    digitalWrite(Led_Column_Pins[i],HIGH); 
  }
}


void switch_leds(int row) {
    int i;

    /* switch off all rows */
    for(i = 0; i < MAXLEDS; i++) {
        digitalWrite(Led_Row_Pins[i], 0);
    }

    /* switch columns according to current row */
    for(i = 0; i < MAXLEDS; i++) {
        digitalWrite(Led_Column_Pins[i], !states[row][i]);
    }

    /* switch on current row */
    digitalWrite(Led_Row_Pins[row], 1);

}

void loop() { 
    static int row = 0;
    /* switch on LEDs in a single row */
    switch_leds(row);
    /* next row */
    row++; row %= MAXLEDS;
    /* The processing delay between calls to loop() is added to this delay. */
    delay(5);
}

The code for the 5*5 push-button matrix is,

#include <Keypad.h>

const byte ROWS = 5; 
const byte COLS = 5; 

char hexaKeys[ROWS][COLS] = {
  {'0', '1', '2' , '3', '4'},
  {'5', '6', '7' , '8', '9'},
  {'A', 'B', 'C' , 'D', 'E'},
  {'F', 'G', 'H',  'I', 'J'},
  {'K', 'L', 'M',   'N','O'},

};

byte rowPins[ROWS] = { 40, 39 , 38 , 37  ,36 }; 
byte colPins[COLS] = { 35  , 34  , 33  , 32 , 31 };  

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 

void setup(){
  Serial.begin(9600);

}

void loop(){
  char customKey = customKeypad.getKey();

  if(customKey)
  Serial.println(customKey);
}
Piglet
  • 27,501
  • 3
  • 20
  • 43
Paulson Raja L
  • 379
  • 2
  • 11
  • You want "...", but what is the problem? What is your question? What help, apart from a program which does as desired, are you expecting? – Yunnosch Nov 11 '19 at 07:00
  • why is this tagged arduino-esp8266 if you're using an Arduino Mega? – Piglet Nov 11 '19 at 07:59
  • understand code a), understand code b) then merge them. That's it. if you just ask how to merge them you won't learn a thing. – Piglet Nov 11 '19 at 08:07
  • @Piglet Sorry Sir, will not definitely do it in the future. – Paulson Raja L Nov 11 '19 at 08:55
  • what stops you from solving this yourself? what is the first step you cannot accomplish alone? – Piglet Nov 11 '19 at 08:57
  • @Piglet Since the Led-Matrix lights up in the shape of a square and when I press the corresponding push-button that led should alone turn off. Should I write like this if( customKey == 1 ){ Led1_Off();} – Paulson Raja L Nov 11 '19 at 09:04
  • that would depend on the rest of your program. Why don't you learn some basics until you get to the point where you find the solution yourself? there are more than enough tutorials and books available – Piglet Nov 11 '19 at 09:11
  • @Piglet Ok Sir..! , Thank You..! – Paulson Raja L Nov 11 '19 at 09:13
  • Possible duplicate of [Is there a possibility to glow the led in 5\*5 matrix in a square shape with the common anode configuration](https://stackoverflow.com/questions/58521030/is-there-a-possibility-to-glow-the-led-in-55-matrix-in-a-square-shape-with-the) – Juraj Nov 12 '19 at 15:30

0 Answers0