【发布时间】:2022-08-14 01:32:57
【问题描述】:
你好
我有一个来自 instrucables 的 arduino 代码,用于构建带有 arduino 和 ds1307 RTC 模块和 74HC595 移位寄存器的基于模拟 LED 时钟的 LED 滚动条
请参阅下面链接中的代码(LED_MEGA_CLOCK.ino):
https://www.instructables.com/LED-Mega-Clock/
一段代码如下:
\'\'\'
/*
LED-CLOCK V1.0
Arduino Mega 2560
K. Michalsky
28.10.14
*/
#include \"Tlc5940.h\"
#include <Time.h>
#include \"Wire.h\"
#define DS1307_ADDRESS 0x68
int dataPin = 2; // The Serial Data Pin to the Shift Register
int latchPin = 3; // The Latch Pin to the Shift Register
int clockPin = 4 ; // The Clock Pin to the Shift Register
// RGB LED Strip Pins
int blueStrip = 5;
int redStrip = 6;
int greenStrip = 7;
int interval = 1; // Variable for delay
int const cycle = 9; // constante for cycles (LED-Strip)
int lum = 500; // birghtness for digit display
int CA[] = {38,39,40,41}; // Anodes for digit display
// Definition of registers arrays for blue LEDs
int register1[] = {0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 1,2,4,8,16,32,64,128};
int register2[] = {0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 1,2,4,8,16,32,64,128, 0,0,0,0,0,0,0,0};
int register3[] = {0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 1,2,4,8,16,32,64,128, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0};
int register4[] = {0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 1,2,4,8,16,32,64,128, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0};
int register5[] = {0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 1,2,4,8,16,32,64,128, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0};
int register6[] = {0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 1,2,4,8,16,32,64,128, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0};
int register7[] = {0,0,0,0,0,0,0,0, 1,2,4,8,16,32,64,128, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0};
int register8[] = {1,2,4,8,16,32,64,128, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0};
// Array for for blue LEDs cathodes
int pin[] = {22,23,24,25,26,27,28,29};
// Definition of pins as output and Tlc setup
void setup()
{
Wire.begin();
Serial.begin(9600);
pinMode(dataPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
for (int i=0; i < 8; i++){
pinMode(pin[i], OUTPUT);
}
Tlc.init();
for(int n=0; n < 4; n++){
pinMode(CA[n], OUTPUT);
}
}
void loop(){
}
\'\'\'
你能帮我准备各种改变指示器形状的数组吗?(根据下图)
-
每个 SO 帖子 1 个问题。
-
对于第二个问题,请阅读Binary-coded decimal。特别是“打包的 BCD”部分。
-
对于您的问题 1, 1,2,4,8,16,32,64,128 是 B0000001, B00000010, B00000100, B00001000, B00010000, B00100000, B01000000, B10000000 二进制,这意味着在任何给定时间只有一位是 1。
标签: c++ arrays arduino microcontroller shift-register