Arduino: printf/fprintf prints question mark instead of float

后端 未结 4 931
别跟我提以往
别跟我提以往 2020-12-06 18:32

I have the following code for an Arduino sketch:

#include 

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
static FILE lcdout = {0} ;

static          


        
4条回答
  •  醉话见心
    2020-12-06 18:51

    I did this one:

    unsigned char buffer[32];
    
    void setup() {
      serial.begin();
    }
    
    void loop() {
      if(serial.available()) {
        int size = serial.read(buffer);
        if (size!=0) {
          //serial.write((const uint8_t*)buffer, size);
          int bright = atoi((char *) buffer);
    
          //int final = ((unsigned int)buffer[0]);
    
          //int final = bright -'0';
          serial.write(bright);
          serial.write('\n');
        }
      }
      serial.poll();
    }
    

    and now i get an ascii char when i send a value from 0-255 through the usb. I should find a way to convert the ascii char to int.

    e.g i type 65 and it prints A

提交回复
热议问题