Dag allen,
Ik ben bezig met een aquariumcontrollertje met een arduino Mega en 3.2'' TFT. Wil hier simpel mijn temperatuur mee uitlezen/verwarming aansturen en pH uitlezen/CO2 aansturen.
Na behoorlijk wat inlezen, tutorials en proberen ben ik inmiddels al een aardig eind op weg en heb hiervoor een aantal pagina's geschreven waar ik op mijn tft e.e.a. kan uitlezen en instellen. Ik struikel op dit moment over het volgende:
om het verwarmingselement aan sturen (middels een relay aan/uit te zetten) tot mijn ingestelde temperatuur is bereikt, wil ik logischerwijs de temperatuur in kunnen stellen. Dit wil ik graag per 0.1 graad instellen. Nu is dat per 0.1 graad voor temperatuur niet zo relevant en kan ik gerust af met hele graden, maar ik heb exact dezelfde paginasetup voor pH en daarvoor is het wel van belang.
Vooralsnog kan ik de temperatuur instellen op hele graden, maar ik krijg het met decimalen niet voor elkaar. In eerste instantie probeerde ik
float count = 0.0, lastCount;
const float tempUpg = 0.1;
void loop ()
{
count < 28 ? "count+tempUpg" : count = 18;
}
maar krijg dan de foutmelding dat ik een const char met een int wil samenvoegen en dat kan niet. Ik heb al lopen zoeken naar het omzetten van floatings (floats?) naar iets anders, maar ik begrijp niet goed waarnaar ik het dan moet omzetten of hoe.
Zou iemand me op weg willen helpen? Hieronder de gehele code voor dit stuk van mijn project.
#include <memorysaver.h>
#include <UTFT.h>
#include <URTouch.h>
#include <URTouchCD.h>
UTFT myGLCD(ILI9341_16, 38, 39, 40, 41);
URTouch myTouch( 6, 5, 4, 3, 2);
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t Various_Symbols_32x32[];
float count = 0.0, lastCount;
int x, y;
const float tempUpg = 0.1;
int tempUp = 0;
int tempDown = 0;
void setup() {
myGLCD.InitLCD();
myGLCD.clrScr();
myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);
drawTemperatureSetting();
}
//==========Temp Config ============
void drawTemperatureSetting()
{
//====Back to Main button====
myGLCD.setColor(100, 155, 203);
myGLCD.fillRoundRect (270, 190, 310, 230);
myGLCD.setColor(255, 255, 255);
myGLCD.setFont(Various_Symbols_32x32);
myGLCD.setBackColor(100, 155, 203);
myGLCD.print("g", 275, 194);
myGLCD.drawRoundRect (270, 190, 310, 230);
//====Back to Settings button====
myGLCD.setColor(100, 155, 203);
myGLCD.fillRoundRect (220, 190, 260, 230);
myGLCD.setColor(255, 255, 255);
myGLCD.setFont(Various_Symbols_32x32);
myGLCD.setBackColor(100, 155, 203);
myGLCD.print("e", 225, 194);
myGLCD.drawRoundRect (220, 190, 260, 230);
//====Page Title====
myGLCD.setBackColor(0, 0, 0);
myGLCD.setFont(BigFont);
myGLCD.print("Temp config", CENTER, 10);
//====Current temp====
myGLCD.setFont(SmallFont);
myGLCD.print("Huidige temp:", 10, 36);
//==Current Set temp
myGLCD.setFont(SmallFont);
myGLCD.print("Huidige set temp:", 10, 56);
//====Line====
myGLCD.setColor(255, 0, 0);
myGLCD.drawLine(0, 78, 319, 78);
//====Select temp====
myGLCD.setBackColor(0, 0, 0);
myGLCD.setColor(255, 255, 255);
myGLCD.setFont(SmallFont);
myGLCD.print("Select temp", 10, 93);
//====New temp====
myGLCD.setFont(BigFont);
myGLCD.print("Nieuwe Temp:", 118, 89);
//myGLCD.setFont(SevenSegNumFont);
//myGLCD.printNumI(tempUpg, 160, 125);
//====Temp Up====
myGLCD.setColor(223, 77, 55);
myGLCD.fillRoundRect (10, 115, 90, 148);
myGLCD.setBackColor(223, 77, 55);
myGLCD.setColor(255, 255, 255);
myGLCD.setFont(Various_Symbols_32x32);
myGLCD.print("c", 35, 115);
myGLCD.drawRoundRect (10, 115, 90, 148);
//====Temp Down====
myGLCD.setColor(223, 77, 55);
myGLCD.fillRoundRect (10, 156, 90, 189);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (10, 156, 90, 189);
myGLCD.setBackColor(223, 77, 55);
myGLCD.setColor(255, 255, 255);
myGLCD.print("d", 35, 157);
}
// Highlights the button when pressed
void drawFrame(int x1, int y1, int x2, int y2)
{
myGLCD.setColor(255, 0, 0);
myGLCD.drawRoundRect (x1, y1, x2, y2);
while (myTouch.dataAvailable())
myTouch.read();
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (x1, y1, x2, y2);
}
void loop()
{
if (myTouch.dataAvailable())
{
myTouch.read();
x = myTouch.getX();
y = myTouch.getY();
// ==If we press the tempUp Button
if ((x >= 10) && (x <= 90) && (y >= 115) && (y <= 148))
{
count < 28 ? count++ : count = 18;
delay (200); // de delay zit erin omdat zonder, de waarde niet normaal is in te stellen. Zelfs bij de geringste aanraking schiet hij al omhoog/omlaag.
}
// ==If we press the tempDown Button
if ((x >= 10) && (x <= 90) && (y >= 156) && (y <= 189))
{
count > 18 ? count-- : count = 28;
delay (200);
}
}
if (count != lastCount)
{
myGLCD.setBackColor(0, 0, 0);
myGLCD.setColor(255, 255, 255);
myGLCD.setFont(BigFont);
myGLCD.printNumF(count, 1, 160, 125);
lastCount = count;
}
}