简体   繁体   English

8x8 LED 矩阵和按钮

[英]8x8 LED matrix and push buttons

I have written some code in order to display arrows for a turn signal.我已经编写了一些代码来显示转向灯的箭头。 I'm trying to implement a two push button system that decides which directional arrow to display.我正在尝试实现一个决定显示哪个方向箭头的两个按钮系统。 I have two problems.我有两个问题。

  1. 8x8 LED matrix starts off by being turned on and I can't figure out why. 8x8 LED 矩阵从打开开始,我不知道为什么。

  2. When I press the left Push Button it stops the arrow.当我按下左按钮时,它会停止箭头。

I didn't include the code where the LED draws the arrows because it only contains arrays filled with each frame rate.我没有包含 LED 绘制箭头的代码,因为它只包含填充每个帧速率的数组。

#include "LedControl.h"

/*the last is how many matrices you have connected (dataPin, clockPin, 
csPin, numberDevices) */
LedControl lc = LedControl(12, 11, 10, 1);
int lButton = 2, rButton = 3, lButtonState = 0, rButtonState = 0;


void setup() {
    pinMode(lButton, INPUT);
    pinMode(rButton, INPUT);
}


void leftArrow(){
    //in setup everything is done once
    /*
    The MAX7219 is in power-saving mode on startup,
    we have to do a wakeup call
    */
    lc.shutdown(0, false);
    // Set the brightness to a medium value
    lc.setIntensity(0, 8);
    // and clear the display
    lc.clearDisplay(0);
}

void loop() {
    lButtonState = digitalRead(lButton);
    if (lButtonState == HIGH)
        leftArrow();
}

1_Check your circuit connections. 1_检查您的电路连接。 They probably have problem on data or CLK pins他们可能在数据或 CLK 引脚上有问题

2_To solve the problem of arrows in void loop() You must also add else If not pressed, it will show something else or turn off or whatever... 2_解决void loop()的箭头问题,还必须加上else如果不按下,会显示别的东西或者关掉什么的...

void loop(){
    lButtonState = digitalRead(lButton);
    rButtonState = digitalRead(rButton);
    if (lButtonState == HIGH){
       leftArrow();
    }
    else if (rButtonState == HIGH){
       rightArrow();
    }
    else {
      lc.clearDisplay(0);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM