Sensor waardes op TFT weergeven

Arduino specifieke Software
Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: Sensor waardes op TFT weergeven

Berichtdoor nicoverduin » 08 Nov 2015, 14:22

benovitch schreef:Nico,

Bedankt vor je reactie maar al die programmeertaal is meestal chinees voor mij. Kan je eventueel de uitleg die je gegeven hebt uitleggen aan de hand van de waardes uit mijn sketch?
Soms als ik de sketch aanpas dan krijg ik het wel klaar dat de waarde van de sensor op de juiste pagina wordt weergegeven maar dan wordt de waarde niet geupdate.

Ben
De enige reden dat ik mijn stukje tekst hebt neergezet is omdat je de terminologie verkeerd gebruikt wat weer bij anderen verwarring veroorzaakt. Shooter was al bezig om je verder te helpen. Die zit er meer in als ik.
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Advertisement

Berichten: 24
Geregistreerd: 01 Sep 2013, 13:00

Re: Sensor waardes op TFT weergeven

Berichtdoor benovitch » 08 Nov 2015, 17:09

Ok bedankt Nico, dan wachten we maar af of Shooter mij verder kan helpen.

Berichten: 4067
Geregistreerd: 16 Okt 2013, 14:31
Woonplaats: s hertogenbosch

Re: Sensor waardes op TFT weergeven

Berichtdoor shooter » 09 Nov 2015, 09:58

als je het allemaal weer netjes hebt, graag je complete programma even zenden tussen de qoutes [code2=cpp] kijk op volledige reactiepagina.
ik kan je programma niet proberen want ik heb nog geen touchtft.
paul deelen
shooter@home.nl

Berichten: 24
Geregistreerd: 01 Sep 2013, 13:00

Re: Sensor waardes op TFT weergeven

Berichtdoor benovitch » 09 Nov 2015, 10:56

Shooter,

Ik heb het programma wat opgedeeld in verschillende tabbladen om het een beetje overzichterlijker te maken. Ik post ze deze avond.
Er zijn ondertussen wel al een paar velden grafisch aangepast maar dat zou niets Mogen doen aan het oorspronkelijk problem denk ik.
Avast bedankt.

Ben

Berichten: 24
Geregistreerd: 01 Sep 2013, 13:00

Re: Sensor waardes op TFT weergeven

Berichtdoor benovitch » 09 Nov 2015, 20:38

cpp code
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library
#include <TouchScreen.h>
#include <EEPROM.h>
/* For the 8 data pins:
Duemilanove/Diecimila/UNO/etc ('168 and '328 chips) microcontoller:
D0 connects to digital 22
D1 connects to digital 23
D2 connects to digital 24
D3 connects to digital 25
D4 connects to digital 26
D5 connects to digital 27
D6 connects to digital 28
D7 connects to digital 29
For Mega's use pins 22 thru 29 (on the double header at the end)
*/

#define YP A5 // must be an analog pin, use "An" notation! A1 for shield
#define XM A6 // must be an analog pin, use "An" notation! A2 for shield
#define YM 32 // mega=32
#define XP 33 // mega=33

#define TS_MINX 115
#define TS_MINY 77
#define TS_MAXX 906
#define TS_MAXY 940
// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 260);
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
// optional
#define LCD_RESET -1
// Color definitions - in 5:6:5
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define TEST 0x1BF5
#define JJCOLOR 0x1CB6
#define JJORNG 0xFD03

Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
int i = 0;
int page = 0;

int esleepeeprom;
int sleep = 0;
unsigned long sleeptime;

int blv;
int blveeprom;

int backlight = 10; //pin-10 uno pin-35 mega pin-3 for shield if you have done the MOD for PWM backlight
char Backlight [10];
int blvold;
int barv;

const long battcheck = 10000; // the amount of time between voltage check and battery icon refresh
unsigned long prevbatt;
int battfill;
int battsens;
int battv;
int battold;
int battpercent;
char battpercenttxt [10];

int prevpage;
int sleepnever;
int esleep;
int backlightbox;

const long weightcheck = 500;
unsigned long prevweight;
//int sensorpin = A8;
int Weightsensmap;
int Weightsens;
char Weight [10];
int Weightold;
int Gewicht();

unsigned long awakeend;
unsigned long currenttime;
unsigned long ssitime;
char voltage[10];


int MnToCoG = 0;
char MainToCoG [10];

int MnToCP = 0;
char MainToCP [10];

int MnToNose = 0;
char MainToNose [10];



void setup(void) {

//analogReference(5);
esleep = EEPROM.read(1);
blv = EEPROM.read(2);
if (esleep == 0 && blv == 0) { // if no previous saves then set sleep and backlight to default.
EEPROM.write(1, 4);
EEPROM.write(2, 200);
}
if (esleep == 1) {
sleeptime = 10000;
}
if (esleep == 2) {
sleeptime = 20000;
}
if (esleep == 3) {
sleeptime = 30000;
}
if (esleep == 4) {
sleeptime = 60000;
}
if (esleep == 5) {
sleeptime = 120000;
}
if (esleep == 6) {
sleeptime = 300000;
}
if (esleep == 7) {
sleeptime = 600000;
}
if (esleep == 8) {
sleepnever = 1;
}
awakeend = sleeptime + 30000; // set the current sleep time based on what the saved settings in EEPROM were
pinMode(backlight, OUTPUT);
Serial.begin(9600);
Serial.println("JOS");
Serial.println("Jeremy Saglimbeni (c) 2011");

tft.reset();

tft.begin(0x8357); //<---Here I bypassed the above. cause I already checked...
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-==-

tft.setRotation(1); //sets landscape mode
tft.fillScreen(BLACK);
tft.drawRect(50, 40, 380, 240, WHITE);
tft.fillRect(51, 41, 378, 238, JJCOLOR);
for (i = 0 ; i <= blv; i += 1) {
analogWrite(backlight, i);
delay(2);
}
delay(2);
tft.setTextSize(10);
tft.setTextColor(WHITE);
tft.setCursor(190, 45);
tft.println("CG");
tft.setTextSize(3);
tft.setTextColor(WHITE);
tft.setCursor(200, 130);
tft.println("Meter");
tft.setTextSize(3);
tft.setTextColor(WHITE);
tft.setCursor(233, 205);
tft.println("by");
tft.setTextSize(3);
tft.setTextColor(WHITE);
tft.setCursor(120, 240);
tft.println("Benovitch 2015");
delay(500);//introscreen delay
tft.fillScreen(BLACK);
tft.fillRect(0, 0, 480, 20, JJCOLOR);
tft.drawRect(445, 2, 30, 16, WHITE); //battery body
tft.fillRect(475, 6, 4, 8, WHITE); // battery tip
tft.fillRect(446, 3, 28, 14, BLACK); // clear the center of the battery
drawbatt();
homescr(); // draw the homescreen


}
#define MINPRESSURE 10
#define MAXPRESSURE 1000



void loop() {


currenttime = millis();
unsigned long currentawake = millis();
if ((currentawake > awakeend) && (sleepnever == 0)) {
if (sleep == 0) {
for (i = blv ; i >= 0; i -= 1) {
analogWrite(backlight, i);
delay(4);
}
sleep = 1;
}
}



TSPoint p = ts.getPoint();

if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
awakeend = currenttime + sleeptime; //set the sleep time when screen is pressed
if (sleep == 1) { // if asleep, then fade the backlight up
for (i = 0 ; i <= blv; i += 1) {
analogWrite(backlight, i);
delay(1);
}
sleep = 0; // change the sleep mode to "awake"
return;
}



// turn from 0->1023 to tft.width
p.x = map(p.x, TS_MINX, TS_MAXX, 0, 480);//default is (480, 0) [default puts touch cord. 0=x/y upper right.
p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320);//default is (320, 0) [I change these cause i like 0=xy bottom left.

Serial.print("p.y:"); // this code will help you get the y and x numbers for the touchscreen
Serial.print(p.y);
Serial.print(" p.x:");
Serial.println(p.x);


//WEIGHT Button
if (p.y > 12 && p.y < 75 && p.x > 24 && p.x < 71) {
if (page == 1) {
if (currenttime - prevweight > weightcheck) {
prevweight = currenttime;
// link to action
}
}
if (page == 0) { // if you are on the "home" page (0)
page = 1; // then you just went to the first page
redraw(); // redraw the screen with the page value 1, giving you the page 1 menu
}
}
//CoG Button
if (p.y > 88 && p.y < 148 && p.x > 24 && p.x < 71) {
if (page == 1) {

}
if (page == 0) { // if you are on the "home" page (0)
page = 2; // then you just went to the 2e page
redraw(); // redraw the screen with the page value 1, giving you the page 1 menu
}
}
// CoG Settings pagina
if (p.y > 241 && p.y < 297 && p.x > 24 && p.x < 71) {
if (page == 2) {
}
if (page == 2) { // if you are on the "home" page (0)
page = 5; // then you just went to the 2e page
redraw(); // redraw the screen with the page value 1, giving you the page 1 menu
}
}
//Back < Button
if (p.y > 4 && p.y < 18 && p.x > 409 && p.x < 444) {
if (page == 5) {

}
if (page == 5) { // if you are on the "home" page (0)
page = 2; // then you just went to the 2e page
redraw(); // redraw the screen with the page value 1, giving you the page 1 menu
}
}


//BALANCE Button
if (p.y > 163 && p.y < 226 && p.x > 24 && p.x < 71) {
if (page == 3) {

}
if (page == 0) { // if you are on the "home" page (0)
page = 3; // then you just went to the 3e page
redraw(); // redraw the screen with the page value 1, giving you the page 1 menu
}
}
//SETTINGS Button
if (p.y > 241 && p.y < 297 && p.x > 24 && p.x < 71) {
if (page == 4) {

}
if (page == 0) { // if you are on the "home" page (0)
page = 4; // then you just went to the 4e page
redraw(); // redraw the screen with the page value 1, giving you the page 1 menu
}
}

// TARE button
if (p.y > 241 && p.y < 297 && p.x > 24 && p.x < 71) {
if (page == 1) {
delay(200);
m1b1action();
}
}



// home
if (p.y > 288 && p.y < 312 && p.x > 392 && p.x < 443) { // if the home icon is pressed
if (page == 4) { // if you are leaving the settings page
//clearmessage(); // clear the battery voltage out of the message box
clearstatus ();
esleepeeprom = EEPROM.read(1);
blveeprom = EEPROM.read(2);
if (esleep != esleepeeprom || blv != blveeprom)
{
EEPROM.write(1, esleep);
EEPROM.write(2, blveeprom);

tft.setCursor(20, 3);
tft.setTextColor(RED);
tft.setTextSize(2);
tft.println("Settings Saved"); // display settings saved in message box
}
else
{

tft.setCursor(20, 3);
tft.setTextColor(GREEN);
tft.setTextSize(2);
tft.println("No Changes Made");
}
}
if (page = prevpage); { // a value to keep track of what WAS on the screen to redraw/erase only what needs to be
page = 0; // make the current page home
redraw(); // redraw the page
}

}

// backlight buttons
if (p.y > 4 && p.y < 36 && p.x > 384 && p.x < 447) { //-
if (page == 4) {
blightdown();
}
}
if (p.y > 173 && p.y < 208 && p.x > 387 && p.x < 447) { //+
if (page == 4) {
blightup();
}
}

// Main To CoG butons +1
if (p.y > 243 && p.y < 256 && p.x > 322 && p.x < 347) {
if (page == 5) {
delay(250);
MaintoCoGUP();
}
}
if (p.y > 172 && p.y < 183 && p.x > 322 && p.x < 347) {
if (page == 5) {
delay(250);
MaintoCoGDOWN();
}
}
// Main To CoG butons +10
if (p.y > 262 && p.y < 276 && p.x > 322 && p.x < 347) {
if (page == 5) {
delay(75);
MaintoCoGUP10();
}
}
if (p.y > 153 && p.y < 165 && p.x > 322 && p.x < 347) {
if (page == 5) {
delay(75);
MaintoCoGDOWN10();
}
}
//DEL button Main To CoG
if (p.y > 281 && p.y < 316 && p.x > 322 && p.x < 347) {
if (page == 5) {
MaintoCoGDEL();
}
}

// Main To CP butons +1
if (p.y > 243 && p.y < 256 && p.x >268 && p.x < 300) {
if (page == 5) {
delay(250);
MaintoCPUP();
}
}
if (p.y > 173 && p.y < 185 && p.x > 268 && p.x < 300) {
if (page == 5) {
delay(250);
MaintoCPDOWN();
}
}
// Main To CP butons +10
if (p.y > 262 && p.y < 275 && p.x > 268 && p.x < 300) {
if (page == 5) {
delay(75);
MaintoCPUP10();
}
}
if (p.y > 153 && p.y < 166 && p.x > 268 && p.x < 300) {
if (page == 5) {
delay(75);
MaintoCPDOWN10();
}
}
//DEL button Main To CP
if (p.y > 280 && p.y < 316 && p.x > 268 && p.x < 300) {
if (page == 5) {
MaintoCPDEL();
}
}

// Main To Nose butons +1
if (p.y > 243 && p.y < 256 && p.x >222 && p.x < 248) {
if (page == 5) {
delay(250);
MaintoNoseUP();
}
}
if (p.y > 172 && p.y < 186 && p.x > 222 && p.x < 248) {
if (page == 5) {
delay(250);
MaintoNoseDOWN();
}
}
// Main To Nose butons +10
if (p.y > 262 && p.y < 275 && p.x > 222 && p.x < 248) {
if (page == 5) {
delay(75);
MaintoNoseUP10();
}
}
if (p.y > 153 && p.y < 166 && p.x > 222 && p.x < 248) {
if (page == 5) {
delay(75);
MaintoNoseDOWN10();
}
}
//DEL button Main To Nose
if (p.y > 280 && p.y < 316 && p.x > 223 && p.x < 248) {
if (page == 5) {
MaintoNoseDEL();
}
}


// sleep buttons
if (p.y > 4 && p.y < 33 && p.x > 296 && p.x < 361) {
if (page == 4) {
sleepdec();
}
}
if (p.y > 173 && p.y < 210 && p.x > 296 && p.x < 361) {
if (page == 4) {
sleepinc();
}
}
}



if (currenttime - prevbatt > battcheck) {
prevbatt = currenttime;
drawbatt();
}

/*if (currenttime - prevweight > weightcheck){
prevweight = currenttime;
Gewicht();
}*/

}
// einde main LOOP

void redraw() { // redraw the page
if ((prevpage != 4) || (page != 5)) {
//clearcenter();
}
if (page == 0) {
homescr();
}
if (page == 1) {
WEIGHT();
}
if (page == 2) {
CoG();
}
if (page == 3) {
BALANCE();
}
if (page == 4) {
settingsscr();
}
if (page == 5) {
CoGsettingsscr();
}
}
void clearcenter() { // the reason for so many small "boxes" is that it's faster than filling the whole thing
tft.fillRect(0, 20, 480, 300, BLACK);
}
void clearstatus() { // this is used to erase the extra drawings when exiting the settings page
tft.fillRect(0, 0, 444, 20, JJCOLOR);
}

/*
void decimate(char test[],int dec) { // creates decimal function decimate(string containing integer, number of decimal places)

int i=0;
int length=strlen(test);
char msg[10]="";

strcpy(msg,test);

if (length <= dec) {
for(i=dec;i>(dec-length);i--) msg[i] = msg[i-(dec-length+1)];
for(i=0;i<(dec+1-length);i++) msg[i]='0';
length = strlen(msg);
}
for (i=length;i>(length-dec);i--) msg[i]=msg[i-1];
msg[length-dec]='.';

strcpy(test,msg);
} */

void sleepinc() { // sleep increese adjustment
if (sleeptime == 600000) {
sleepnever = 1;
esleep = 8;
sleeptime = 11111111;
showsleep();
}
if (sleeptime == 300000) {
sleeptime = 600000;
esleep = 7;
showsleep();
}
if (sleeptime == 120000) {
sleeptime = 300000;
esleep = 6;
showsleep();
}
if (sleeptime == 60000) {
sleeptime = 120000;
esleep = 5;
showsleep();
}
if (sleeptime == 30000) {
sleeptime = 60000;
esleep = 4;
showsleep();
}
if (sleeptime == 20000) {
sleeptime = 30000;
esleep = 3;
showsleep();
}
if (sleeptime == 10000) {
sleeptime = 20000;
esleep = 2;
showsleep();
}
delay(350);
}
void sleepdec() { // sleep decreese adjustment
if (sleeptime == 20000) {
sleeptime = 10000;
esleep = 1;
showsleep();
}
if (sleeptime == 30000) {
sleeptime = 20000;
esleep = 2;
showsleep();
}
if (sleeptime == 60000) {
sleeptime = 30000;
esleep = 3;
showsleep();
}
if (sleeptime == 120000) {
sleeptime = 60000;
esleep = 4;
showsleep();
}
if (sleeptime == 300000) {
sleeptime = 120000;
esleep = 5;
showsleep();
}
if (sleeptime == 600000) {
sleeptime = 300000;
esleep = 6;
showsleep();
}
if (sleepnever == 1) {
sleeptime = 600000;
sleepnever = 0;
esleep = 7;
showsleep();
}
delay(350);
}
void showsleep() { // shows the sleep time on the settings page
tft.fillRect(110, 108, 80, 10, BLACK);
tft.setTextColor(WHITE);
tft.setTextSize(1);
if (sleeptime == 10000) {
tft.setCursor(130, 108);
tft.println("10 Seconds");
}
if (sleeptime == 20000) {
tft.setCursor(130, 108);
tft.println("20 Seconds");
}
if (sleeptime == 30000) {
tft.setCursor(130, 108);
tft.println("30 Seconds");
}
if (sleeptime == 60000) {
tft.setCursor(136, 108);
tft.println("1 Minute");
}
if (sleeptime == 120000) {
tft.setCursor(133, 108);
tft.println("2 Minutes");
}
if (sleeptime == 300000) {
tft.setCursor(133, 108);
tft.println("5 Minutes");
}
if (sleeptime == 600000) {
tft.setCursor(130, 108);
tft.println("10 Minutes");
}
if (sleepnever == 1) {
tft.setCursor(133, 108);
tft.println("Always On");
}
}
//void blightup100() { // adjust option 3 down in the settings screen
//}
//void blightdown100() { // adjust option 3 up in the settings screen
//}
//custom defined actions - this is where you put your button functions

void clearmessage() {
tft.fillRect(12, 213, 226, 16, BLACK); // black out the inside of the message box
}
void drawbatt() {
battv = analogRead(A10); // read the voltage
//battsens = map(battv,0 , 1023, 0, 5);

if (battv < battold) { // if the voltage goes down, erase the inside of the battery
tft.fillRect(446, 3, 28, 14, BLACK);

}
battfill = map(battv, 0, 1023, 2, 28); // map the battery voltage 300 is the low, 415 is the high
battfill = constrain(battfill, 2, 28); // constrains batt display limits
if (battfill > 8) { // if the battfill value is between 8 and 18, fill with green
tft.fillRect(446, 3, battfill, 14, GREEN);
//Serial.println(battfill);
}
else { // if the battfill value is below 8, fill with red
tft.fillRect(446, 3, battfill, 14, RED);
}
battold = battv; // this helps determine if redrawing the battfill area is necessary
}

void MnToCogDist() {

itoa(MnToCoG, MainToCoG, 10);
tft.setTextSize(3);
tft.setTextColor(WHITE);
tft.fillRect(287, 89, 73, 22, BLACK);
tft.setCursor(290, 90);
tft.print(MainToCoG);
}
void MnToCPDist() {

itoa (MnToCP, MainToCP, 10);
tft.setTextColor(WHITE);
tft.fillRect(287, 121, 73, 23, BLACK);
tft.setCursor(290,122);
tft.print(MainToCP);
}

void MnToNoseDist() {

itoa (MnToNose, MainToNose, 10);
tft.setTextColor(WHITE);
tft.fillRect(287, 153, 73, 23, BLACK);
tft.setCursor(290, 153);
tft.print(MainToNose);
}


void blbar() { // this function fills the yellow bar in the backlight brightness adjustment
if (blv < barv) {
tft.fillRect(111, 49, 98, 8, BLACK);
}
itoa (blv, Backlight, 10);
backlightbox = map(blv, 1, 255, 0, 98);
tft.fillRect(111, 49, backlightbox, 8, YELLOW);
barv = blv;

tft.fillRect(20, 240, 100, 21, BLACK);
tft.setCursor(20, 240);
tft.setTextColor(WHITE);
tft.print(Backlight);

}
int Gewicht() {
Weightsens = analogRead (A8);
Weightsensmap = map(Weightsens, 0, 1023, 0, 1000);
itoa (Weightsensmap, Weight, 10);
//Serial.println(Weightsens);
// Serial.println (Weight);

if (Weightsensmap != Weightold) {
tft.setTextSize(2);
tft.setCursor(20, 240);
tft.setTextColor(BLACK);
tft.print(Weight);
delay(10);
tft.fillRect(20, 240, 100, 20, BLACK);
tft.setCursor(20, 240);
tft.setTextColor(WHITE);
tft.print(Weight);
Weightold = Weightsensmap;
}
}
/*
void drawbattvoltage(){
battv = analogRead(A10); // read the voltage ANalog 1
battpercent = (battv / 480) * 100, 2; // if using battery set 480(4.80v) to fresh charge value
battpercent = constrain(battpercent, 1, 100); // battery percent between 1% and 100%
itoa (battpercent, battpercenttxt, 10);
tft.setTextColor(YELLOW);
tft.setTextSize(2);
tft.setCursor(390, 4);
tft.println(battpercenttxt);
tft.setTextColor(YELLOW);
tft.setTextSize(2);
tft.setCursor(430, 4);
tft.println("%");

}
void drawbattpercent(){

battv = analogRead(A10);// read the voltage Analog 10
battpercent = map(battv, 0, 1024, 0,100);
//battpercent = (battv / 480) * 100, 2; // if using battery set 480(4.80v) to fresh charge value
battpercent = constrain(battpercent, 1, 100); // battery percent between 1% and 100%
itoa (battpercent, battpercenttxt, 10);
tft.setTextColor(YELLOW);
tft.setTextSize(2);
tft.setCursor(390, 4);
tft.println(battpercenttxt);
delay(250);
tft.setTextColor(JJCOLOR);
tft.setTextSize(2);
tft.setCursor(390, 4);
tft.println(battpercenttxt);
tft.setTextColor(YELLOW);
tft.setTextSize(2);
tft.setCursor(430, 4);
tft.println("%");
}*/


de acties:
cpp code
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library
#include <TouchScreen.h>
#include <EEPROM.h>
/* For the 8 data pins:
Duemilanove/Diecimila/UNO/etc ('168 and '328 chips) microcontoller:
D0 connects to digital 22
D1 connects to digital 23
D2 connects to digital 24
D3 connects to digital 25
D4 connects to digital 26
D5 connects to digital 27
D6 connects to digital 28
D7 connects to digital 29
For Mega's use pins 22 thru 29 (on the double header at the end)
*/

#define YP A5 // must be an analog pin, use "An" notation! A1 for shield
#define XM A6 // must be an analog pin, use "An" notation! A2 for shield
#define YM 32 // mega=32
#define XP 33 // mega=33

#define TS_MINX 115
#define TS_MINY 77
#define TS_MAXX 906
#define TS_MAXY 940
// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 260);
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
// optional
#define LCD_RESET -1
// Color definitions - in 5:6:5
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define TEST 0x1BF5
#define JJCOLOR 0x1CB6
#define JJORNG 0xFD03

Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
int i = 0;
int page = 0;

int esleepeeprom;
int sleep = 0;
unsigned long sleeptime;

int blv;
int blveeprom;

int backlight = 10; //pin-10 uno pin-35 mega pin-3 for shield if you have done the MOD for PWM backlight
char Backlight [10];
int blvold;
int barv;

const long battcheck = 10000; // the amount of time between voltage check and battery icon refresh
unsigned long prevbatt;
int battfill;
int battsens;
int battv;
int battold;
int battpercent;
char battpercenttxt [10];

int prevpage;
int sleepnever;
int esleep;
int backlightbox;

const long weightcheck = 500;
unsigned long prevweight;
//int sensorpin = A8;
int Weightsensmap;
int Weightsens;
char Weight [10];
int Weightold;
int Gewicht();

unsigned long awakeend;
unsigned long currenttime;
unsigned long ssitime;
char voltage[10];


int MnToCoG = 0;
char MainToCoG [10];

int MnToCP = 0;
char MainToCP [10];

int MnToNose = 0;
char MainToNose [10];



void setup(void) {

//analogReference(5);
esleep = EEPROM.read(1);
blv = EEPROM.read(2);
if (esleep == 0 && blv == 0) { // if no previous saves then set sleep and backlight to default.
EEPROM.write(1, 4);
EEPROM.write(2, 200);
}
if (esleep == 1) {
sleeptime = 10000;
}
if (esleep == 2) {
sleeptime = 20000;
}
if (esleep == 3) {
sleeptime = 30000;
}
if (esleep == 4) {
sleeptime = 60000;
}
if (esleep == 5) {
sleeptime = 120000;
}
if (esleep == 6) {
sleeptime = 300000;
}
if (esleep == 7) {
sleeptime = 600000;
}
if (esleep == 8) {
sleepnever = 1;
}
awakeend = sleeptime + 30000; // set the current sleep time based on what the saved settings in EEPROM were
pinMode(backlight, OUTPUT);
Serial.begin(9600);
Serial.println("JOS");
Serial.println("Jeremy Saglimbeni (c) 2011");

tft.reset();

tft.begin(0x8357); //<---Here I bypassed the above. cause I already checked...
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-==-

tft.setRotation(1); //sets landscape mode
tft.fillScreen(BLACK);
tft.drawRect(50, 40, 380, 240, WHITE);
tft.fillRect(51, 41, 378, 238, JJCOLOR);
for (i = 0 ; i <= blv; i += 1) {
analogWrite(backlight, i);
delay(2);
}
delay(2);
tft.setTextSize(10);
tft.setTextColor(WHITE);
tft.setCursor(190, 45);
tft.println("CG");
tft.setTextSize(3);
tft.setTextColor(WHITE);
tft.setCursor(200, 130);
tft.println("Meter");
tft.setTextSize(3);
tft.setTextColor(WHITE);
tft.setCursor(233, 205);
tft.println("by");
tft.setTextSize(3);
tft.setTextColor(WHITE);
tft.setCursor(120, 240);
tft.println("Benovitch 2015");
delay(500);//introscreen delay
tft.fillScreen(BLACK);
tft.fillRect(0, 0, 480, 20, JJCOLOR);
tft.drawRect(445, 2, 30, 16, WHITE); //battery body
tft.fillRect(475, 6, 4, 8, WHITE); // battery tip
tft.fillRect(446, 3, 28, 14, BLACK); // clear the center of the battery
drawbatt();
homescr(); // draw the homescreen


}
#define MINPRESSURE 10
#define MAXPRESSURE 1000



void loop() {


currenttime = millis();
unsigned long currentawake = millis();
if ((currentawake > awakeend) && (sleepnever == 0)) {
if (sleep == 0) {
for (i = blv ; i >= 0; i -= 1) {
analogWrite(backlight, i);
delay(4);
}
sleep = 1;
}
}



TSPoint p = ts.getPoint();

if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
awakeend = currenttime + sleeptime; //set the sleep time when screen is pressed
if (sleep == 1) { // if asleep, then fade the backlight up
for (i = 0 ; i <= blv; i += 1) {
analogWrite(backlight, i);
delay(1);
}
sleep = 0; // change the sleep mode to "awake"
return;
}



// turn from 0->1023 to tft.width
p.x = map(p.x, TS_MINX, TS_MAXX, 0, 480);//default is (480, 0) [default puts touch cord. 0=x/y upper right.
p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320);//default is (320, 0) [I change these cause i like 0=xy bottom left.

Serial.print("p.y:"); // this code will help you get the y and x numbers for the touchscreen
Serial.print(p.y);
Serial.print(" p.x:");
Serial.println(p.x);


//WEIGHT Button
if (p.y > 12 && p.y < 75 && p.x > 24 && p.x < 71) {
if (page == 1) {
if (currenttime - prevweight > weightcheck) {
prevweight = currenttime;
// link to action
}
}
if (page == 0) { // if you are on the "home" page (0)
page = 1; // then you just went to the first page
redraw(); // redraw the screen with the page value 1, giving you the page 1 menu
}
}
//CoG Button
if (p.y > 88 && p.y < 148 && p.x > 24 && p.x < 71) {
if (page == 1) {

}
if (page == 0) { // if you are on the "home" page (0)
page = 2; // then you just went to the 2e page
redraw(); // redraw the screen with the page value 1, giving you the page 1 menu
}
}
// CoG Settings pagina
if (p.y > 241 && p.y < 297 && p.x > 24 && p.x < 71) {
if (page == 2) {
}
if (page == 2) { // if you are on the "home" page (0)
page = 5; // then you just went to the 2e page
redraw(); // redraw the screen with the page value 1, giving you the page 1 menu
}
}
//Back < Button
if (p.y > 4 && p.y < 18 && p.x > 409 && p.x < 444) {
if (page == 5) {

}
if (page == 5) { // if you are on the "home" page (0)
page = 2; // then you just went to the 2e page
redraw(); // redraw the screen with the page value 1, giving you the page 1 menu
}
}


//BALANCE Button
if (p.y > 163 && p.y < 226 && p.x > 24 && p.x < 71) {
if (page == 3) {

}
if (page == 0) { // if you are on the "home" page (0)
page = 3; // then you just went to the 3e page
redraw(); // redraw the screen with the page value 1, giving you the page 1 menu
}
}
//SETTINGS Button
if (p.y > 241 && p.y < 297 && p.x > 24 && p.x < 71) {
if (page == 4) {

}
if (page == 0) { // if you are on the "home" page (0)
page = 4; // then you just went to the 4e page
redraw(); // redraw the screen with the page value 1, giving you the page 1 menu
}
}

// TARE button
if (p.y > 241 && p.y < 297 && p.x > 24 && p.x < 71) {
if (page == 1) {
delay(200);
m1b1action();
}
}



// home
if (p.y > 288 && p.y < 312 && p.x > 392 && p.x < 443) { // if the home icon is pressed
if (page == 4) { // if you are leaving the settings page
//clearmessage(); // clear the battery voltage out of the message box
clearstatus ();
esleepeeprom = EEPROM.read(1);
blveeprom = EEPROM.read(2);
if (esleep != esleepeeprom || blv != blveeprom)
{
EEPROM.write(1, esleep);
EEPROM.write(2, blveeprom);

tft.setCursor(20, 3);
tft.setTextColor(RED);
tft.setTextSize(2);
tft.println("Settings Saved"); // display settings saved in message box
}
else
{

tft.setCursor(20, 3);
tft.setTextColor(GREEN);
tft.setTextSize(2);
tft.println("No Changes Made");
}
}
if (page = prevpage); { // a value to keep track of what WAS on the screen to redraw/erase only what needs to be
page = 0; // make the current page home
redraw(); // redraw the page
}

}

// backlight buttons
if (p.y > 4 && p.y < 36 && p.x > 384 && p.x < 447) { //-
if (page == 4) {
blightdown();
}
}
if (p.y > 173 && p.y < 208 && p.x > 387 && p.x < 447) { //+
if (page == 4) {
blightup();
}
}

// Main To CoG butons +1
if (p.y > 243 && p.y < 256 && p.x > 322 && p.x < 347) {
if (page == 5) {
delay(250);
MaintoCoGUP();
}
}
if (p.y > 172 && p.y < 183 && p.x > 322 && p.x < 347) {
if (page == 5) {
delay(250);
MaintoCoGDOWN();
}
}
// Main To CoG butons +10
if (p.y > 262 && p.y < 276 && p.x > 322 && p.x < 347) {
if (page == 5) {
delay(75);
MaintoCoGUP10();
}
}
if (p.y > 153 && p.y < 165 && p.x > 322 && p.x < 347) {
if (page == 5) {
delay(75);
MaintoCoGDOWN10();
}
}
//DEL button Main To CoG
if (p.y > 281 && p.y < 316 && p.x > 322 && p.x < 347) {
if (page == 5) {
MaintoCoGDEL();
}
}

// Main To CP butons +1
if (p.y > 243 && p.y < 256 && p.x >268 && p.x < 300) {
if (page == 5) {
delay(250);
MaintoCPUP();
}
}
if (p.y > 173 && p.y < 185 && p.x > 268 && p.x < 300) {
if (page == 5) {
delay(250);
MaintoCPDOWN();
}
}
// Main To CP butons +10
if (p.y > 262 && p.y < 275 && p.x > 268 && p.x < 300) {
if (page == 5) {
delay(75);
MaintoCPUP10();
}
}
if (p.y > 153 && p.y < 166 && p.x > 268 && p.x < 300) {
if (page == 5) {
delay(75);
MaintoCPDOWN10();
}
}
//DEL button Main To CP
if (p.y > 280 && p.y < 316 && p.x > 268 && p.x < 300) {
if (page == 5) {
MaintoCPDEL();
}
}

// Main To Nose butons +1
if (p.y > 243 && p.y < 256 && p.x >222 && p.x < 248) {
if (page == 5) {
delay(250);
MaintoNoseUP();
}
}
if (p.y > 172 && p.y < 186 && p.x > 222 && p.x < 248) {
if (page == 5) {
delay(250);
MaintoNoseDOWN();
}
}
// Main To Nose butons +10
if (p.y > 262 && p.y < 275 && p.x > 222 && p.x < 248) {
if (page == 5) {
delay(75);
MaintoNoseUP10();
}
}
if (p.y > 153 && p.y < 166 && p.x > 222 && p.x < 248) {
if (page == 5) {
delay(75);
MaintoNoseDOWN10();
}
}
//DEL button Main To Nose
if (p.y > 280 && p.y < 316 && p.x > 223 && p.x < 248) {
if (page == 5) {
MaintoNoseDEL();
}
}


// sleep buttons
if (p.y > 4 && p.y < 33 && p.x > 296 && p.x < 361) {
if (page == 4) {
sleepdec();
}
}
if (p.y > 173 && p.y < 210 && p.x > 296 && p.x < 361) {
if (page == 4) {
sleepinc();
}
}
}



if (currenttime - prevbatt > battcheck) {
prevbatt = currenttime;
drawbatt();
}

/*if (currenttime - prevweight > weightcheck){
prevweight = currenttime;
Gewicht();
}*/

}
// einde main LOOP

void redraw() { // redraw the page
if ((prevpage != 4) || (page != 5)) {
//clearcenter();
}
if (page == 0) {
homescr();
}
if (page == 1) {
WEIGHT();
}
if (page == 2) {
CoG();
}
if (page == 3) {
BALANCE();
}
if (page == 4) {
settingsscr();
}
if (page == 5) {
CoGsettingsscr();
}
}
void clearcenter() { // the reason for so many small "boxes" is that it's faster than filling the whole thing
tft.fillRect(0, 20, 480, 300, BLACK);
}
void clearstatus() { // this is used to erase the extra drawings when exiting the settings page
tft.fillRect(0, 0, 444, 20, JJCOLOR);
}

/*
void decimate(char test[],int dec) { // creates decimal function decimate(string containing integer, number of decimal places)

int i=0;
int length=strlen(test);
char msg[10]="";

strcpy(msg,test);

if (length <= dec) {
for(i=dec;i>(dec-length);i--) msg[i] = msg[i-(dec-length+1)];
for(i=0;i<(dec+1-length);i++) msg[i]='0';
length = strlen(msg);
}
for (i=length;i>(length-dec);i--) msg[i]=msg[i-1];
msg[length-dec]='.';

strcpy(test,msg);
} */

void sleepinc() { // sleep increese adjustment
if (sleeptime == 600000) {
sleepnever = 1;
esleep = 8;
sleeptime = 11111111;
showsleep();
}
if (sleeptime == 300000) {
sleeptime = 600000;
esleep = 7;
showsleep();
}
if (sleeptime == 120000) {
sleeptime = 300000;
esleep = 6;
showsleep();
}
if (sleeptime == 60000) {
sleeptime = 120000;
esleep = 5;
showsleep();
}
if (sleeptime == 30000) {
sleeptime = 60000;
esleep = 4;
showsleep();
}
if (sleeptime == 20000) {
sleeptime = 30000;
esleep = 3;
showsleep();
}
if (sleeptime == 10000) {
sleeptime = 20000;
esleep = 2;
showsleep();
}
delay(350);
}
void sleepdec() { // sleep decreese adjustment
if (sleeptime == 20000) {
sleeptime = 10000;
esleep = 1;
showsleep();
}
if (sleeptime == 30000) {
sleeptime = 20000;
esleep = 2;
showsleep();
}
if (sleeptime == 60000) {
sleeptime = 30000;
esleep = 3;
showsleep();
}
if (sleeptime == 120000) {
sleeptime = 60000;
esleep = 4;
showsleep();
}
if (sleeptime == 300000) {
sleeptime = 120000;
esleep = 5;
showsleep();
}
if (sleeptime == 600000) {
sleeptime = 300000;
esleep = 6;
showsleep();
}
if (sleepnever == 1) {
sleeptime = 600000;
sleepnever = 0;
esleep = 7;
showsleep();
}
delay(350);
}
void showsleep() { // shows the sleep time on the settings page
tft.fillRect(110, 108, 80, 10, BLACK);
tft.setTextColor(WHITE);
tft.setTextSize(1);
if (sleeptime == 10000) {
tft.setCursor(130, 108);
tft.println("10 Seconds");
}
if (sleeptime == 20000) {
tft.setCursor(130, 108);
tft.println("20 Seconds");
}
if (sleeptime == 30000) {
tft.setCursor(130, 108);
tft.println("30 Seconds");
}
if (sleeptime == 60000) {
tft.setCursor(136, 108);
tft.println("1 Minute");
}
if (sleeptime == 120000) {
tft.setCursor(133, 108);
tft.println("2 Minutes");
}
if (sleeptime == 300000) {
tft.setCursor(133, 108);
tft.println("5 Minutes");
}
if (sleeptime == 600000) {
tft.setCursor(130, 108);
tft.println("10 Minutes");
}
if (sleepnever == 1) {
tft.setCursor(133, 108);
tft.println("Always On");
}
}
//void blightup100() { // adjust option 3 down in the settings screen
//}
//void blightdown100() { // adjust option 3 up in the settings screen
//}
//custom defined actions - this is where you put your button functions

void clearmessage() {
tft.fillRect(12, 213, 226, 16, BLACK); // black out the inside of the message box
}
void drawbatt() {
battv = analogRead(A10); // read the voltage
//battsens = map(battv,0 , 1023, 0, 5);

if (battv < battold) { // if the voltage goes down, erase the inside of the battery
tft.fillRect(446, 3, 28, 14, BLACK);

}
battfill = map(battv, 0, 1023, 2, 28); // map the battery voltage 300 is the low, 415 is the high
battfill = constrain(battfill, 2, 28); // constrains batt display limits
if (battfill > 8) { // if the battfill value is between 8 and 18, fill with green
tft.fillRect(446, 3, battfill, 14, GREEN);
//Serial.println(battfill);
}
else { // if the battfill value is below 8, fill with red
tft.fillRect(446, 3, battfill, 14, RED);
}
battold = battv; // this helps determine if redrawing the battfill area is necessary
}

void MnToCogDist() {

itoa(MnToCoG, MainToCoG, 10);
tft.setTextSize(3);
tft.setTextColor(WHITE);
tft.fillRect(287, 89, 73, 22, BLACK);
tft.setCursor(290, 90);
tft.print(MainToCoG);
}
void MnToCPDist() {

itoa (MnToCP, MainToCP, 10);
tft.setTextColor(WHITE);
tft.fillRect(287, 121, 73, 23, BLACK);
tft.setCursor(290,122);
tft.print(MainToCP);
}

void MnToNoseDist() {

itoa (MnToNose, MainToNose, 10);
tft.setTextColor(WHITE);
tft.fillRect(287, 153, 73, 23, BLACK);
tft.setCursor(290, 153);
tft.print(MainToNose);
}


void blbar() { // this function fills the yellow bar in the backlight brightness adjustment
if (blv < barv) {
tft.fillRect(111, 49, 98, 8, BLACK);
}
itoa (blv, Backlight, 10);
backlightbox = map(blv, 1, 255, 0, 98);
tft.fillRect(111, 49, backlightbox, 8, YELLOW);
barv = blv;

tft.fillRect(20, 240, 100, 21, BLACK);
tft.setCursor(20, 240);
tft.setTextColor(WHITE);
tft.print(Backlight);

}
int Gewicht() {
Weightsens = analogRead (A8);
Weightsensmap = map(Weightsens, 0, 1023, 0, 1000);
itoa (Weightsensmap, Weight, 10);
//Serial.println(Weightsens);
// Serial.println (Weight);

if (Weightsensmap != Weightold) {
tft.setTextSize(2);
tft.setCursor(20, 240);
tft.setTextColor(BLACK);
tft.print(Weight);
delay(10);
tft.fillRect(20, 240, 100, 20, BLACK);
tft.setCursor(20, 240);
tft.setTextColor(WHITE);
tft.print(Weight);
Weightold = Weightsensmap;
}
}
/*
void drawbattvoltage(){
battv = analogRead(A10); // read the voltage ANalog 1
battpercent = (battv / 480) * 100, 2; // if using battery set 480(4.80v) to fresh charge value
battpercent = constrain(battpercent, 1, 100); // battery percent between 1% and 100%
itoa (battpercent, battpercenttxt, 10);
tft.setTextColor(YELLOW);
tft.setTextSize(2);
tft.setCursor(390, 4);
tft.println(battpercenttxt);
tft.setTextColor(YELLOW);
tft.setTextSize(2);
tft.setCursor(430, 4);
tft.println("%");

}
void drawbattpercent(){

battv = analogRead(A10);// read the voltage Analog 10
battpercent = map(battv, 0, 1024, 0,100);
//battpercent = (battv / 480) * 100, 2; // if using battery set 480(4.80v) to fresh charge value
battpercent = constrain(battpercent, 1, 100); // battery percent between 1% and 100%
itoa (battpercent, battpercenttxt, 10);
tft.setTextColor(YELLOW);
tft.setTextSize(2);
tft.setCursor(390, 4);
tft.println(battpercenttxt);
delay(250);
tft.setTextColor(JJCOLOR);
tft.setTextSize(2);
tft.setCursor(390, 4);
tft.println(battpercenttxt);
tft.setTextColor(YELLOW);
tft.setTextSize(2);
tft.setCursor(430, 4);
tft.println("%");
}*/


De knoppen

cpp code
void drawbackbutton() {
tft.drawRect(2, 22, 30, 30, WHITE);
tft.fillRect(3, 23, 28, 28, YELLOW);
tft.setTextColor(BLUE);
tft.setTextSize(3);
tft.setCursor(6, 26 );
tft.print("<");
}

void drawhomebutton() {
tft.drawRect(438, 22, 40, 40, WHITE);
tft.fillRect(439, 23, 38, 38, RED);
tft.drawRect(443, 39, 30, 20, WHITE);
tft.drawLine(440, 39, 475, 39, WHITE);
tft.drawTriangle(440, 39, 457, 24, 475, 39, WHITE);
tft.drawRect(448, 49, 7, 10, WHITE);
tft.drawRect(459, 48, 10, 7, WHITE);
}

void drawBalancebutton() {
tft.drawRect(247, 270, 100, 40, WHITE);
tft.fillRect(248, 271, 98, 38, YELLOW);
tft.setTextColor(BLACK);
tft.setTextSize(2);
tft.setCursor(257, 284 );
tft.print("BALANCE");
}

void drawCoGbutton() {
tft.drawRect(133, 270, 100, 40, WHITE);
tft.fillRect(134, 271, 98, 38, YELLOW);
tft.setTextColor(BLACK);
tft.setTextSize(3);
tft.setCursor(157, 279 );
tft.println("CoG");
}
void drawWeightbutton() {
tft.drawRect(20, 270, 100, 40, WHITE);
tft.fillRect(21, 271, 98, 38, YELLOW);
tft.setTextColor(BLACK);
tft.setTextSize(2);
tft.setCursor(35, 284 );
tft.println("WEIGHT");
}

void drawSettingsbutton() {
tft.drawRect(360, 270, 100, 40, WHITE);
tft.fillRect(361, 271, 98, 38, YELLOW);
tft.setTextColor(BLACK);
tft.setTextSize(2);
tft.setCursor(363, 284 );
tft.println("SETTINGS");
}

De verschillende schermen:
[code2=]
void drawbackbutton() {
tft.drawRect(2, 22, 30, 30, WHITE);
tft.fillRect(3, 23, 28, 28, YELLOW);
tft.setTextColor(BLUE);
tft.setTextSize(3);
tft.setCursor(6, 26 );
tft.print("<");
}

void drawhomebutton() {
tft.drawRect(438, 22, 40, 40, WHITE);
tft.fillRect(439, 23, 38, 38, RED);
tft.drawRect(443, 39, 30, 20, WHITE);
tft.drawLine(440, 39, 475, 39, WHITE);
tft.drawTriangle(440, 39, 457, 24, 475, 39, WHITE);
tft.drawRect(448, 49, 7, 10, WHITE);
tft.drawRect(459, 48, 10, 7, WHITE);
}

void drawBalancebutton() {
tft.drawRect(247, 270, 100, 40, WHITE);
tft.fillRect(248, 271, 98, 38, YELLOW);
tft.setTextColor(BLACK);
tft.setTextSize(2);
tft.setCursor(257, 284 );
tft.print("BALANCE");
}

void drawCoGbutton() {
tft.drawRect(133, 270, 100, 40, WHITE);
tft.fillRect(134, 271, 98, 38, YELLOW);
tft.setTextColor(BLACK);
tft.setTextSize(3);
tft.setCursor(157, 279 );
tft.println("CoG");
}
void drawWeightbutton() {
tft.drawRect(20, 270, 100, 40, WHITE);
tft.fillRect(21, 271, 98, 38, YELLOW);
tft.setTextColor(BLACK);
tft.setTextSize(2);
tft.setCursor(35, 284 );
tft.println("WEIGHT");
}

void drawSettingsbutton() {
tft.drawRect(360, 270, 100, 40, WHITE);
tft.fillRect(361, 271, 98, 38, YELLOW);
tft.setTextColor(BLACK);
tft.setTextSize(2);
tft.setCursor(363, 284 );
tft.println("SETTINGS");
}

[/code2]

Berichten: 24
Geregistreerd: 01 Sep 2013, 13:00

Re: Sensor waardes op TFT weergeven

Berichtdoor benovitch » 12 Nov 2015, 13:22

Ik heb denk ik de oplossing gevonden voor mijn probleem. Heb na het eerste stuk van mijn loop zoals hieronder
Code: Alles selecteren
void loop() {


 
  currenttime = millis();
  unsigned long currentawake = millis();
  if ((currentawake > awakeend) && (sleepnever == 0)) {
    if (sleep == 0) {
      for (i = blv ; i >= 0; i -= 1) {
        analogWrite(backlight, i);
        delay(4);
      }
      sleep = 1;
    }
  }


Heb ik dit erachter gezet:

Code: Alles selecteren
if (currenttime - prevweight > weightcheck){
    prevweight = currenttime;
  Weightsens = analogRead (A8);
  Weightsensmap = map(Weightsens, 0, 1023, 0, 10000);
  itoa (Weightsensmap, Weight, 10);
  if (Weightsensmap != Weightold) {
    if (page == 1) {
    tft.fillRect(235, 40,70, 22, BLACK);
    tft.setCursor(235, 40);
    tft.setTextColor(WHITE);
    tft.print(Weight);
    }
    if (page == 3){
    tft.fillRect(235, 40,70, 22, BLACK);
    tft.setCursor(235, 40);
    tft.setTextColor(WHITE);
    tft.print(Weight);
      }
  Weightold = Weightsensmap;
  }
}


Daarna gaat het verder met de touchscreen enz.

Door de "if (page==1)" er bij te zetten krijg ik nu wel op de juiste plaats de waardes van de sensor te zien.
Nu kan ik voor elke
gewichtssensor hetzelfde stukje code schrijven om de waardes af te lezen.

Berichten: 4067
Geregistreerd: 16 Okt 2013, 14:31
Woonplaats: s hertogenbosch

Re: Sensor waardes op TFT weergeven

Berichtdoor shooter » 12 Nov 2015, 21:06

nu is het wel een erg lang programma aan het worden en ben ik nog steeds verloren gelopen.

eigenlijk elk deel van je programma een pagina lang maken.
al die if vragen in een functie zetten en daar weer functies inzetten.
dan krijg je allemaal kleine stukjes programma die iets doen en kun je overzicht bewaren.
tft.fillRect(235, 40,70, 22, BLACK);
tft.setCursor(235, 40);
tft.setTextColor(WHITE);
tft.print(Weight);
}
if (page == 3){
tft.fillRect(235, 40,70, 22, BLACK);
tft.setCursor(235, 40);
tft.setTextColor(WHITE);
tft.print(Weight);

staat er bijvoorbeeld twee keer in, wat niet nodig is, in een functie stoppen en er comment bijzetten wat er gebeurt.

dus :
tft.fillRect(235, 40,70, 22, BLACK);
tft.setCursor(235, 40);
tft.setTextColor(WHITE);
tft.print(Weight);
in een functie void displayweight()
dat is gelijk stel regels minder en duidelijk wat die functie doet.
paul deelen
shooter@home.nl

Berichten: 24
Geregistreerd: 01 Sep 2013, 13:00

Re: Sensor waardes op TFT weergeven

Berichtdoor benovitch » 12 Nov 2015, 22:00

Shooter,

Ondertussen is het programma al helemaal aangepast. Hieronder het programma waar ik nu zit.
In mijn vorige post gaf ik reeds aan dat ik de oplossing gevonden had. Ondertussen heb ik dit verder uitgewerkt voor de drie weegschalen. Als je wil kan ik anders een ZIP file maken met alles erin en zo ff doorsturen.

TFT_CG
Code: Alles selecteren

#include <HX711.h>
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library
#include <TouchScreen.h>
#include <EEPROM.h>
/* For the 8 data pins:
 DuemiLAnove/DiecimiLA/UNO/etc ('168 and '328 chips) microcontoller:
 D0 connects to digital 22
 D1 connects to digital 23
 D2 connects to digital 24
 D3 connects to digital 25
 D4 connects to digital 26
 D5 connects to digital 27
 D6 connects to digital 28
 D7 connects to digital 29
 For Mega's use pins 22 thru 29 (on the double header at the end)
 */
#define DOUT_RA  38
#define CLK_RA   39
#define DOUT_LA  42
#define CLK_LA   43
#define DOUT_NOSE  46
#define CLK_NOSE   47

HX711 scale_RA(DOUT_RA, CLK_RA);
HX711 scale_LA(DOUT_LA, CLK_LA);
HX711 scale_NOSE(DOUT_NOSE, CLK_NOSE);


#define YP A5  // must be an analog pin, use "An" notation!  A1 for shield
#define XM A6  // must be an analog pin, use "An" notation!  A2 for shield
#define YM 32  // mega=32     
#define XP 33   // mega=33     

#define TS_MINX 115
#define TS_MINY 77
#define TS_MAXX 906
#define TS_MAXY 940
// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X pLAte
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 260);
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
// optional
#define LCD_RESET -1
// Color definitions - in 5:6:5
#define   BLACK           0x0000
#define   BLUE            0x001F
#define   RED             0xF800
#define   GREEN           0x07E0
#define CYAN            0x07FF
#define MAGENTA         0xF81F
#define YELLOW          0xFFE0
#define WHITE           0xFFFF
#define TEST            0x1BF5
#define JJCOLOR         0x1CB6
#define JJORNG          0xFD03

Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
int i = 0;
int page = 0;

int esleepeeprom;
int sleep = 0;
unsigned long sleeptime;

int blv;
int blveeprom;

int backlight = 10;  //pin-10 uno  pin-35 mega  pin-3 for shield if you have done the MOD   for PWM backlight
char Backlight [10];
int blvold;
int barv;

const long battcheck = 10000; // the amount of time between voltage check and battery icon refresh
unsigned long prevbatt;
int battfill;
int battsens;
int battv;
int battold;
int battpercent;
char battpercenttxt [10];

int prevpage;
int sleepnever;
int esleep;
int backlightbox;

const float calibration_factor_LA = 218.25;//This value is obtained using the SparkFun_HX711_Calibration sketch
const float calibration_factor_RA = 219.5; //This value is obtained using the SparkFun_HX711_Calibration sketch
const float calibration_factor_NOSE = 219.75; //This value is obtained using the SparkFun_HX711_Calibration sketch
const float Zwaartekracht =9.81;

const long weightcheck = 200;

const long weightcheckTotal = 250;
const long Differencecheck = 250;

// Scale RA
int Gewicht_RA;
unsigned long prevweightRA;
char GewichtRA [10];
int WeightoldRA;

// Scale LA
int Gewicht_LA;
unsigned long prevweightLA;
char GewichtLA [10];
int WeightoldLA;

// Scale Nose
int Gewicht_NOSE;
unsigned long prevweightNOSE;
char GewichtNOSE [10];
int WeightoldNOSE;

//Total
int Total;
unsigned long prevweightTotal;
char TotalWeight [10];
int Totalold;

// Differenc
int Difference;
unsigned long prevDifference;
char DIFFERENCE [10];
int Differenceold;


unsigned long awakeend;
unsigned long currenttime;
unsigned long ssitime;
char voltage[10];


int MnToCoG = 0;
char MainToCoG [10];

int MnToCP = 0;
char MainToCP [10];

int MnToNose = 0;
char MainToNose [10];



void setup(void) {

  //analogReference(5);
  esleep = EEPROM.read(1);
  blv = EEPROM.read(2);
  if (esleep == 0 && blv == 0) {  // if no previous saves then set sleep and backlight to default.
    EEPROM.write(1, 4);
    EEPROM.write(2, 200);
  }
  if (esleep == 1) {
    sleeptime = 10000;
  }
  if (esleep == 2) {
    sleeptime = 20000;
  }
  if (esleep == 3) {
    sleeptime = 30000;
  }
  if (esleep == 4) {
    sleeptime = 60000;
  }
  if (esleep == 5) {
    sleeptime = 120000;
  }
  if (esleep == 6) {
    sleeptime = 300000;
  }
  if (esleep == 7) {
    sleeptime = 600000;
  }
  if (esleep == 8) {
    sleepnever = 1;
  }
  awakeend = sleeptime + 30000; // set the current sleep time based on what the saved settings in EEPROM were
 
  pinMode(backlight, OUTPUT);
  Serial.begin(9600);
 
 long zero_factor_LA = scale_LA.read_average(5);
 long zero_factor_RA = scale_RA.read_average(5);
 long zero_factor_NOSE = scale_NOSE.read_average(5);
 
  tft.reset();
  tft.begin(0x8357); //<---Here I bypassed the above. cause I already checked...

  tft.setRotation(1); //sets LAndscape mode
  tft.fillScreen(BLACK);
  tft.drawRect(50, 40, 380, 240, WHITE);
  tft.fillRect(51, 41, 378, 238, JJCOLOR);
  for (i = 0 ; i <= blv; i += 1) {
    analogWrite(backlight, i);
    delay(2);
  }
  delay(2);
  tft.setTextSize(10);
  tft.setTextColor(WHITE);
  tft.setCursor(190, 45);
  tft.println("CG");
  tft.setTextSize(3);
  tft.setTextColor(WHITE);
  tft.setCursor(200, 130);
  tft.println("Meter");
  tft.setTextSize(3);
  tft.setTextColor(WHITE);
  tft.setCursor(233, 205);
  tft.println("by");
  tft.setTextSize(3);
  tft.setTextColor(WHITE);
  tft.setCursor(120, 240);
  tft.println("Benovitch 2015");
  delay(500);//introscreen delay
 
  scale_RA.set_scale(calibration_factor_RA); //This value is obtained by using the SparkFun_HX711_Calibration sketch
  scale_RA.set_offset(zero_factor_RA); //Zero out the scale using a previously known zero_factor
  scale_LA.set_scale(calibration_factor_LA); //This value is obtained by using the SparkFun_HX711_Calibration sketch
  scale_LA.set_offset(zero_factor_LA); //Zero out the scale using a previously known zero_factor
  scale_NOSE.set_scale(calibration_factor_NOSE); //This value is obtained by using the SparkFun_HX711_Calibration sketch
  scale_NOSE.set_offset(zero_factor_NOSE); //Zero out the scale using a previously known zero_factor
 
scale_LA.tare();
scale_RA.tare();
scale_NOSE.tare();

  tft.fillScreen(BLACK);
  tft.fillRect(0, 0, 480, 20, JJCOLOR);
  tft.drawRect(445, 2, 30, 16, WHITE); //battery body
  tft.fillRect(475, 6, 4, 8, WHITE); // battery tip
  tft.fillRect(446, 3, 28, 14, BLACK); // clear the center of the battery
  drawbatt();
  homescr(); // draw the homescreen

}
#define MINPRESSURE 10
#define MAXPRESSURE 1000



void loop() {


 
  currenttime = millis();
  unsigned long currentawake = millis();
  if ((currentawake > awakeend) && (sleepnever == 0)) {
    if (sleep == 0) {
      for (i = blv ; i >= 0; i -= 1) {
        analogWrite(backlight, i);
        delay(4);
      }
      sleep = 1;
    }
  }

// Scale Nose
     if (currenttime - prevweightNOSE > weightcheck){
    prevweightNOSE = currenttime;
    Gewicht_NOSE= scale_NOSE.get_units();
    Gewicht_NOSE = constrain(Gewicht_NOSE,0,10001);
    itoa (Gewicht_NOSE , GewichtNOSE,10);
    if (Gewicht_NOSE != WeightoldNOSE){
    if (page == 1) {
      if (Gewicht_NOSE <= 10000){
    tft.fillRect(235,40,142,22,BLACK);
    //tft.fillRect(235,40,80, 22, BLACK);
    tft.setTextSize(2);
    tft.setCursor(315, 45);
    tft.setTextColor(WHITE);
    tft.println(" gr");
    tft.setTextSize(3);
    tft.setCursor(235,40);
    tft.setTextColor(WHITE);
    tft.print(GewichtNOSE);
    }
    else{
      tft.fillRect(235,40,120,22,BLACK);
    tft.setTextSize(3);
    tft.setCursor(235,40);
    tft.setTextColor(RED);
    tft.print("OVERLOAD");
   }
  } 
  WeightoldNOSE = Gewicht_NOSE;
  }
}

// Scale LA
    if (currenttime - prevweightLA > weightcheck){
    prevweightLA = currenttime;
    Gewicht_LA = scale_LA.get_units() ;
    Gewicht_LA = constrain(Gewicht_LA,0,10001);
    itoa (Gewicht_LA , GewichtLA,10);
    if (Gewicht_LA != WeightoldLA){
    if (page == 1) {
    if (Gewicht_LA <= 10000){
    tft.fillRect(235, 80,142, 22, BLACK);
    tft.setTextSize(2);
    tft.setCursor(315, 85);
    tft.setTextColor(WHITE);
    tft.println(" gr");
    tft.setTextSize(3);
    tft.setCursor(235,80);
    tft.setTextColor(WHITE);
    tft.print(GewichtLA);
    }
    else{
      tft.fillRect(235,80,120,22,BLACK);
    tft.setTextSize(3);
    tft.setCursor(235,80);
    tft.setTextColor(RED);
    tft.print("OVERLOAD");
   }
   }
    if (page == 3){
    tft.fillRect(31,226,74, 28, BLACK);
    tft.setTextSize(2);
    tft.setCursor(35,233);
    tft.setTextColor(WHITE);
    tft.print (GewichtLA);
      }
  WeightoldLA = Gewicht_LA;
  }
}

  // Scale RA
    if (currenttime - prevweightRA > weightcheck){
    prevweightRA = currenttime;
    Gewicht_RA = scale_RA.get_units() ;
    Gewicht_RA = constrain(Gewicht_RA,0,10001);
    itoa (Gewicht_RA , GewichtRA,10);
    if (Gewicht_RA != WeightoldRA){
    if (page == 1) {
      if (Gewicht_RA <= 10000){
    tft.fillRect(235, 120,142, 22, BLACK);
    tft.setTextSize(2);
    tft.setCursor(315, 125);
    tft.setTextColor(WHITE);
    tft.println(" gr");
    tft.setTextSize(3);
    tft.setCursor(235,120);
    tft.setTextColor(WHITE);
    tft.print(GewichtRA);
    }
    else{
    tft.fillRect(235,120,120,22,BLACK);
    tft.setTextSize(3);
    tft.setCursor(235,120);
    tft.setTextColor(RED);
    tft.print("OVERLOAD");
   }
   }
    if (page == 3){
    tft.fillRect(377,226,74, 28, BLACK);
    tft.setTextSize(2);
    tft.setCursor(381,233);
    tft.setTextColor(WHITE);
    tft.print (GewichtRA);
      }
  WeightoldRA = Gewicht_RA;
  }
}

//Total
    if (currenttime - prevweightTotal > weightcheckTotal){
    prevweightTotal = currenttime;
    Total = (Gewicht_NOSE + Gewicht_LA + Gewicht_RA);
    itoa (Total, TotalWeight,10);
    if (Total != Totalold){
    if (page == 1) {
    tft.fillRect(199, 219,105, 35, BLACK);
    tft.setTextSize(4);
    tft.setCursor(200, 220);
    tft.setTextColor(JJORNG);
    tft.print(TotalWeight);
    }
  Totalold = Total;
  }
 }
 
 //Difference
     if (currenttime - prevDifference > Differencecheck){
    prevDifference = currenttime;
    Difference = (Gewicht_LA - Gewicht_RA);
    itoa (Difference, DIFFERENCE,10);
    if (Difference != Differenceold){
    if (page == 3) {
    tft.fillRect(203, 256,74, 28, BLUE);
    tft.setTextSize(3);
    tft.setCursor(204,259);
    tft.setTextColor(JJORNG);
    tft.print(DIFFERENCE);
    }
  Differenceold = Difference;
  }
 }
 
  TSPoint p = ts.getPoint();
 

  if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
    awakeend = currenttime + sleeptime; //set the sleep time when screen is pressed
    if (sleep == 1) { // if asleep, then fade the backlight up
      for (i = 0 ; i <= blv; i += 1) {
        analogWrite(backlight, i);
        delay(1);
      }
      sleep = 0; // change the sleep mode to "awake"
      return;
    }



    // turn from 0->1023 to tft.width
    p.x = map(p.x, TS_MINX, TS_MAXX, 0, 480);//default is (480, 0) [default puts touch cord. 0=x/y upper right.
    p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320);//default is (320, 0) [I change these cause i like 0=xy bottom left.

    Serial.print("p.y:"); // this code will help you get the y and x numbers for the touchscreen
    Serial.print(p.y);
    Serial.print("   p.x:");
    Serial.println(p.x);


    //WEIGHT Button
    if (p.y > 12 && p.y < 75 && p.x > 24 && p.x < 71) {
      if (page == 1) {
      }
      if (page == 0) { // if you are on the "home" page (0)
        page = 1; // then you just went to the first page
        redraw(); // redraw the screen with the page value 1, giving you the page 1 menu
      }
    }
    //CoG Button
    if (p.y > 88 && p.y < 148 && p.x > 24 && p.x < 71) {
      if (page == 1) {

      }
      if (page == 0) { // if you are on the "home" page (0)
        page = 2; // then you just went to the 2e page
        redraw(); // redraw the screen with the page value 1, giving you the page 1 menu
      }
    }
    // CoG Settings pagina
    if (p.y > 241 && p.y < 297 && p.x > 24 && p.x < 71) {
      if (page == 2) {
      }
      if (page == 2) { // if you are on the "home" page (0)
        page = 5; // then you just went to the 2e page
        redraw(); // redraw the screen with the page value 1, giving you the page 1 menu
      }
    }
    //BackButton CoGSetting > CoG
    if (p.y > 4 && p.y < 18 && p.x > 409 && p.x < 444) {
      if (page == 5) {

      }
      if (page == 5) { // if you are on the "home" page (0)
        page = 2; // then you just went to the 2e page
        redraw(); // redraw the screen with the page value 1, giving you the page 1 menu
      }
    }
   
     //BackButton BaLAnce > CoG
    if (p.y > 4 && p.y < 18 && p.x > 409 && p.x < 444) {
      if (page == 3) {

      }
      if (page == 3) { // if you are on the "home" page (0)
        page = 2; // then you just went to the 2e page
        redraw(); // redraw the screen with the page value 1, giving you the page 1 menu
      }
    }



    //BALANCE Button
    if (p.y > 163 && p.y < 226 && p.x > 24 && p.x < 71) {
      if (page == 2) {

      }
      if (page == 2) { // if you are on the "home" page (0)
        page = 3; // then you just went to the 3e page
        redraw(); // redraw the screen with the page value 1, giving you the page 1 menu
      }
    }
        //ANGLE Button
    if (p.y > 163 && p.y < 226 && p.x > 24 && p.x < 71) {
      if (page == 1) {

      }
      if (page == 0) { // if you are on the "home" page (0)
        page = 6; // then you just went to the 3e page
        redraw(); // redraw the screen with the page value 1, giving you the page 1 menu
      }
    }
   
   
   
    //SETTINGS Button
    if (p.y > 241 && p.y < 297 && p.x > 24 && p.x < 71) {
      if (page == 4) {

      }
      if (page == 0) { // if you are on the "home" page (0)
        page = 4; // then you just went to the 4e page
        redraw(); // redraw the screen with the page value 1, giving you the page 1 menu
      }
    }

    // TARE button
    if (p.y > 241 && p.y < 297 && p.x > 24 && p.x < 71) {
      if (page == 1) {
        delay(200);
        m1b1action();
      }
    }



    // home
    if (p.y > 288 && p.y < 312 && p.x > 392 && p.x < 443) { // if the home icon is pressed
      if (page == 4) { // if you are leaving the settings page
        //clearmessage(); // clear the battery voltage out of the message box
        clearstatus ();
        esleepeeprom = EEPROM.read(1);
        blveeprom = EEPROM.read(2);
        if (esleep != esleepeeprom || blv != blveeprom)
        {
          EEPROM.write(1, esleep);
          EEPROM.write(2, blveeprom);

          tft.setCursor(20, 3);
          tft.setTextColor(RED);
          tft.setTextSize(2);
          tft.println("Settings Saved"); // dispLAy settings saved in message box
        }
        else
        {

          tft.setCursor(20, 3);
          tft.setTextColor(GREEN);
          tft.setTextSize(2);
          tft.println("No Changes Made");
        }
      }
      if (page = prevpage); { // a value to keep track of what WAS on the screen to redraw/erase only what needs to be
        page = 0; // make the current page home
        redraw(); // redraw the page
      }

    }

    // backlight buttons
    if (p.y > 4 && p.y < 36 && p.x > 384 && p.x < 447) {  //-
      if (page == 4) {
        blightdown();
      }
    }
    if (p.y > 173 && p.y < 208 && p.x > 387 && p.x < 447) {  //+
      if (page == 4) {
        blightup();
      }
    }
   
   // Main To CoG butons +1
    if (p.y > 243 && p.y < 256 && p.x > 322 && p.x < 347) {
      if (page == 5) {
        delay(250);
        MaintoCoGUP();   
      }
    }
    if (p.y > 172 && p.y < 183 && p.x > 322 && p.x < 347) {
      if (page == 5) {
        delay(250);
        MaintoCoGDOWN();
      }
    }
    // Main To CoG butons +10
    if (p.y > 262 && p.y < 276 && p.x > 322 && p.x < 347) {
      if (page == 5) {
        delay(75);
        MaintoCoGUP10();
      }
    }
    if (p.y > 153 && p.y < 165 && p.x > 322 && p.x < 347) {
      if (page == 5) {
        delay(75);
        MaintoCoGDOWN10();
      }
    }
    //DEL button Main To CoG
        if (p.y > 281 && p.y < 316 && p.x > 322 && p.x < 347) {
      if (page == 5) {
        MaintoCoGDEL();
      }
    }
   
    // Main To CP butons +1
    if (p.y > 243 && p.y < 256 && p.x >268 && p.x < 300) {
      if (page == 5) {
        delay(250);
        MaintoCPUP();   
      }
    }
    if (p.y > 173 && p.y < 185 && p.x > 268 && p.x < 300) {
      if (page == 5) {
        delay(250);
        MaintoCPDOWN();
      }
    }
    // Main To CP butons +10
    if (p.y > 262 && p.y < 275 && p.x > 268 && p.x < 300) {
      if (page == 5) {
        delay(75);
        MaintoCPUP10();
      }
    }
    if (p.y > 153 && p.y < 166 && p.x > 268 && p.x < 300) {
      if (page == 5) {
        delay(75);
        MaintoCPDOWN10();
      }
    }
    //DEL button Main To CP
        if (p.y > 280 && p.y < 316 && p.x > 268 && p.x < 300) {
      if (page == 5) {
        MaintoCPDEL();
      }
    }
   
     // Main To Nose butons +1
    if (p.y > 243 && p.y < 256 && p.x >222 && p.x < 248) {
      if (page == 5) {
        delay(250);
        MaintoNoseUP();   
      }
    }
    if (p.y > 172 && p.y < 186 && p.x > 222 && p.x < 248) {
      if (page == 5) {
        delay(250);
        MaintoNoseDOWN();
      }
    }
    // Main To Nose butons +10
    if (p.y > 262 && p.y < 275 && p.x > 222 && p.x < 248) {
      if (page == 5) {
        delay(75);
        MaintoNoseUP10();
      }
    }
    if (p.y > 153 && p.y < 166 && p.x > 222 && p.x < 248) {
      if (page == 5) {
        delay(75);
        MaintoNoseDOWN10();
      }
    }
    //DEL button Main To Nose
        if (p.y > 280 && p.y < 316 && p.x > 223 && p.x < 248) {
      if (page == 5) {
        MaintoNoseDEL();
      }
    }


    // sleep buttons
    if (p.y > 4 && p.y < 33 && p.x > 296 && p.x < 361) {
      if (page == 4) {
        sleepdec();
      }
    }
    if (p.y > 173 && p.y < 210 && p.x > 296 && p.x < 361) {
      if (page == 4) {
        sleepinc();
      }
    }
  }

  if (currenttime - prevbatt > battcheck) {
    prevbatt = currenttime;
    drawbatt();
  }


}
// einde main LOOP

void redraw() { // redraw the page
  if ((prevpage != 4) || (page != 5)) {
    //clearcenter();
  }
  if (page == 0) {
    homescr();
  }
  if (page == 1) {
    WEIGHT();
  }
  if (page == 2) {
    CoG();
  }
  if (page == 3) {
    BALANCE();
  }
  if (page == 4) {
    settingsscr();
  }
  if (page == 5) {
    CoGsettingsscr();
  }
  if (page == 6) {
    ANGLE();
    }
}
void clearcenter() { // the reason for so many small "boxes" is that it's faster than filling the whole thing
  tft.fillRect(0, 20, 480, 300, BLACK);
}
void clearstatus() { // this is used to erase the extra drawings when exiting the settings page
  tft.fillRect(0, 0, 444, 20, JJCOLOR);
}

/*
void decimate(char test[],int dec) {  // creates decimal function  decimate(string containing integer, number of decimal pLAces)

 int i=0;
 int length=strlen(test);
 char msg[10]="";

 strcpy(msg,test);

 if (length <= dec) {
   for(i=dec;i>(dec-length);i--)  msg[i] = msg[i-(dec-length+1)];
   for(i=0;i<(dec+1-length);i++)  msg[i]='0';
   length = strlen(msg);
 }
 for (i=length;i>(length-dec);i--)  msg[i]=msg[i-1];
 msg[length-dec]='.';

 strcpy(test,msg);
} */

void sleepinc() { // sleep increese adjustment
  if (sleeptime == 600000) {
    sleepnever = 1;
    esleep = 8;
    sleeptime = 11111111;
    showsleep();
  }
  if (sleeptime == 300000) {
    sleeptime = 600000;
    esleep = 7;
    showsleep();
  }
  if (sleeptime == 120000) {
    sleeptime = 300000;
    esleep = 6;
    showsleep();
  }
  if (sleeptime == 60000) {
    sleeptime = 120000;
    esleep = 5;
    showsleep();
  }
  if (sleeptime == 30000) {
    sleeptime = 60000;
    esleep = 4;
    showsleep();
  }
  if (sleeptime == 20000) {
    sleeptime = 30000;
    esleep = 3;
    showsleep();
  }
  if (sleeptime == 10000) {
    sleeptime = 20000;
    esleep = 2;
    showsleep();
  }
  delay(350);
}
void sleepdec() { // sleep decreese adjustment
  if (sleeptime == 20000) {
    sleeptime = 10000;
    esleep = 1;
    showsleep();
  }
  if (sleeptime == 30000) {
    sleeptime = 20000;
    esleep = 2;
    showsleep();
  }
  if (sleeptime == 60000) {
    sleeptime = 30000;
    esleep = 3;
    showsleep();
  }
  if (sleeptime == 120000) {
    sleeptime = 60000;
    esleep = 4;
    showsleep();
  }
  if (sleeptime == 300000) {
    sleeptime = 120000;
    esleep = 5;
    showsleep();
  }
  if (sleeptime == 600000) {
    sleeptime = 300000;
    esleep = 6;
    showsleep();
  }
  if (sleepnever == 1) {
    sleeptime = 600000;
    sleepnever = 0;
    esleep = 7;
    showsleep();
  }
  delay(350);
}
void showsleep() { // shows the sleep time on the settings page
  tft.fillRect(110, 108, 80, 10, BLACK);
  tft.setTextColor(WHITE);
  tft.setTextSize(1);
  if (sleeptime == 10000) {
    tft.setCursor(130, 108);
    tft.println("10 Seconds");
  }
  if (sleeptime == 20000) {
    tft.setCursor(130, 108);
    tft.println("20 Seconds");
  }
  if (sleeptime == 30000) {
    tft.setCursor(130, 108);
    tft.println("30 Seconds");
  }
  if (sleeptime == 60000) {
    tft.setCursor(136, 108);
    tft.println("1 Minute");
  }
  if (sleeptime == 120000) {
    tft.setCursor(133, 108);
    tft.println("2 Minutes");
  }
  if (sleeptime == 300000) {
    tft.setCursor(133, 108);
    tft.println("5 Minutes");
  }
  if (sleeptime == 600000) {
    tft.setCursor(130, 108);
    tft.println("10 Minutes");
  }
  if (sleepnever == 1) {
    tft.setCursor(133, 108);
    tft.println("Always On");
  }
}
//void blightup100() { // adjust option 3 down in the settings screen
//}
//void blightdown100() { // adjust option 3 up in the settings screen
//}
//custom defined actions - this is where you put your button functions

void clearmessage() {
  tft.fillRect(12, 213, 226, 16, BLACK); // bLAck out the inside of the message box
}
void drawbatt() {
  battv = analogRead(A10); // read the voltage
  //battsens = map(battv,0 , 1023, 0, 5);

  if (battv < battold) { // if the voltage goes down, erase the inside of the battery
    tft.fillRect(446, 3, 28, 14, BLACK);

  }
  battfill = map(battv, 0, 1023, 2, 28); // map the battery voltage 300 is the low, 415 is the high
  battfill = constrain(battfill, 2, 28); // constrains batt dispLAy limits
  if (battfill > 8) { // if the battfill value is between 8 and 18, fill with green
    tft.fillRect(446, 3, battfill, 14, GREEN);
    //Serial.println(battfill);
  }
  else { // if the battfill value is below 8, fill with red
    tft.fillRect(446, 3, battfill, 14, RED);
  }
  battold = battv; // this helps determine if redrawing the battfill area is necessary
}

void MnToCogDist() {

  itoa(MnToCoG, MainToCoG, 10);
  tft.setTextSize(3);
  tft.setTextColor(WHITE);
  tft.fillRect(287, 89, 73, 22, BLACK);
  tft.setCursor(290, 90);
  tft.print(MainToCoG);
}
void MnToCPDist() {

  itoa (MnToCP, MainToCP, 10);
  tft.setTextColor(WHITE);
  tft.fillRect(287, 121, 73, 23, BLACK);
  tft.setCursor(290,122);
  tft.print(MainToCP);
}

void MnToNoseDist() {

  itoa (MnToNose, MainToNose, 10);
  tft.setTextColor(WHITE);
  tft.fillRect(287, 153, 73, 23, BLACK);
  tft.setCursor(290, 153);
  tft.print(MainToNose);
}


void blbar() { // this function fills the yellow bar in the backlight brightness adjustment
  if (blv < barv) {
    tft.fillRect(111, 49, 98, 8, BLACK);
  }
  itoa (blv, Backlight, 10);
  backlightbox = map(blv, 1, 255, 0, 98);
  tft.fillRect(111, 49, backlightbox, 8, YELLOW);
  barv = blv;

  tft.fillRect(20, 240, 100, 21, BLACK);
  tft.setCursor(20, 240);
  tft.setTextColor(WHITE);
  tft.print(Backlight);

}
/*
void drawbattvoltage(){
  battv = analogRead(A10); // read the voltage ANalog 1
  battpercent = (battv / 480) * 100, 2;  // if using battery set 480(4.80v) to fresh charge value
  battpercent = constrain(battpercent, 1, 100);  // battery percent between 1% and 100%
  itoa (battpercent, battpercenttxt, 10);
         tft.setTextColor(YELLOW);
         tft.setTextSize(2);
         tft.setCursor(390, 4);
  tft.println(battpercenttxt);
         tft.setTextColor(YELLOW);
         tft.setTextSize(2);
         tft.setCursor(430, 4);
  tft.println("%");

  }
void drawbattpercent(){

  battv = analogRead(A10);// read the voltage Analog 10
  battpercent = map(battv, 0, 1024, 0,100);
  //battpercent = (battv / 480) * 100, 2;  // if using battery set 480(4.80v) to fresh charge value
  battpercent = constrain(battpercent, 1, 100);  // battery percent between 1% and 100%
  itoa (battpercent, battpercenttxt, 10);
         tft.setTextColor(YELLOW);
         tft.setTextSize(2);
         tft.setCursor(390, 4);
         tft.println(battpercenttxt);
  delay(250);
         tft.setTextColor(JJCOLOR);
         tft.setTextSize(2);
         tft.setCursor(390, 4);
         tft.println(battpercenttxt);
  tft.setTextColor(YELLOW);
  tft.setTextSize(2);
  tft.setCursor(430, 4);
  tft.println("%");
}*/



Acties
Code: Alles selecteren
void m1b1action() {
scale_LA.tare();
scale_RA.tare();
scale_NOSE.tare();
  //Serial.println("TARE");
}
void m2b1action() {
  //Serial.println ("CoG Settings");
}

// Backlight buttons
void blightup() { // increase the backlight brightness
  blv = blv + 1;
  if (blv >= 255) {
    blv = 255;
  }
  analogWrite(10, blv);
  blbar();
}
void blightdown() { // decrease the backlight brightness
  blv = blv - 1;
  if (blv <= 5) {
    blv = 5;
  }
  analogWrite(10, blv);
  blbar();
}

void blightup10() {
  blv = blv + 10;
  if (blv >= 255) {
    blv = 255;
  }
  analogWrite(10, blv);
  blbar();
}
void blightdown10() {
  blv = blv - 10;
  if (blv <= 5) {
    blv = 5;
  }
  analogWrite(10, blv);
  blbar();
}

// Distance buttons
void MaintoCoGUP() { // increase the backlight brightness
  MnToCoG = MnToCoG + 1;
  MnToCogDist();
}

void MaintoCoGDOWN() { // decrease the backlight brightness
  MnToCoG = MnToCoG - 1;
  MnToCogDist();
}

void MaintoCoGUP10() { // increase the backlight brightness
  MnToCoG = MnToCoG + 10;
  MnToCogDist();
}

void MaintoCoGDOWN10() { // decrease the backlight brightness
  MnToCoG = MnToCoG - 10;
  MnToCogDist();
}

void MaintoCoGDEL(){
  MnToCoG = 0;
  MnToCogDist();
}

void MaintoCPUP() {
  MnToCP = MnToCP + 1;
  MnToCPDist();
}
void MaintoCPDOWN() {
  MnToCP = MnToCP - 1;
  MnToCPDist();
}
void MaintoCPUP10() {
  MnToCP = MnToCP + 10;
  MnToCPDist();
}
void MaintoCPDOWN10() {
  MnToCP = MnToCP - 10;
  MnToCPDist();
}
void MaintoCPDEL(){
  MnToCP = 0;
  MnToCPDist();
}

void MaintoNoseUP() {
  MnToNose = MnToNose + 1;
  MnToNoseDist();
}
void MaintoNoseDOWN() {
  MnToNose = MnToNose - 1;
  MnToNoseDist();
}
void MaintoNoseUP10() {
  MnToNose = MnToNose + 10;
  MnToNoseDist();
}
void MaintoNoseDOWN10() {
  MnToNose = MnToNose - 10;
  MnToNoseDist();
}
void MaintoNoseDEL(){
  MnToNose = 0;
  MnToNoseDist();
}


Knoppen
Code: Alles selecteren
void drawbackbutton() {
  tft.drawRect(2, 22, 30, 30, WHITE);
  tft.fillRect(3, 23, 28, 28, YELLOW);
  tft.setTextColor(BLUE);
  tft.setTextSize(3);
  tft.setCursor(6, 26 );
  tft.print("<");
}

void drawhomebutton() {
  tft.drawRect(438, 22, 40, 40, WHITE);
  tft.fillRect(439, 23, 38, 38, RED);
  tft.drawRect(443, 39, 30, 20, WHITE);
  tft.drawLine(440, 39, 475, 39, WHITE);
  tft.drawTriangle(440, 39, 457, 24, 475, 39, WHITE);
  tft.drawRect(448, 49, 7, 10, WHITE);
  tft.drawRect(459, 48, 10, 7, WHITE);
}

void drawBalancebutton() {
  tft.drawRect(247, 270, 100, 40, WHITE);
  tft.fillRect(248, 271, 98, 38, YELLOW);
  tft.setTextColor(BLACK);
  tft.setTextSize(2);
  tft.setCursor(257, 284 );
  tft.print("BALANCE");
}

void drawCoGbutton() {
  tft.drawRect(133, 270, 100, 40, WHITE);
  tft.fillRect(134, 271, 98, 38, YELLOW);
  tft.setTextColor(BLACK);
  tft.setTextSize(3);
  tft.setCursor(157, 279 );
  tft.println("CoG");
}
void drawWeightbutton() {
  tft.drawRect(20, 270, 100, 40, WHITE);
  tft.fillRect(21, 271, 98, 38, YELLOW);
  tft.setTextColor(BLACK);
  tft.setTextSize(2);
  tft.setCursor(35, 284 );
  tft.println("WEIGHT");
}

void drawSettingsbutton() {
  tft.drawRect(360, 270, 100, 40, WHITE);
  tft.fillRect(361, 271, 98, 38, YELLOW);
  tft.setTextColor(BLACK);
  tft.setTextSize(2);
  tft.setCursor(363, 284 );
  tft.println("SETTINGS");
}
void drawAnglebutton() {
  tft.drawRect(247, 270, 100, 40, WHITE);
  tft.fillRect(248, 271, 98, 38, YELLOW);
  tft.setTextColor(BLACK);
  tft.setTextSize(2);
  tft.setCursor(268, 284 );
  tft.print("ANGLE");
}


Schermen

Code: Alles selecteren
void homescr() {

  clearcenter();
  clearstatus();
  drawWeightbutton();
  drawCoGbutton();
   drawAnglebutton();
  drawSettingsbutton();

}
void WEIGHT() {
 
  drawhomebutton();
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.setCursor(20, 3);
  tft.println("Weight");
  tft.setTextColor(WHITE);
  tft.setTextSize(3);
  tft.setCursor(10, 40);
  tft.println("Nose Gear: ");
  tft.setTextColor(WHITE);
  /*tft.setTextSize(2);
  tft.setCursor(315, 45);
  tft.println(" gr");*/
  tft.setTextColor(WHITE);
  tft.setTextSize(3);
  tft.setCursor(10, 80);
  tft.println("Main Gear L: ");
  /*tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.setCursor(315, 85);
  tft.println(" gr");*/
  tft.setTextColor(WHITE);
  tft.setTextSize(3);
  tft.setCursor(10, 120);
  tft.println("Main Gear R: ");
  /*tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.setCursor(315, 125);
  tft.println(" gr");*/
  tft.setTextColor(BLUE);
  tft.setTextSize(4);
  tft.setCursor( 10, 160);
  tft.println("Total Weight:");
  tft.setTextColor(WHITE);
  tft.setTextSize(3);
  tft.setCursor(305, 226);
  tft.println(" gr");
  tft.drawRect(360, 270, 100, 40, WHITE);
  tft.fillRect(361, 271, 98, 38, YELLOW);
  tft.setTextColor(RED);
  tft.setTextSize(3);
  tft.setCursor(375, 279 );
  tft.println("TARE");
  tft.fillRect(20, 270, 100, 40, BLACK);
  tft.fillRect(133, 270, 100, 40, BLACK); // Fill other buttons (CoG, BaLAnce, Setttings)
  tft.fillRect (247, 270, 100, 40, BLACK);
}

void CoG() {
  clearstatus();
  clearcenter();
  drawhomebutton();
  drawBalancebutton();
  tft.fillRect(20, 270, 100, 40, BLACK);
  tft.fillRect(133, 270, 100, 40, BLACK); // Fill other buttons (CoG, BaLAnce, Setttings)
  //tft.fillRect (247, 270, 100, 40, BLACK);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.setCursor(20, 3);
  tft.print("CoG");
  tft.drawRect(360, 270, 100, 40, WHITE);
  tft.fillRect(361, 271, 98, 38, YELLOW);
  tft.setTextColor(BLACK);
  tft.setTextSize(2);
  tft.setCursor(395, 273 );
  tft.print("CoG");
  tft.setTextColor(BLACK);
  tft.setTextSize(2);
  tft.setCursor(364, 291 );
  tft.print("Settings");
  tft.setTextColor(YELLOW);
  tft.setTextSize(2);
  tft.setCursor(5,23);
  tft.print("WARNING: Make sure pLAne is level!");
}

void CoGsettingsscr() {
  clearstatus();
  clearcenter();
  drawhomebutton();
  drawbackbutton();
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.setCursor(20, 3);
  tft.println("CoG Settings");

  MnToCogDist ();
  MnToCPDist ();
  MnToNoseDist ();
 
  // Main to CoG
  tft.setTextColor(WHITE);
  tft.setTextSize(3);
  tft.setCursor(2, 60);
  tft.println("Distance:");
  tft.setTextSize(3);
  tft.setCursor(2, 90);
  tft.println("Main to CoG:");
  tft.drawRect(230,88,26,25,WHITE);
  tft.fillRect(231,89,24,23,RED);
  tft.setTextSize(2);
  tft.setCursor(232,94);
  tft.print("--");
  tft.drawRect(258,88,26,25,WHITE);
  tft.fillRect(259,89,24,23,RED);
  tft.setTextSize(2);
  tft.setCursor(266,94);
  tft.print("-");
  tft.drawRect(286, 88, 75, 25, JJORNG);
  tft.drawRect(363,88,26,25,WHITE);
  tft.fillRect(364,89,24,23,GREEN);
  tft.setTextSize(2);
  tft.setCursor(371,94);
  tft.print("+");
  tft.drawRect(391,88,26,25,WHITE);
  tft.fillRect(392,89,24,23,GREEN);
  tft.setTextSize(2);
  tft.setCursor(393,94);
  tft.print("++");
  tft.drawRect(419,88,60,25,WHITE);
  tft.drawRect(419,88,60,25,WHITE);
  tft.setTextSize(3);
  tft.setTextColor(RED);
  tft.setCursor(424,90);
  tft.print("DEL");

  //Main to CP
  tft.setTextColor(WHITE);
  tft.setTextSize(3);
  tft.setCursor(2, 122);
  tft.println("Main to CP: ");
  tft.drawRect(230,120,26,25,WHITE);
  tft.fillRect(231,121,24,23,RED);
  tft.setTextSize(2);
  tft.setCursor(232,126);
  tft.print("--");
  tft.drawRect(258,120,26,25,WHITE);
  tft.fillRect(259,121,24,23,RED);
  tft.setTextSize(2);
  tft.setCursor(266,126);
  tft.print("-");
  tft.drawRect(286, 120, 75, 25, JJORNG);
  tft.drawRect(363,120,26,25,WHITE);
  tft.fillRect(364,121,24,23,GREEN);
  tft.setTextSize(2);
  tft.setCursor(371,126);
  tft.print("+");
  tft.drawRect(391,120,26,25,WHITE);
  tft.fillRect(392,121,24,23,GREEN);
  tft.setTextSize(2);
  tft.setCursor(393,126);
  tft.print("++");
  tft.drawRect(419,120,60,25,WHITE);
  tft.drawRect(419,120,60,25,WHITE);
  tft.setTextSize(3);
  tft.setTextColor(RED);
  tft.setCursor(424,122);
  tft.print("DEL");

  // Main to LA
  tft.setTextColor(WHITE);
  tft.setTextSize(3);
  tft.setCursor(2, 154);
  tft.println("Main to LA:");
  tft.drawRect(230,152,26,25,WHITE);
  tft.fillRect(231,153,24,23,RED);
  tft.setTextSize(2);
  tft.setCursor(232,158);
  tft.print("--");
  tft.drawRect(258,152,26,25,WHITE);
  tft.fillRect(259,153,24,23,RED);
  tft.setTextSize(2);
  tft.setCursor(266,158);
  tft.print("-");
  tft.drawRect(286, 152, 75, 25, JJORNG);
  tft.drawRect(363,152,26,25,WHITE);
  tft.fillRect(364,153,24,23,GREEN);
  tft.setTextSize(2);
  tft.setCursor(371,158);
  tft.print("+");
  tft.drawRect(391,152,26,25,WHITE);
  tft.fillRect(392,153,24,23,GREEN);
  tft.setTextSize(2);
  tft.setCursor(393,158);
  tft.print("++");
  tft.drawRect(419,152,60,25,WHITE);
  tft.setTextSize(3);
  tft.setTextColor(RED);
  tft.setCursor(424,154);
  tft.print("DEL");
  tft.drawRect(0, 180, 480, 140, WHITE);
  tft.fillRect (360, 270, 100, 40, BLACK);
 

}
void BALANCE() {
  clearstatus();
  clearcenter();
  drawhomebutton();
  drawbackbutton();
  tft.fillRect(20, 270, 100, 40, BLACK);
  tft.fillRect(133, 270, 100, 40, BLACK);
  tft.fillRect (247, 270, 100, 40, BLACK);
  tft.fillRect (360, 270, 100, 40, BLACK);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.setCursor(20, 3);
  tft.println("Balance");
  tft.fillRect(0,290,480,30,RED);
  tft.setTextSize(3);
  tft.setTextColor(YELLOW);
  tft.setCursor(75,295);
  tft.println("To Heavy LEFT side!");
  tft.setTextSize(2);
  tft.setTextColor(YELLOW);
  tft.setCursor(45,205);
  tft.println("LEFT");
  tft.setTextSize(2);
  tft.setTextColor(YELLOW);
  tft.setCursor(386,205);
  tft.println("RIGHT");
  tft.setTextSize(2);
  tft.setTextColor(YELLOW);
  tft.setCursor(182,235);
  tft.println("DIFFERENCE");
  tft.drawRect(30,225,76,30,JJORNG);
  tft.drawRect(376,225,76,30,JJORNG);
  tft.drawRect(202,255,76,30,JJORNG); 
}

void settingsscr() {
  drawhomebutton();
  // backlight level
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.setCursor(20, 3);
  tft.println("Settings");
  tft.fillRect(0, 20, 60, 50, RED);
  tft.drawRect(0, 20, 60, 50, WHITE);
  tft.drawRect(80, 20, 160, 50, JJCOLOR);
  tft.fillRect(260, 20, 60, 50, GREEN);
  tft.drawRect(260, 20, 60, 50, WHITE);
  tft.setTextColor(WHITE);
  tft.setTextSize(3);
  tft.setCursor(22, 33);
  tft.println("-");
  tft.setTextSize(1);
  tft.setCursor(120, 31);
  tft.println("Backlight Level");
  tft.setTextSize(3);
  tft.setCursor(282, 33);
  tft.println("+");
  tft.drawRect(110, 48, 100, 10, WHITE);
  blbar();

  // sleep time
  tft.fillRect(0, 80, 60, 50, RED);
  tft.drawRect(0, 80, 60, 50, WHITE);
  tft.drawRect(80, 80, 160, 50, JJCOLOR);
  tft.fillRect(260, 80, 60, 50, GREEN);
  tft.drawRect(260, 80, 60, 50, WHITE);
  tft.setTextSize(3);
  tft.setCursor(22, 93);
  tft.println("-");
  tft.setTextSize(2);
  tft.setCursor(100, 91);
  //tft.println("Backlight Level /100");
  tft.setTextSize(3);
  tft.setCursor(282, 93);
  tft.println("+");
  showsleep();
  tft.fillRect(20, 270, 100, 40, BLACK);
  tft.fillRect(133, 270, 100, 40, BLACK);
  tft.fillRect (247, 270, 100, 40, BLACK);
  tft.fillRect (360, 270, 100, 40, BLACK);

  tft.fillRect(0, 140, 60, 50, RED);
  tft.drawRect(0, 140, 60, 50, WHITE);
  tft.drawRect(80, 140, 160, 50, JJCOLOR);
  tft.fillRect(260, 140, 60, 50, GREEN);
  tft.drawRect(260, 140, 60, 50, WHITE);
  tft.setTextSize(3);
  tft.setCursor(22, 153);
  tft.println("--");
  tft.setTextSize(1);
  tft.setCursor(130, 151);
  tft.println("Thing #3");
  tft.setTextSize(3);
  tft.setCursor(282, 153);
  tft.println("++");
  tft.drawRect(110, 168, 100, 10, WHITE);
}

void ANGLE(){
  clearstatus();
  clearcenter();
  drawhomebutton();
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.setCursor(20, 3);
  tft.println("Angle");
  tft.fillRect(20, 270, 100, 40, BLACK);
  tft.fillRect(133, 270, 100, 40, BLACK);
  tft.fillRect (247, 270, 100, 40, BLACK);
  tft.fillRect (360, 270, 100, 40, BLACK);
  }
 

Vorige

Terug naar Arduino software

Wie is er online?

Gebruikers in dit forum: Google Adsense [Bot], onejelatifumh en 88 gasten