weer een uitdaging utft druk sensor laten werken

Projecten die niet passen in bovenstaande onderwerpen
Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: weer een uitdaging utft druk sensor laten werken

Berichtdoor nicoverduin » 16 Feb 2016, 16:03

Hoe ziet de hele sketch er nu uit?
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Advertisement

Berichten: 46
Geregistreerd: 07 Jan 2016, 23:29
Woonplaats: arnhem city

Re: weer een uitdaging utft druk sensor laten werken

Berichtdoor dongolfcabrio » 16 Feb 2016, 16:33

cpp code
#include <UTFT.h>
#include <UTouch.h>



// Declare which fonts we will be using
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];
extern uint8_t SevenSeg_XXXL_Num[];


int x, y,g,menu;

UTFT myGLCD(ITDB32S,38,39,40,41);
UTouch myTouch(6,5,4,3,2);

#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
//druksensoren
int rawValue; // A/D readings
int offset = 95; // zero pressure adjust
int fullScale = 807; // max pressure (span) adjust
float pressure; // final pressure

const int voorup = 14;
const int voordown = 15;
const int achterup = 16;
const int achterdown = 17;


void setup()
{

Serial.begin(9600);
pinMode(voorup, OUTPUT);
pinMode(voordown, OUTPUT);
pinMode(achterup, OUTPUT);
pinMode(achterdown, OUTPUT);

digitalWrite(voorup, HIGH);
digitalWrite(voordown, HIGH);
digitalWrite(achterup, HIGH);
digitalWrite(achterdown, HIGH);

myGLCD.InitLCD(LANDSCAPE); // Initialize the display
myGLCD.clrScr(); // Clear the screen (black)
myTouch.InitTouch(LANDSCAPE);
myTouch.setPrecision(PREC_MEDIUM);
myGLCD.setFont(BigFont);
myGLCD.fillScr(255,255,255); // Clear the screen (White)
delay(600); //Delay to draw the image
myGLCD.clrScr(); // Clear the screen (black)
Menu1();
menu=1;
}

//Buttons coordinates
//Menu 1
//Button motor
int x11=20; int y11=20; int x12=150; int y12=100;
//Button air
int x21=180; int y21=20; int x22=300; int y22=100;
//Button games
int x31=20; int y31=130; int x32=150; int y32=210;
//Button setup
int x41=180; int y41=130; int x42=300; int y42=210;
//Button Back

// Menu air
int x61=250; int y61=200; int x62=310; int y62=230;




void Menu1() // MAIN MENU
{
myGLCD.clrScr(); // Clear the screen (black)
myGLCD.setFont(BigFont);
myGLCD.setColor(0, 0, 255);
myGLCD.setBackColor(0, 0, 255);
//BUTTON motor
button (x11,y11,x12,y12); myGLCD.print("MOTOR",45,50);
//BUTTON air
button (x21,y21,x22,y22); myGLCD.print("AIR",210,50);
//BUTTON games
button (x31,y31,x32,y32); myGLCD.print("GAMES",45,160);
//BUTTON setup
button (x41,y41,x42,y42); myGLCD.print("SETUP",200,160);

menu =1;


}

void Menu2() //motor MENU
{
myGLCD.clrScr(); // Clear the screen (black)
button (x61,y61,x62,y62); myGLCD.setFont(BigFont); myGLCD.print("<--",255,207);
menu =2;

}

void Menu3() //air MENU
{
myGLCD.clrScr(); // Clear the screen (black)
myGLCD.setBackColor(BLACK);
// vak links onder
myGLCD.setColor(RED);
myGLCD.drawRoundRect(5, 5, 120,120); ///links boven
myGLCD.drawRoundRect(120, 5, 240,120); ///rechts boven
myGLCD.drawRoundRect(5, 235, 120,120); ///links onder
myGLCD.drawRoundRect(120, 235, 240,120); ///rechts onder

myGLCD.setColor(WHITE);
myGLCD.print("DRIVE",23,50);
myGLCD.print("+",170,20);
myGLCD.print("ALL",155,50);
myGLCD.print("-",170,80);
myGLCD.print("FRONT",23,121);
myGLCD.print("+",55,140);
myGLCD.print("-",55,210);
myGLCD.print("REAR",145,121);
myGLCD.print("+",170,140);
myGLCD.print("0,00",150,175);
myGLCD.print("-",170,210);

button (x61,y61,x62,y62); myGLCD.setFont(BigFont); myGLCD.print("<--",255,207);
menu =3;

}

void Menu4() // MENU 4
{


button (x61,y61,x62,y62); myGLCD.setFont(BigFont); myGLCD.print("<--",255,207);
menu =4;

}

void Menu5() // MENU 5
{

myGLCD.clrScr(); // Clear the screen (black)
button (x61,y61,x62,y62); myGLCD.setFont(BigFont); myGLCD.print("<--",255,207);
menu =5;

}




void loop()
{

while (true)

{
if (myTouch.dataAvailable())
{
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();
/////////////////////////////////////////////////////////////////////////////////////////////
if (menu ==1)
{
if ((y>=y11) && (y<=y12)) // Upper row
{
if ((x>=x11) && (x<=x12)) // Button: MOTOR
{
waitForIt(x11,y11,x12,y12);
menu =2;
Menu2();
}
if ((x>=x21) && (x<=x22)) // Button: AIR
{
waitForIt(x21,y21,x22,y22);
menu =3;
Menu3();

}
}
if ((y>=y31) && (y<=y32)) // Lower row
{
if ((x>=x31) && (x<=x32)) // Button: GAMES
{
waitForIt(x31,y31,x32,y32);
menu =4;
Menu4();
}
if ((x>=x41) && (x<=x42)) // Button: SETUP
{
waitForIt(x41,y41,x42,y42);
menu =5;
Menu5();

}
}
}
/////////////////////////////////////////////////////////////////////////////////////////////
if (menu==2)////////////motor
{
myGLCD.setFont(BigFont);
myGLCD.setColor(CYAN);
myGLCD.print("NOG IN AANBOUW",40 ,100);


if ((y>=y61) && (y<=y62)) // Button: Back
{
if ((x>=x61) && (x<=x62)) // Button: Back
{
waitForIt(x61,y61,x62,y62);
menu =1;
Menu1();
}

}
}
/////////////////////////////////////////////////////////////////////////////////////////////
if (menu==3)//////////air {


rawValue = analogRead(A0);
pressure = (rawValue - offset) * 7.9 / (fullScale - offset);
myGLCD.setFont(BigFont);
myGLCD.printNumF(pressure,1,40,175);



if ((x>160) && (x<180) && (y>10) && (y<30)) // button: + ALL
{
digitalWrite(voorup, LOW);
digitalWrite(achterup, LOW);
delay(200);
digitalWrite(voorup, HIGH);
digitalWrite(achterup, HIGH);
}else{
if ((x>160) && (x<180) && (y>70) && (y<90)) // button: - ALL
{
digitalWrite(voordown, LOW);
digitalWrite(achterdown, LOW);
delay(200);
digitalWrite(voordown, HIGH);
digitalWrite(achterdown, HIGH);
}else{
if ((x>60) && (x<80) && (y>120) && (y<160)) // button: + FRONT
{
digitalWrite(voorup, LOW);
delay(200);
digitalWrite(voorup, HIGH);
}else{
if ((x>60) && (x<80) && (y>200) && (y<240)) // button: - FRONT
{
digitalWrite(voordown, LOW);
delay(200);
digitalWrite(voordown, HIGH);
}else{
if ((x>170) && (x<190) && (y>140) && (y<160)) // button: + REAR
{
digitalWrite(achterup, LOW);
delay(200);
digitalWrite(achterup, HIGH);
}else{
if ((x>170) && (x<190) && (y>210) && (y<230)) // button: - REAR
{
digitalWrite(achterdown, LOW);
delay(200);
digitalWrite(achterdown, HIGH);
}else{

if ((y>=y61) && (y<=y62)) // Button: Back
{
if ((x>=x61) && (x<=x62)) // Button: Back
{
waitForIt(x61,y61,x62,y62);
menu =1;
Menu1();
}

}
}

/////////////////////////////////////////////////////////////////////////////////////////////
if (menu==4)//////////games
{

myGLCD.setFont(BigFont);
myGLCD.setColor(CYAN);
myGLCD.print("NOG IN AANBOUW",40 ,100);


if ((y>=y61) && (y<=y62)) // Button: Back
{
if ((x>=x61) && (x<=x62)) // Button: Back
{
waitForIt(x61,y61,x62,y62);
menu =1;
Menu1();
}

}
}
/////////////////////////////////////////////////////////////////////////////////////////////
if (menu==5)////////////setup
{
myGLCD.setFont(BigFont);
myGLCD.setColor(CYAN);
myGLCD.print("NOG IN AANBOUW",40 ,100);

if ((y>=y61) && (y<=y62)) // Button: Back
{
if ((x>=x61) && (x<=x62)) // Button: Back
{
waitForIt(x61,y61,x62,y62);
menu =1;
Menu1();
}
}
}}}}}}}}}


void button(int x1, int y1, int x2, int y2)
{
myGLCD.setColor(BLUE);
myGLCD.fillRoundRect (x1,y1,x2,y2);
myGLCD.setColor(WHITE);
myGLCD.drawRoundRect (x1,y1,x2,y2);
}

// Draw a red frame while a button is touched
void waitForIt(int x1, int y1, int x2, int y2)
{
myGLCD.setColor(255, 0, 0);
myGLCD.drawRoundRect (x1, y1, x2, y2);
//while (myTouch.dataAvailable())
//myTouch.read();
delay(300);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (x1, y1, x2, y2);
}


dit is de volledige code met menu,s erin alleen nu werkt gaat de digitalwrite knipperen en de druk blijft staan tot ik ergens op het scherm druk dan veranderd de druk weer

Vorige

Terug naar Overige projecten

Wie is er online?

Gebruikers in dit forum: Geen geregistreerde gebruikers en 50 gasten