![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
cbcx
Dependencies: DmTftLibrary mbed
Fork of LCD_Proj by
Revision 4:0d4286278f41, committed 2016-02-01
- Comitter:
- TFuchsbichler
- Date:
- Mon Feb 01 13:08:54 2016 +0000
- Parent:
- 3:03c08a612220
- Commit message:
- dshshd
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/as5047p.h Mon Feb 01 13:08:54 2016 +0000 @@ -0,0 +1,164 @@ +#include "mbed.h" +extern Serial pc; + +//0x3FFD = CORDIC magnitude +//0x3FFE = Measured angle without dynamic angle error compensation +//0x3FFF = Measured angle with dynamic angle error compensation + +//Chipselect = activ Low +//Vor jedem einzelnem Data muss steigende Flanke erzeugt werden + +SPI spi(p11, p12, p13); // mosi, miso, sclk +DigitalOut cs1(p23); +DigitalOut cs2(p24); +//Adresse ANGLECOM = 0x3FFF + + +class _as50 +{ +int Index; +unsigned int Sarray1[24]; +unsigned int Sarray2[24]; +unsigned int Laenge,Breite; //Länge und breite des rechteckigen Kanals in dem gemessen wird +Timer timer; + +public: _as50() //Konstruktor + { + Index=24;//Arraygröße für schleifen + spi.format(16,1); // heißt 16 Bit und //mode 1 -->CPOL=0, CPHA=1 heißt steigende Flanke + spi.frequency(1000000); //10Mhz clock + cs1 = 1; cs2= 1; //steigende Flanke --> anfangs (0 benötigt) + InitFeld(); + Laenge=1;Breite=1; //Länge und Breite des Kanals in Meter + } + public: unsigned int Durchfluss(int welcher) + { + int durchfluss=0; + if(welcher==1) + { + timer.start(); + while(timer.read()<=1) // 1 Sekunde lang Daten sammeln und dann mittelwert zurückgeben + { + durchfluss=Sensormittelwert(1); + } + timer.stop();timer.reset(); + } + if(welcher==2) + { + timer.start();timer.reset(); + while(timer.read()<=1) + { + durchfluss=Sensormittelwert(2); + } + timer.stop();timer.reset(); + } + return durchfluss*Laenge*Breite; //*Länge*Breite des Kanals pro sekunde --> physikalischer Durchfluss + } + unsigned int Sensormittelwert(int welcher) + { + if(welcher==1) + { + unsigned int Sensor1=Sensor(1); //pc.printf("Sensor1: %u ",Sensor1); + unsigned int size1= Arraysize(Sarray1); //pc.printf("size1: %u ",size1); + AddField(1,Sensor1,size1); + unsigned int Mittelwert1=Mittelwert(Sarray1); //pc.printf("Mittelwert1: %u \r\n",Mittelwert1); + return Mittelwert1; //*Lange*Breite pro sekunde --> Durchfluss + } + if(welcher==2) + { + unsigned int Sensor2=Sensor(2); //pc.printf("Sensor2: %u",Sensor2); + unsigned int size2= Arraysize(Sarray2); //pc.printf("size2: %u",size2); + AddField(2,Sensor2,size2); + unsigned int Mittelwert2=Mittelwert(Sarray2); //pc.printf("Mittelwert2: %u \r\n",Mittelwert2); + return Mittelwert2; //*Lange*Breite pro sekunde --> Durchfluss + } + return 0; //Default + } + + unsigned int Sensor(unsigned int welcher) //Sensorwerte auslesen + { + unsigned int whoami; + + if(welcher==1) + { + cs1 = 0; //select Sensor 1 setzen + + // Send 0x8f, the command to read the WHOAMI register + whoami = spi.write(0x3FFE | (1<<14)); //Register auslesen 1<<um 14 //rüberschieben (1 heißt lesen 0 heißt schreiben) + whoami &= ~(0xC000); + wait(0.001); //mindestens 5ns delay vor Flanke + cs1 = 1; //deselect Sensor (0 setzen) + } + if (welcher==2) + { + cs2 = 0; //select Sensor 1 setzen + + // Send 0x8f, the command to read the WHOAMI register + whoami = spi.write(0x3FFE | (1<<14)); //Register auslesen 1<<um 14 //rüberschieben (1 heißt lesen 0 heißt schreiben) + whoami &= ~(0xC000); + wait(0.001); //mindestens 5ns delay vor Flanke + cs2 = 1; //deselect Sensor (0 setzen) + } + whoami/=360; + return whoami; + + } + void InitFeld() //Alle Felder in Array auf 0 setzen + { + for(int i=0;i<Index;i++) + { + Sarray1[i]=0; + Sarray2[i]=0; + } + } + unsigned int Arraysize(unsigned int Sarray[]) //Felder mit Werten sind ungleich 0...liefert Anzahl der Felder mit Werten + { + int counter=0; + for(int i=0;i<Index;i++) + { + if(Sarray[i]!=0) + { + counter++; + } + } + return counter; + } + + void AddField(unsigned int welcher,unsigned int wert,unsigned int gross) + { + if(gross==(Index-1)) //Bevor Feld "out of index geht" --> alles 0 setzen + { + InitFeld(); + if(welcher==1) + Sarray1[0]=wert; + if(welcher==2) + Sarray2[0]=wert; + } + else //Fügt Sensordaten in Array ein + { + if (welcher==1) + { + Sarray1[gross]=wert; + } + if (welcher==2) + { + Sarray2[gross]=wert; + } + } + + } + unsigned int Mittelwert(unsigned int Array[]) //Errechnet den Mittelwert der Arraydaten + { + unsigned int groesse=Arraysize(Array); + if((groesse)==0) + groesse=1; + unsigned int value=0; + for(int i=0;i<groesse;i++) + { + value+=Array[i]; //alle addieren + } + value/=groesse; //durch Anzahl + + return value; + } +};
--- a/bild.h Mon Jan 25 12:42:52 2016 +0000 +++ b/bild.h Mon Feb 01 13:08:54 2016 +0000 @@ -202,4 +202,40 @@ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2113, 20998, 23013, 18853, 18852, 16772, 18885, 20965, 20965, 23045, 23045, 23013, 23013, 23013, 23013, 22981, 25093, 16805, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4258, 18918, 16804, 16805, 18885, 20933, 22981, 23013, 23013, 23013, 23013, 23013, 22981, 25061, 25126, 20998, 4193, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10532, 23078, 18852, 18853, 20933, 23013, 23013, 23013, 25061, 23013, 25061, 27142, 27175, 16806, 4226, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + + +uint16_t fuellstand[]={ +0, 0, 0, 0, 0, 0, 2145, 33808, 31727, 31695, 31727, 31727, 31727, 31727, 31727, 31727, 31727, 31727, 31727, 31727, 31727, 31727, 31695, 31695, 33808, 6339, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 12710, 42292, 48599, 54938, 54970, 54938, 54938, 54938, 54938, 54938, 54938, 54938, 54938, 54938, 54938, 54938, 54938, 54970, 54970, 50712, 44373, 27469, 0, 0, 0, 0, 0, +0, 0, 0, 0, 4226, 42292, 52825, 63422, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 54970, 46518, 19049, 0, 0, 0, 0, +0, 0, 0, 0, 25388, 50712, 65535, 65535, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63422, 65535, 52857, 38034, 0, 0, 0, 0, +0, 0, 0, 0, 31727, 57051, 65535, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 65535, 57051, 38034, 0, 0, 0, 0, +0, 0, 0, 0, 29614, 54970, 65535, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 65535, 57051, 38034, 0, 0, 0, 0, +0, 0, 0, 0, 29614, 54970, 65535, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 65535, 54970, 38034, 0, 0, 0, 0, +0, 0, 0, 0, 29614, 54970, 65535, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 65535, 54970, 38034, 0, 0, 0, 0, +0, 0, 0, 0, 29614, 54970, 65535, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 65535, 54970, 38034, 0, 0, 0, 0, +0, 0, 0, 0, 29614, 54970, 65535, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 65535, 54970, 38034, 0, 0, 0, 0, +0, 0, 0, 0, 29614, 54970, 65535, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 65535, 54970, 38034, 0, 0, 0, 0, +0, 0, 0, 0, 29614, 54970, 65535, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 65535, 54970, 38034, 0, 0, 0, 0, +0, 0, 0, 0, 29614, 54970, 65535, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 65535, 54970, 38034, 0, 0, 0, 0, +0, 0, 0, 0, 29614, 54970, 65535, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 63390, 65535, 54970, 38034, 0, 0, 0, 0, +0, 0, 0, 0, 29614, 54971, 65535, 63391, 63391, 63391, 63391, 63391, 63391, 63391, 63391, 63391, 63391, 63391, 63391, 63391, 63391, 63391, 63391, 63391, 63391, 65535, 54972, 38033, 0, 0, 0, 0, +0, 0, 0, 0, 29614, 54969, 65534, 63388, 63388, 63388, 63388, 63388, 63388, 63388, 63388, 63388, 63388, 63388, 63388, 63388, 63388, 63388, 63388, 63388, 63388, 65534, 54969, 38034, 0, 0, 0, 0, +0, 0, 0, 0, 29618, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 30005, 9071, 9071, 9071, 9071, 9071, 9071, 38035, 0, 0, 0, 0, +0, 0, 0, 0, 29618, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 13264, 63455, 13264, 9071, 9071, 9071, 9071, 9071, 38035, 0, 0, 0, 0, +0, 0, 0, 0, 29618, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 34166, 65535, 34166, 9071, 9071, 9071, 9071, 9071, 38035, 0, 0, 0, 0, +0, 0, 0, 0, 29618, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 55100, 65535, 55100, 9071, 9071, 9071, 9071, 9071, 38035, 0, 0, 0, 0, +0, 0, 0, 0, 29618, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 65535, 9071, 9071, 9071, 9071, 9071, 9071, 38035, 0, 0, 0, 0, +0, 0, 0, 0, 29618, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 65535, 9071, 9071, 9071, 9071, 9071, 9071, 38035, 0, 0, 0, 0, +0, 0, 0, 0, 29618, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 65535, 9071, 9071, 9071, 9071, 9071, 9071, 38035, 0, 0, 0, 0, +0, 0, 0, 0, 29618, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 65535, 9071, 9071, 9071, 9071, 9071, 9071, 38035, 0, 0, 0, 0, +0, 0, 0, 0, 29618, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 65535, 9071, 9071, 9071, 9071, 9071, 9071, 38035, 0, 0, 0, 0, +0, 0, 0, 0, 29618, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 65535, 9071, 9071, 9071, 9071, 9071, 9071, 38035, 0, 0, 0, 0, +0, 0, 0, 0, 29618, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 65535, 9071, 9071, 9071, 9071, 9071, 9071, 38035, 0, 0, 0, 0, +0, 0, 0, 0, 31731, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 55100, 65535, 55100, 9071, 9071, 9071, 9071, 9071, 38068, 0, 0, 0, 0, +0, 0, 0, 0, 27505, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 34166, 65535, 34166, 9071, 9071, 9071, 9071, 9071, 38039, 0, 0, 0, 0, +0, 0, 0, 0, 4291, 42328, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 13264, 63455, 15312, 9071, 9071, 9071, 9071, 46518, 21164, 0, 0, 0, 0, +0, 0, 0, 0, 0, 16937, 42295, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 9071, 32053, 9071, 9071, 9071, 9071, 46454, 27504, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 4259, 35925, 33878, 33877, 33877, 33877, 33877, 33877, 33877, 33877, 33877, 33877, 33845, 35957, 35957, 33845, 33877, 33877, 33878, 31697, 0, 0, 0, 0, 0, 0 }; \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fuellstand.h Mon Feb 01 13:08:54 2016 +0000 @@ -0,0 +1,64 @@ +#include "mbed.h" + +class Fuellstand{ + int grenze; //Wert unter welchem die Pumpe ON oder OFF sein soll + int now; //Aktueller Messwert + public: + //constructers + Fuellstand(int,PinName, PinName, PinName, PinName,PinName); //Konstruktor mit Schwellenwerteingabe bei fehler defaultwert + //p25p p50p p75p p100p pboden + //methodes + int wert(); //gibt den aktuelle 1wert zurück in 25er Schritten + + bool activate(); //gibt an ob die Pumpe aus sein soll + void setgrenze(int); //um die grenze zu setzten + + void setboden(bool); //Messungaktivieren + private: + void getnow(); //misst den Wert + PinName pp25p; + PinName pp50p; + PinName pp75p; + PinName pp100p; + PinName ppboden; +}; + //constructers +Fuellstand::Fuellstand(int ober, PinName new25p, PinName new50p, PinName new75p, PinName new100p ,PinName newboden){ //Konstruktor mit Schwellenwerteingabe bei fehler defaultwert + if(ober>0&&ober<100) grenze=ober; + else grenze=80; + pp25p=new25p; //25% + pp50p=new50p; + pp75p=new75p; + pp100p=new100p; + ppboden=newboden; +} + //methodes +void Fuellstand::getnow(){ //misst den Wert + DigitalIn DI25(pp25p); + DigitalIn DI50(pp50p); + DigitalIn DI75(pp75p); + DigitalIn DI100(pp100p); + if(DI25==1) now=25; + else now=0; + if(DI50==1) now=50; + if(DI75==1) now=75; + if(DI100==1) now=100; +} +int Fuellstand::wert(){ //gibt den aktuelle wert zurück in 25er Schritten + getnow(); + return now; +} +bool Fuellstand::activate(){ //gibt an ob die Pumpe aus sein soll + getnow(); + if(now<=grenze) + return true; + else + return false; +} +void Fuellstand::setgrenze(int newgrenze){ //um die grenze zu setzten + grenze=newgrenze; +} +void Fuellstand::setboden(bool newbodenstate){ //um die 1 aktivieren zu setzten + DigitalOut DOboden(ppboden); + DOboden=newbodenstate; +} \ No newline at end of file
--- a/main.cpp Mon Jan 25 12:42:52 2016 +0000 +++ b/main.cpp Mon Feb 01 13:08:54 2016 +0000 @@ -16,6 +16,9 @@ #include "mbed.h" #include "bild.h" //Bilder mit einbinden +#include "as5047p.h" +#include "fuellstand.h" + #include "DmTftHX8353C.h" #include "DmTftS6D0164.h" @@ -61,6 +64,8 @@ * Local variables *****************************************************************************/ +/********* Fuellstand *********/ +Fuellstand fst(75,p25, p26, p27, p28, p30); /********* TFT DISPLAY INIT *********/ DmTftIli9341 tft(p21, p22, p5, p6, p7); /* DmTftIli9341(PinName cs, PinName dc, PinName mosi, PinName miso, PinName clk) DM_TFT28_105 and DM_TFT28_116*/ @@ -216,6 +221,7 @@ touch.init(); tft.drawImage(208,0,32,32,zahnrad); + tft.drawImage(0,0,32,32,fuellstand); } @@ -343,13 +349,82 @@ } + + +void FReckt(int width, int x, int y, int percent) +{ + tft.drawRectangle(x,y,x+width,y+100,WHITE); + tft.fillRectangle(x+1,y+1,x+width-2,y+98,BLACK); + + + + if(percent>=1&&percent<=25) + { + tft.fillRectangle(x+1,y+76,x+width-2,y+98,BLUE); + + } + + if(percent>=26&&percent<=50) + { + tft.fillRectangle(x+1,y+51,x+width-2,y+98,BLUE); + } + + if(percent>=51&&percent<=75) + { + tft.fillRectangle(x+1,y+26,x+width-2,y+98,BLUE); + } + + if(percent == 100) + { + tft.fillRectangle(x+1,y+1,x+width-2,y+98,BLUE); + } + +} + +void Fstand() +{ + + tft.clearScreen(BLACK); + + + while(1) + { + FReckt(60, 30, 30, fst.wert()); + wait(0.5); + } + /* + while(1) + { + a=a+5; + wait(0.5); + FReckt(120,80,10,10,a); + if(a>=100) + { + a=100; + break; + } + + } + while(1) + { + a=a-5; + wait(0.5); + FReckt(120,80,10,10,a); + if(a<=0) + { + break; + } + } + */ +} + /****************************************************************************** * Main *****************************************************************************/ int main() { - + fst.setboden(true); struct tm t; t.tm_sec = 00; // 0-59 @@ -406,6 +481,10 @@ //Reset Stoppuhr if(down==true&&x>=165&&x<=214&&y>=285&&y<=310) reset(); + //Füllstand + if(down==true&&x>=0&&x<=32&&y>=0&&y<=32) + Fstand(); + tft.drawNumber(78,230,stund,2,1); tft.drawString(94, 230, ":");