我已经编写了一些代码来显示转向信号的箭头。我正在尝试实现一个两个按钮系统,决定显示哪个方向箭头。我有两个问题。
8x8 LED矩阵因打开而开始,我无法弄清楚原因。
当我按下左按钮时,它会停止箭头。
我没有包含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();
}
答案 0 :(得分:0)
1_检查您的电路连接。他们可能在数据或 CLK 引脚上有问题
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);
}