Säkerligen en väldigt enkel nöt att knäcka för er som begriper
Jag har gjort en termometer som visar temp på Oled. Jag använder en DS20B18 och Oled som kommer med startpaketet Arduino.
Det jag skulle behöva hjälp med är att ta bort en decimal på det som visas, hur gör jag detta?
Kod: Markera allt
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h><br>#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#define ONE_WIRE_BUS 4
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup(void)
{
// Start serial communication for debugging purposes
Serial.begin(9600); // initialize the Serial Monitor at a baud rate of 9600
// Start up the library
sensors.begin(); // initialize the DS18B20 temperature sensor:
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
}
void loop(void){
// Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
sensors.requestTemperatures();
Serial.print("Celsius temperature: ");
// Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
Serial.println(sensors.getTempCByIndex(0)); // get and print the temperature in degree Celsius
float T = sensors.getTempCByIndex(0); // let T be temperature in degC from sensor<br>// floating-point number, with a decimal point
delay(1000);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println("Vattentemp: "); // display temperature in deg Celsius
display.setCursor(0,10);
display.setTextSize(3);
display.print(T);
display.print(" ");
display.cp437(true); // code page 437
display.write(167); // character 167 is degree
display.println("C");
display.display(); // for the changes to make effect
}