简体   繁体   中英

I am trying to send light sensor data to a microprocessor and getting "call of overloaded 'print(const char[19],unsigned int&)' is ambiguous" error

I have stored light sensor values in comb1, as an array in an unsigned int. I am trying to send these values to a microprocessor. The values are taken from a sensor stored in an array. Then I am trying to send the commands through this:

for(int i = 0; i < 6; i++) {
  Serial1.print("AT+SEND=488,3,%u\r\n", comb1[i]);
}

The entire code compiles fine until I add this line of code. I receive this error message:

 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.

This is my whole code:

#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);
}

Please let me know if you need any more information. I think overloading means that there are different kinds of information stored on comb1 and the compiler does not know which to choose from? But comb1 is declared as an unsigned int and nothing but integers are in the value. I do not know if I have the wrong understanding of what overloaded means, or if I am assigning multiple kinds of data in comb1 . Please let me know what you think.

Serial1.print("AT+SEND=488,3,%u\r\n", comb1[i]);

print doesn't work with formatted strings. You need to use printf .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM