Arduino 函数参数

Arduino function parameters

本文关键字:参数 函数 Arduino      更新时间:2023-10-16

Code

#include <SPI.h>
#include "Ucglib.h"
Ucglib_ILI9341_18x240x320_HWSPI ucg(/*cd=*/ 8, /*cs=*/ 7, /*reset=*/ 5);
void functionBar()
{
ucg.begin(UCG_FONT_MODE_TRANSPARENT);
ucg.clearScreen();
ucg.setRotate270();
ucg.setColor(94, 88, 107);
ucg.drawBox(0,0, 320, 20);
ucg.setColor(255,255, 255);
ucg.setFont(ucg_font_9x18_tf);
frm("Blitz OS", 0);


}
void frm(string a, int b)
{
int width = ucg.getStrWidth(a);
ucg.setPrintPos(width, 15);
ucg.print(a);
}

错误:

FunctionBar:23:10: error: variable or field 'frm' declared void
void frm(string a, int b)
^~~~~~
FunctionBar:23:10: error: 'string' was not declared in this scope
D:UsersALMADesktopBlitz OSSetupFunctionBar.ino:23:10: note: suggested alternative: 'String'
void frm(string a, int b)
^~~~~~
String
FunctionBar:23:20: error: expected primary-expression before 'int'
void frm(string a, int b)
^~~
D:UsersALMADesktopBlitz OSSetupFunctionBar.ino: In function 'void functionBar()':
FunctionBar:18:3: error: 'frm' was not declared in this scope
frm("Blitz OS", 0);
^~~
D:UsersALMADesktopBlitz OSSetupFunctionBar.ino:18:3: note: suggested alternative: 'free'
frm("Blitz OS", 0);
^~~
free
D:UsersALMADesktopBlitz OSSetupFunctionBar.ino: At global scope:
FunctionBar:23:10: error: variable or field 'frm' declared void
void frm(string a, int b)
^~~~~~
FunctionBar:23:10: error: 'string' was not declared in this scope
D:UsersALMADesktopBlitz OSSetupFunctionBar.ino:23:10: note: suggested alternative: 'String'
void frm(string a, int b)
^~~~~~
String
FunctionBar:23:20: error: expected primary-expression before 'int'
void frm(string a, int b)
^~~
exit status 1
variable or field 'frm' declared void

我不知道为什么,但它不允许我在字符串 a 之后添加另一个参数。

ucg.getStrWidth中参数的类型为const char*。因此,您也可以将此类型用作函数中的参数。