我在comb1中存储了光传感器的值,作为一个无符号整型数组。我试图将这些值发送到微处理器。这些值是从存储在数组中的传感器中获取的。然后我试图通过以下命令发送命令:
for(int i = 0; i < 6; i++) {
Serial1.print("AT+SEND=488,3,%u\r\n", comb1[i]);
}
在添加这一行代码之前,整个代码都编译得很好。我收到以下错误消息:
Energia: 1.8.11E23 (Windows 10), Board: "MSP-EXP430FR2355LP"
C:\Users\turne\OneDrive\Documents\Energia\M_Station\M_Station.ino: In function 'void loop()':
M_Station:137:55: error: call of overloaded 'print(const char [19], unsigned int&)' is ambiguous
C:\Users\turne\OneDrive\Documents\Energia\M_Station\M_Station.ino:137:55: note: candidates are:
C:\Users\turne\OneDrive\Documents\energia-1.8.10E23\hardware\energia\msp430\cores\msp430/Print.h:63:12: note: size_t Print::print(unsigned char, int) <near match>
C:\Users\turne\OneDrive\Documents\energia-1.8.10E23\hardware\energia\msp430\cores\msp430/Print.h:63:12: note: no known conversion for argument 1 from 'const char [19]' to 'unsigned char'
C:\Users\turne\OneDrive\Documents\energia-1.8.10E23\hardware\energia\msp430\cores\msp430/Print.h:64:12: note: size_t Print::print(int, int) <near match>
C:\Users\turne\OneDrive\Documents\energia-1.8.10E23\hardware\energia\msp430\cores\msp430/Print.h:64:12: note: no known conversion for argument 1 from 'const char [19]' to 'int'
C:\Users\turne\OneDrive\Documents\energia-1.8.10E23\hardware\energia\msp430\cores\msp430/Print.h:65:12: note: size_t Print::print(unsigned int, int) <near match>
C:\Users\turne\OneDrive\Documents\energia-1.8.10E23\hardware\energia\msp430\cores\msp430/Print.h:65:12: note: no known conversion for argument 1 from 'const char [19]' to 'unsigned int'
C:\Users\turne\OneDrive\Documents\energia-1.8.10E23\hardware\energia\msp430\cores\msp430/Print.h:66:12: note: size_t Print::print(long int, int) <near match>
C:\Users\turne\OneDrive\Documents\energia-1.8.10E23\hardware\energia\msp430\cores\msp430/Print.h:66:12: note: no known conversion for argument 1 from 'const char [19]' to 'long int'
C:\Users\turne\OneDrive\Documents\energia-1.8.10E23\hardware\energia\msp430\cores\msp430/Print.h:67:12: note: size_t Print::print(long unsigned int, int) <near match>
C:\Users\turne\OneDrive\Documents\energia-1.8.10E23\hardware\energia\msp430\cores\msp430/Print.h:67:12: note: no known conversion for argument 1 from 'const char [19]' to 'long unsigned int'
Multiple libraries were found for "Wire.h"
Used: C:\Users\turne\OneDrive\Documents\energia-1.8.10E23\hardware\energia\msp430\libraries\Wire
exit status 1
call of overloaded 'print(const char [19], unsigned int&)' is ambiguous
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
这是我的全部代码:
#include <Wire.h>
#include <msp430.h>
#define VEML7700 0x10
// digital pin 40 has a pushbutton attached to it:
const int Switch = 24;
String DataIn; // Variable to store in the String value
int Sendback = 0;
int Sendreq = 0;
int maintain = 0;
unsigned int comb [6];
unsigned int comb1 [6];
void setup() {
Serial1.begin(115200); // Set up Serial to 115200 baud
pinMode(Switch, OUTPUT);
digitalWrite(Switch, LOW); // turn off switch
// I2C protocol set up
Wire.begin();
Wire.beginTransmission(VEML7700);
Wire.write(0x00);
Wire.write(0x00);
Wire.write(0x08);
Wire.endTransmission();
Wire.beginTransmission(VEML7700);
Wire.write(0x01);
Wire.write(0x00);
Wire.write(0x00);
Wire.endTransmission();
Wire.beginTransmission(VEML7700);
Wire.write(0x02);
Wire.write(0xFF);
Wire.write(0xFF);
Wire.endTransmission();
Wire.beginTransmission(VEML7700);
Wire.write(0x03);
Wire.write(0x04);
Wire.write(0x00);
Wire.endTransmission();
}
void loop() {
if (Serial1.available()) { // Serial is receiving?
DataIn = Serial1.readString(); // Reading from Serial
if (DataIn.indexOf("Wake!") > 0) { // Checking for "Wake!" String
}
//storing light sensor values to be sent to 'M' Station
for (int i = 0; i < 3; i++) {
int Cup = Wire.read(); // receive a byte as character
int Cdown = Wire.read(); // receive a byte as character
if (Cdown < 200) {
maintain = 1;
delay(10);
}
else {
maintain = 0;
delay(10);
}
comb[i] = Cdown * 256 + Cup; // array to get assigned values in each position
}
digitalWrite(Switch, HIGH); // turn on switch////////////////////////////////////////////////////////////////////////////
delay(10);
//storing light sensor values to be sent to second set 'M' Station
{
for (int i = 3; i < 6; i++) {
int Cup = Wire.read(); // receive a byte as character
int Cdown = Wire.read(); // receive a byte as character
if (Cdown < 200) {
maintain = 1;
delay(10);
}
else {
maintain = 0;
delay(10);
}
comb[i] = Cdown * 256 + Cup; // array to get assigned values in each position
}
}
for (int i = 0; i < 6; i++) {
//Serial.println(comb[i]);
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (Serial1.available()) { // Serial is receiving?
DataIn = Serial1.readString(); // Reading from Serial
//storing light sensor values to be sent to 'M' Station
for (int i = 0; i < 3; i++) {
int Cup = Wire.read(); // receive a byte as character
int Cdown = Wire.read(); // receive a byte as character
if (Cdown < 200) {
maintain = 1;
delay(10);
}
else {
maintain = 0;
delay(10);
}
comb1[i] = Cdown * 256 + Cup; // array to get assigned values in each position
}
digitalWrite(Switch, LOW); // turn off switch/////////////////////////////////////////////////////////////////
delay(10);
//storing light sensor values to be sent to 'M' Station
for (int i = 3; i < 6; i++) {
int Cup = Wire.read(); // receive a byte as character
int Cdown = Wire.read(); // receive a byte as character
if (Cdown < 200) {
maintain = 1;
delay(10);
}
else {
maintain = 0;
delay(10);
}
comb1[i] = Cdown * 256 + Cup; // array to get assigned values in each position
}
Sendback = 2;
Sendreq = 0;
maintain = 0;
for (int i = 0; i < 6; i++) {
Serial1.print("AT+SEND=488,3,%u\r\n", comb1[i]);
}
}
if (Sendback == 1) {
Serial1.print("AT+SEND=488,3,Up!\r\n"); // Send AT command with String "Up!"
delay(10);
Sendback = 0;
Sendreq = 1;
}
if (Sendreq == 1) {
Wire.beginTransmission(VEML7700);
Wire.write(0x04);
Wire.write(0x04);
Wire.endTransmission(false);
Wire.requestFrom(VEML7700, 2, true);
while (Wire.available()); // slave may send less than requested
}
if (maintain == 1) {
Serial1.print("AT+SEND=488,4,req!\r\n"); // Send AT command with String "req!"
delay(10);
maintain = 0;
}
if (Sendback == 2) {
Serial1.print("AT+SEND=488,5,Down!\r\n"); // Send AT command with String "Down!"
delay(10);
Sendback = 0;
Sendreq = 0;
maintain = 0;
}
delay(100);
}
如果你需要更多的信息,请告诉我。我认为重载意味着有不同种类的信息存储在comb1上,编译器不知道从哪种信息中选择?但是comb1
被声明为unsigned int
,值中只有整数。我不知道我是否错误地理解了重载的含义。或者如果我在comb1
中分配多种数据,请让我知道你的想法。
1条答案
按热度按时间gojuced71#
Serial1.print("AT+SEND=488,3,%u\r\n", comb1[i]);
print
不适用于带格式的字符串。您需要使用printf
。