projets de S3 s4 2021

Dependencies:   mbed TFT_fonts SPI_TFT_ILI9341

Files at this revision

API Documentation at this revision

Comitter:
dujardin
Date:
Sun Oct 18 16:05:21 2020 +0000
Parent:
7:a72b2f80ae04
Commit message:
version avec spi

Changed in this revision

IUT.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
touch.cpp Show diff for this revision Revisions of this file
diff -r a72b2f80ae04 -r eb61367f53ce IUT.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IUT.h	Sun Oct 18 16:05:21 2020 +0000
@@ -0,0 +1,39 @@
+// declaration utiles à la cartes IUT-BED 
+// reservation des broches 
+#include "SPI_TFT_ILI9341.h"
+#include "Arial12x12.h"
+#include "Arial24x23.h"
+#include "Arial28x28.h"
+#include "font_big.h"
+
+#define     PIN_XP          PC_0
+#define     PIN_XM          PC_1
+#define     PIN_YP          PB_0
+#define     PIN_YM          PA_4
+#define     PIN_MOSI        PA_7
+#define     PIN_MISO        PA_6
+#define     PIN_SCLK        PA_5
+#define     PIN_CS_TFT      PB_4
+#define     PIN_DC_TFT      PB_10
+#define     PIN_BL_TFT      PA_8
+#define     PIN_CS_SD       PP_5
+
+SPI_TFT_ILI9341 TFT(PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TFT, PIN_BL_TFT, PIN_DC_TFT, "TFT");   //PIN_BL_TFT does not have to be connected
+
+DigitalOut  Wals(PC_13);   // Wals al witch ?
+DigitalIn   k1(PC_10);     // k1   switch 1
+DigitalIn   k2(PC_12);     // k2   switch 1
+DigitalOut  DCpot(PC_3);   // Wapot alim pot
+AnalogIn    pot(PC_2);     // entrée ana pot 
+DigitalOut  led0(PA_14);   // Wled0   
+DigitalOut  led1(PA_15);   // Wled1 
+
+// initialisation diverses 
+void winit()
+   {
+   k1.mode(PullNone);     k2.mode(PullNone); 
+    
+   led0 = 1 ; led1 = 0 ;
+   DCpot = 1 ;  // alimente le pot de la carte 
+   }
+
diff -r a72b2f80ae04 -r eb61367f53ce main.cpp
--- a/main.cpp	Sat Jan 12 03:55:06 2019 +0000
+++ b/main.cpp	Sun Oct 18 16:05:21 2020 +0000
@@ -1,132 +1,56 @@
-/* KL25Z mbed library for ILI9341 touch devices
- * SPI Interface
 
- * Uses Peter Drescher ILI9341 Library
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-
+// init générales appels de lybraries 
 #include "mbed.h"
-#include "SPI_TFT_ILI9341.h"
-#include "Arial12x12.h"
-#include "touch.h"
-
+#include "IUT.h"     // programmes utiles carte IUT-BED  dans le fichier IUT.h
 
-#define     PIN_XP          PTB3
-#define     PIN_XM          PTB1
-#define     PIN_YP          PTB2
-#define     PIN_YM          PTB0
-#define     PIN_MOSI        PTD2
-#define     PIN_MISO        PTD3
-#define     PIN_SCLK        PTD1
-#define     PIN_CS_TFT      PTA5
-#define     PIN_DC_TFT      PTC8
-#define     PIN_BL_TFT      PTC9
-#define     PIN_CS_SD       PTA4
+//  après c'est la lieu de  déclaration de vos  variables et  sous programmes
+//  vos varriables et vos grogrammes commenceront par un V
+//  afin de  se différiencier des variables globales déja créées
+float  Vpot = 0;  // V pot valeur 
 
+Serial serial(SERIAL_TX, SERIAL_RX); // laison serie en USB par usb driver STlink
+// sous programme callback  à completer  en cas de reception serie .. interruption
+void callback() 
+    {serial.printf("%c\n", serial.getc()); } // ( retourne le caractère arrivé 
 
-SPI_TFT_ILI9341 TFT(PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TFT, PIN_BL_TFT, PIN_DC_TFT, "TFT");   //PIN_BL_TFT does not have to be connected
-TouchScreen tft(PIN_XP, PIN_YP, PIN_XM, PIN_YM); //init TouchScreen port pins
-
-
-// Paint application - Demonstate both TFT and Touch Screen
-int ColorPaletteHigh = 15;  //Height of color palette
-int color = White;  //Paint brush initial color
-unsigned int colors[16] = {Red, Green, Blue, Cyan, Yellow, Purple, Pink, Black, Orange, Brown, BlueGreen, White, LightPink, DarkGrey, DarkGreen, Mustard};
+//  debut du "main" 
+int main()
+{
+    winit();  // ligne obligatoire pour initialiser la carte IUT BED
+    serial.baud(115200);  // initialise la vitesse de serie 
+    serial.attach(&callback); // autorise l'arrivée de caractère usb serie
+    
+     // exemples de choses à faire
+    TFT.background(Black);   // fond ecran
+    TFT.foreground(White);   // couleur ecriture
+    TFT.cls();               // efface tout
 
-int RXPLATE = 350;  //Set this to the resistance measured across XP and XM
-int Q = 1024;  //10 bit TSC Resolution
-float TS_MINX = 5500;   //Set this to screen x min
-float TS_MAXX = 58100;  //Set this to screen x max
-float TS_MINY = 4700;   //Set this to screen y min
-float TS_MAXY = 57600;  //Set this to screen y max
-int PRESSURE = 200;     //Set this to max pressure (z) that will register as a touch event
-int v[3] ={0,0,0};      //array to roll touches for comparison and validation, initialized at zero briefly.
+    //Print : message 
+    TFT.set_font((unsigned char*) Arial28x28);
+    TFT.locate(0,5);  // 0 pix en X ,   5 en vertical
+    TFT.printf("IUT-BED2021");
+    
+    while (true) // boucle sans fin
+    {    // 
+        serial.printf("carte IUT-BED2021 connectee\r\n");
+        TFT.locate(0,100);
+        TFT.printf("bonjour");
+        
+        TFT.locate(0,75);
+        TFT.printf("pot=        " );
+        TFT.locate(0,75);
+        Vpot = pot.read();  // read (en float)  la tension sur la broche pot
+        Vpot = 3.2 * Vpot ; // sortie float de 0 a 3.2 ( 1024 pas)
+        TFT.printf("pot= %.2f", Vpot );
 
-struct point
-{
-    int x;
-    int y;
-    int z;
-};
+        wait(0.5);
+        
+        led0 = k2;     // led = etat interrupteur k2
+        led1 = !led1;  // inverse led
 
-typedef struct point Point;
-
-
-Point point(int xx, int yy, int zz){
-    Point p;
-    p.x = xx;
-    p.y = yy;
-    p.z = zz;
-    return p;
+   }
+    
 }
 
 
-Point getPoint(){
 
-    float z;
-    int y2 = tft.readTouch(PTB3,PTB1,PTB2,PTB0);    //a(analog),i(analog),n(digital),m(digital)
-    int x2 = tft.readTouch(PTB2,PTB0,PTB3,PTB1);    //Resources to help set these up
-    int z2 = tft.readTouch(PTB0,PTB3,PTB2,PTB1);    //http://electronics.stackexchange.com/questions/113223/4-wire-resisitive-touch-screen-not-working
-    int z1 = tft.readTouch(PTB3,PTB0,PTB2,PTB1);    //http://www.ti.com/lit/an/sbaa155a/sbaa155a.pdf
-    
-    if (z1!=0){
-        z = (float)z2/(float)z1;
-    }else{
-        z = 0;
-    }
-    int x = x2;
-    int y = y2;
-    return point(x,y,z);
-}
-
-    
-    
-int main(){
-    TFT.claim(stdout);          // send stdout to the TFT display
-    TFT.set_orientation(0);
-    TFT.set_font((unsigned char*) Arial12x12);  //set font to arial 12x12
-    TFT.foreground(Cyan);      // set text chars to Cyan
-    TFT.background(Purple);      // set text background to Purple
-
-    for(int i = 0; i<16; i++){
-        TFT.fillrect(i*15, 0, 15*(i+1), ColorPaletteHigh, colors[i]);   //Fill color palete with 16 colors defined in SPI_TFT_ILI9341.h
-    }
-    while(1){
-        // a point object holds x y and z coordinates.
-        Point p = getPoint();
-        //map the ADC value read to into pixel co-ordinates
-        p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240);   //Use map functionm to size p.x to screen size
-        p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320);   //Use map functionm to size p.y to screen size
-        p.z = 20+p.x * RXPLATE / Q * (p.z -1);  //Calc p.z based on above reference links
-        
-        v[2]=v[1];  //Rotate p.z touch values in array
-        v[1]=v[0];
-        v[0]=p.z;
-
-        /*TFT.locate(60,90);
-        printf("x = %d      \r\n", p.x);    //Uncomment these to see point data on screen and to obtain calibration values
-        TFT.locate(60,110);
-        printf("y = %d      \r\n", p.y);
-        TFT.locate(60,130);
-        printf("z = %d      \r\n", p.z);*/
-
-        // we have some minimum pressure we consider 'valid'
-        // pressure of 0 means no pressing!
-        if (p.z > 40 && p.z < PRESSURE & p.z == (v[1]+v[2])/2) {    //Validate that p.z senses a touch event
-            // Detect  paint brush color change
-            if(int(p.y) < ColorPaletteHigh+2){
-                color = colors[int(p.x)/15];    //Touch event occured in color palette, change color.
-            }else{
-                TFT.fillcircle(int(p.x),int(p.y),2,color);  //Touch event caused paint event with 2 pixel brush
-            }
-        }
-    }
-}
\ No newline at end of file
diff -r a72b2f80ae04 -r eb61367f53ce touch.cpp
--- a/touch.cpp	Sat Jan 12 03:55:06 2019 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-/* KL25Z mbed library for ILI9341 touch devices
- * SPI Interface
-
- * Uses Peter Drescher ILI9341 Library
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-
-#include "touch.h"
-#include "mbed.h"
-
-
-TouchScreen::TouchScreen(PinName xp, PinName yp, PinName xm, PinName ym) {
-    }
-    
-
-int TouchScreen::readTouch(PinName a, PinName i, PinName n, PinName m){
-    
-    AnalogIn   _a(a);
-    AnalogIn   _i(i);
-    DigitalOut _n(n);
-    DigitalOut _m(m);
-    int a1=1;
-    int a2=0;
-    _n = 1;
-    _m = 0;
-    wait_us(50);
-    a1 = _a.read_u16();
-    wait_us(50);
-    a2 = _a.read_u16();
-    wait_us(50);
-    _n=0;
-    return (a1+a2)/2;
-}
-
-
-                
-int map(float value, float fromSource, float toSource, float fromTarget, float toTarget){
-        return (value - fromSource) / (toSource - fromSource) * (toTarget - fromTarget) + fromTarget;
-}
\ No newline at end of file