ENC28j60 Arduino 不显示小数

ENC28j60 Arduino does not show decimals

我在 Arduino uno 中使用带温度传感器的 ENC28j60 来查看互联网上的温度,但问题是它不显示小数,只显示整数。

Image of Issue

enter code here#include <OneWire.h>
#include <DallasTemperature.h>
#define DS18B20 2
 
OneWire ourWire(DS18B20);
DallasTemperature sensors(&ourWire);
float TempDS;

#include "etherShield.h"
#include "ETHER_28J60.h"

static uint8_t mac[6] = {0x54, 0x55, 0x58, 0x10, 0x00, 0x24};                                                       
static uint8_t ip[4] = {192, 168, 0, 15};
static uint16_t port = 80;

ETHER_28J60 ethernet;

void setup(){
  ethernet.setup(mac, ip, port);
  
Serial.begin(9600);
delay(1000);
sensors.begin();
}
 
void loop(){ sensors.requestTemperatures();  TempDS = sensors.getTempCByIndex(0);

Serial.print(TempDS);
Serial.println(" C");

  if (ethernet.serviceRequest()){
    ethernet.print("<H1>Hello World</H1>");
    ethernet.print( TempDS );
    ethernet.respond();}
}

ETHER_28J60 的打印采用字符指针或整数。您正在向其中填充一个浮点数,所以您丢失了小数点。

将您的浮点数转换为 string