【发布时间】:2017-06-13 09:39:38
【问题描述】:
我的问题涉及如何使用 arduino 轻松访问大量变量的主题。我想知道是否有可能在循环中动态更改变量名。我的英语不是最好的,所以让我用我现在正在处理的代码来解释一下。
我有一台小型热敏打印机。打印方法来自adafruit热敏打印库
void Adafruit_Thermal::printBitmap(int w, int h, const uint8_t *bitmap, bool fromProgMem) {
...
}
我创建了一个如下所示的位图字体:
static const uint8_t PROGMEM Char_32[] {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
}; // Char 032 ( )
static const uint8_t PROGMEM Char_33[] {
0x00, 0x00, 0x2E, 0x00, 0x00, 0x00, 0x00, 0x00
}; // Char 033 (!)
... for each caracter
我喜欢在这个 for 循环中逐字打印:
for(j = 0; j <= messageLength - 1; j++){ // Go through each character in the message.
int character = message[j]; // reads and stores the ASCII value of the current Character
printer.printBitmap(letter_width, letter_height, Char_XX); // i like to print the specific character
}
通常我会采用一个二维数组并像这样打印:
static const uint8_t PROGMEM letter_data[][8] =
{
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // Char 032 ( )
{0x00, 0x00, 0x2E, 0x00, 0x00, 0x00, 0x00, 0x00}, // Char 033 (!)
{0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00} // Char 034 (")
}
for(j = 0; j <= messageLength - 1; j++){ //Go through each character in the message.
int Character = message[j] - 32; // first visible ASCIIcharacter '!' is number 33. reads and stores the ASCII value of the current Character we are dealing with and -32 so the char correspnds to our array.
printer.printBitmap(letter_width, letter_height, letter_data[Character]);
}
但是,我的字母会比 8x8 像素大得多,而且我的数组也会变大。那么有没有可能解决这个问题?
【问题讨论】:
-
变得太大是什么意思?内存不足了吗?
-
您需要 3 个嵌套循环:位图行/消息中的字符/位图列。
-
根据您的代码,听起来 "changeing variable names" 对您的问题的描述是错误的,您的问题更多地与尝试管理内存使用有关,尤其是在堆栈使用方面。
-
@user3853544 我的字母是 136x72px 所以对应的 aray 必须是 array[][1224] 并且编译器会抛出这个错误
letters.h:7554: error: size of array is too large }; ^
标签: c++ variables arduino concatenation concat