I'm trying to figure out how to display my output without any numbers beyond the whole number no decimal. for instance my code will display 72.20 degrees and I just want the 72 not the decimal or what comes beyond.
Watering1-1-19.ino (4.16 KB)
I'm trying to figure out how to display my output without any numbers beyond the whole number no decimal. for instance my code will display 72.20 degrees and I just want the 72 not the decimal or what comes beyond.
Watering1-1-19.ino (4.16 KB)
Hey,
I would 10/10 recommend you post the code that you're working with on here.
My first guess would be that you're using doubles instead of ints, the latter of which would give you nothing past the decimal point, which seems to be what you're looking for.
Hope that helps.
Post code inline, using code tags, as described in "How to use this forum".
When using Serial.print or Serial.println with floats, you can add an argument to specify the number of digits to display after the comma
Example
Serial.print (h, 0);
would display 10 if h was equal to 10.965
I believe it's the same with tft.print
Try it...
No, it prints "11"
The simplest approach is to change the variable type to int.
Try this
float aFloat = 123.55;
Serial.println(floor(aFloat),0);
Hello,
Im sorry I thought I attached my code in my first message. Thank you for the replies without it.
See code as follows
/* Evan S Gray
*
*/
// Libraries to include
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "DHT.h"
// Define pins For the Adafruit TFT shield, these are the default.
#define TFT_DC 9
#define TFT_CS 10
// what pin DHT sensor is connected to
#define DHTPIN 30
// what type of DHT sensor
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
// Color definitions
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
// If using the breakout, change pins as desired
void setup() {
// Begin Serial Comm
Serial.begin(9600);
Serial.println("ILI9341 Test!");
Serial.println("DHT test");
// Begin DHT11
dht.begin();
// Begin TFT
tft.begin();
//set screen rotation
tft.setRotation(1);
//fill screen black
tft.fillScreen(BLACK);
//set text wrap
tft.setTextWrap(true);
// Display text
tft.setCursor(0, 0);
tft.setTextColor(WHITE);
tft.setTextSize(1);
tft.println("Hello World!");
tft.setTextColor(RED);
tft.setTextSize(2);
tft.println("Welcome to the first");
tft.setTextColor(GREEN);
tft.setTextSize(3);
tft.println("Version of our Watering");
tft.setTextColor(BLUE);
tft.setTextSize(4);
tft.println("System");
delay(4000);
tft.fillScreen(BLACK);
}
// the loop routine runs over and over again forever:
void loop()
{
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
float t = dht.readTemperature();
// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t) || isnan(h)) {
Serial.println("Failed to read from DHT");
} else {
// Uncomment these lines if you prefer to use the Fahrenheit scale
// instead of Celsius. Remember to change line 44 so that the
// symbol is "F" instead of "C"
float fahrenheitTemp = t * 9.0/5.0+32.0;
Serial.print("Temperature: ");
Serial.print(fahrenheitTemp);
Serial.println(" F");
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
// read the input on analog pin 10
float sensorValue = analogRead(A10); //get current sensorValue between 0-1000
float Voltage = sensorValue*(5.0/1024.0); //convert sensorValue to voltage 0-5v
float pH = (Voltage*3.56)-1.889; //convert voltage to pH
// print out the value for pH
Serial.println("SensorValue");
Serial.println(sensorValue);
Serial.println("Voltage");
Serial.println(Voltage);
Serial.println("pH");
Serial.println(pH);
// print header
tft.setCursor(1,0);
tft.setTextSize(3);
tft.setTextColor(WHITE);
tft.println("GrayMatter");
tft.setCursor(25,25);
tft.println("Growers");
tft.drawRoundRect(210,10,90,45,25,WHITE);
tft.setCursor(230,15);
tft.setTextSize(2);
tft.setTextColor(WHITE);
tft.println("pH =");
tft.setCursor(230,33);
tft.println(pH); // print pH value 0-14
tft.drawRoundRect(210,65,90,45,25,WHITE);
tft.setCursor(230,70);
tft.setTextSize(2);
tft.setTextColor(WHITE);
tft.println("Temp");
tft.setCursor(230,88);
tft.println(fahrenheitTemp); // print temp value F
tft.drawRoundRect(210,120,90,45,25,WHITE);
tft.setCursor(230,125);
tft.setTextSize(2);
tft.setTextColor(WHITE);
tft.println("Hum =");
tft.setCursor(230,143);
tft.println(h); // print Humidity value %
tft.drawRoundRect(210,175,90,45,25,WHITE);
tft.setCursor(230,180);
tft.setTextSize(2);
tft.setTextColor(WHITE);
tft.println("cO2 =");
tft.setCursor(230,198);
tft.println(pH); // print cO2 value ppm
delay(10000); // delay in between reads for stability
tft.fillScreen(BLACK);
}
}
PaulS:
The simplest approach is to change the variable type to int.
so use int instead of float?
I don't quite understand the language so can you elaborate using my code?
@everone yeah that’s it! int should do the trick.
As for the request—I’d suggest trying find and replace first, then trying to sort out any issues. If you’re still having trouble, feel free to post again!
brightorange:
@everone yeah that’s it! int should do the trick.
As for the request—I’d suggest trying find and replace first, then trying to sort out any issues. If you’re still having trouble, feel free to post again!
So for instance just remove the float from below and replace it with int?
float h = dht.readHumidity();
float t = dht.readTemperature();
as follows
int h = dht.readHumidity();
int t = dht.readTemperature();
please elaborate on the syntax is the above correct?
Yes that worked thank you all