Arduino 如何在仅接受文本的HT1632上打印数字
我刚买了一块8x32点阵板(led矩阵),我用Arduino控制它。问题是我只能在我上的库中使用文本。但不是数字,我该怎么做 我将把代码放在下面,滚动文本的代码和库中指定用于设置文本的函数的部分代码 对滚动文本进行编程的arduino代码如下:Arduino 如何在仅接受文本的HT1632上打印数字,arduino,arduino-c++,Arduino,Arduino C++,我刚买了一块8x32点阵板(led矩阵),我用Arduino控制它。问题是我只能在我上的库中使用文本。但不是数字,我该怎么做 我将把代码放在下面,滚动文本的代码和库中指定用于设置文本的函数的部分代码 对滚动文本进行编程的arduino代码如下: #include <HT1632.h> #include <font_5x4.h> #include <images.h> int i = 0; int wd; char disp[] = "Hello, how a
#include <HT1632.h>
#include <font_5x4.h>
#include <images.h>
int i = 0;
int wd;
char disp[] = "Hello, how are you?";
int x = 10;
void setup() {
HT1632.begin(A5, A4, A3);
wd = HT1632.getTextWidth(disp, FONT_5X4_END, FONT_5X4_HEIGHT);
}
void loop() {
HT1632.renderTarget(1);
HT1632.clear();
HT1632.drawText(disp, OUT_SIZE - i, 2, FONT_5X4, FONT_5X4_END,
FONT_5X4_HEIGHT);
HT1632.render();
i = (i + 1) % (wd + OUT_SIZE);
delay(100);
}
#包括
#包括
#包括
int i=0;
int-wd;
char disp[]=“你好,你好吗?”;
int x=10;
无效设置(){
HT1632.开始(A5、A4、A3);
wd=HT1632.getTextWidth(显示、字体5X4结束、字体5X4高度);
}
void循环(){
HT1632.渲染目标(1);
HT1632.clear();
HT1632.drawText(显示,输出大小-i,2,字体5X4,字体5X4,结束,
字体(5×4×高度);
HT1632.render();
i=(i+1)%(wd+外部尺寸);
延迟(100);
}
指定文本打印的库代码如下:
void HT1632Class::drawText(const char text[], int x, int y, const byte font[],
int font_end[], uint8_t font_height,
uint8_t gutter_space) {
int curr_x = x;
char i = 0;
char currchar;
// Check if string is within y-bounds
if (y + font_height < 0 || y >= COM_SIZE)
return;
while (true) {
if (text[i] == '\0')
return;
currchar = text[i] - 32;
if (currchar >= 65 &&
currchar <=
90) // If character is lower-case, automatically make it upper-case
currchar -= 32; // Make this character uppercase.
if (currchar < 0 || currchar >= 64) { // If out of bounds, skip
++i;
continue; // Skip this character.
}
// Check to see if character is not too far right.
if (curr_x >= OUT_SIZE)
break; // Stop rendering - all other characters are no longer within the
// screen
// Check to see if character is not too far left.
int chr_width = getCharWidth(font_end, font_height, currchar);
if (curr_x + chr_width + gutter_space >= 0) {
drawImage(font, chr_width, font_height, curr_x, y,
getCharOffset(font_end, currchar));
// Draw the gutter space
for (char j = 0; j < gutter_space; ++j)
drawImage(font, 1, font_height, curr_x + chr_width + j, y, 0);
}
curr_x += chr_width + gutter_space;
++i;
}
}
void HT1632Class::drawText(常量字符文本[],int x,int y,常量字节字体[],
int font_end[],uint8_t font_height,
uint8_t排水沟_空间){
int curr_x=x;
字符i=0;
半焦半焦;
//检查字符串是否在y范围内
如果(y+font|U高度<0||y>=COM|U大小)
返回;
while(true){
如果(文本[i]='\0')
返回;
currchar=文本[i]-32;
如果(currchar>=65&&
currchar=64){//如果超出范围,则跳过
++一,;
continue;//跳过此字符。
}
//检查字符是否不太右。
如果(当前大小>=外部大小)
break;//停止渲染-所有其他字符不再在
//屏风
//检查字符是否离得不太远。
int-chr\u-width=getCharWidth(font\u-end,font\u-height,currchar);
如果(当前宽度+边沟间距>=0){
drawImage(字体、字体宽度、字体高度、当前x、y、,
getCharOffset(font_end,currchar));
//绘制排水沟空间
对于(字符j=0;j
您需要查看。这允许您像printf
一样格式化字符串。它允许您将int
之类的内容转换为字符串的一部分
例如:
int hour = 10;
int minutes = 50;
char buffer[60];
int status = snprintf(buffer, 60, "the current time is: %i:%i\n", hour, minutes);
缓冲区现在包含:
“当前时间是:10:50”
(并且在\0
后面有几个空字符)。您有没有收到任何错误?没有,我没有收到任何错误,但问题是我想打印一个不时变化的变量int,上面的代码是用于打印文本的,但是如果我想打印int变量,我该如何更改它,如何更改库和主代码:)你的意思是Serial.println(variable)
?我不想在串行监视器中打印它,我想在led lattice 8x32中打印变量,这就是为什么我把代码放在上面:)所以我在我的ht1632库中包含snprintf函数?你不编辑ht1632库。这是外部的东西,你不应该编辑它。您应该做的是使用snprintf
创建一个设置长度的字符数组,并对其内容进行填充。您可以将该数组作为第一个参数传递给drawText
;整数分钟=50;字符缓冲区[60];HT1632.renderTarget(0);HT1632.clear();HT1632.drawText(缓冲区、输出大小-i、0、字体8X4、字体8X4、结束、字体8X4高度);您忘记使用snprintf
将小时和分钟数添加到缓冲区