在哪里输入5 * 5按钮矩阵的代码来控制5 * 5 LED矩阵,该矩阵以方形发光

时间:2019-11-11 06:47:10

标签: arduino arduino-uno arduino-ide arduino-esp8266

我希望5 * 5 Led矩阵中的Led以正方形发光。如果按下5 * 5按钮矩阵中的相应按钮,则LED指示灯熄灭。从左上方的第一个按钮开始,按顺时针方向按按钮。我使用Arduino-Uno作为程序员,使用Arduino-Mega2560作为目标,并且5 * 5 Led-Matrix和5 * 5按钮矩阵连接到Arduino-Mega2560。我有5 * 5 LED矩阵代码的代码,该代码以正方形的形式点亮,作为单独的代码,而5 * 5按钮矩阵作为单独的代码,在其中输入5 * 5按钮矩阵的代码到如上所述,控制5 * 5 Led矩阵。谢谢

5 * 5 Led矩阵以正方形发光的代码

#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);
}

5 * 5按钮矩阵的代码是

#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);
}

0 个答案:

没有答案