marc le dep

Dependencies:   BSP_DISCO_F429ZI LCD_DISCO_F429ZI TS_DISCO_F429ZI mbed

Committer:
Alex_mln
Date:
Thu Mar 29 07:14:46 2018 +0000
Revision:
1:59fe933886bd
Parent:
0:4910cdb3d377
sghkjlm

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Alex_mln 0:4910cdb3d377 1 #include "calibrage.h"
Alex_mln 0:4910cdb3d377 2 #include "fonctions.h"
Alex_mln 0:4910cdb3d377 3
Alex_mln 0:4910cdb3d377 4
Alex_mln 0:4910cdb3d377 5 LCD_DISCO_F429ZI lcd2;
Alex_mln 0:4910cdb3d377 6 //LCD_DISCO_F429ZI lcd;
Alex_mln 0:4910cdb3d377 7 TS_DISCO_F429ZI ts2;
Alex_mln 0:4910cdb3d377 8 TS_StateTypeDef tsState2;
Alex_mln 0:4910cdb3d377 9
Alex_mln 0:4910cdb3d377 10 AnalogIn capteur1(PF_6);
Alex_mln 0:4910cdb3d377 11 AnalogIn capteur2(PF_7);
Alex_mln 0:4910cdb3d377 12 AnalogIn capteur3(PF_8);
Alex_mln 0:4910cdb3d377 13
Alex_mln 0:4910cdb3d377 14
Alex_mln 0:4910cdb3d377 15
Alex_mln 0:4910cdb3d377 16 uint16_t xc, yc;
Alex_mln 0:4910cdb3d377 17
Alex_mln 0:4910cdb3d377 18
Alex_mln 0:4910cdb3d377 19
Alex_mln 0:4910cdb3d377 20 void detectionc(){
Alex_mln 0:4910cdb3d377 21 xc = tsState2.X;
Alex_mln 0:4910cdb3d377 22 yc = tsState2.Y;
Alex_mln 0:4910cdb3d377 23 uint8_t text[7];
Alex_mln 0:4910cdb3d377 24 sprintf((char*)text, "%d; %d", xc, yc);
Alex_mln 0:4910cdb3d377 25 lcd2.DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); }
Alex_mln 0:4910cdb3d377 26
Alex_mln 0:4910cdb3d377 27
Alex_mln 0:4910cdb3d377 28
Alex_mln 0:4910cdb3d377 29
Alex_mln 0:4910cdb3d377 30
Alex_mln 0:4910cdb3d377 31 void interface_noir(){
Alex_mln 0:4910cdb3d377 32 lcd2.Clear(LCD_COLOR_WHITE);
Alex_mln 0:4910cdb3d377 33
Alex_mln 0:4910cdb3d377 34 lcd2.SetTextColor(LCD_COLOR_BLUE);
Alex_mln 0:4910cdb3d377 35 lcd2.FillRect(40,25,150,40);
Alex_mln 0:4910cdb3d377 36 lcd2.SetBackColor(LCD_COLOR_BLUE);
Alex_mln 0:4910cdb3d377 37 lcd2.SetTextColor(LCD_COLOR_WHITE);
Alex_mln 0:4910cdb3d377 38 lcd2.DisplayStringAt(0, LINE(2), (uint8_t *)"Calibrage", CENTER_MODE);
Alex_mln 0:4910cdb3d377 39
Alex_mln 0:4910cdb3d377 40 lcd2.SetBackColor(LCD_COLOR_WHITE);
Alex_mln 0:4910cdb3d377 41 lcd2.SetTextColor(LCD_COLOR_BLACK);
Alex_mln 0:4910cdb3d377 42 lcd2.DisplayStringAt(0, LINE(7), (uint8_t *)"Mesure du noir", CENTER_MODE);
Alex_mln 0:4910cdb3d377 43
Alex_mln 0:4910cdb3d377 44 lcd2.SetTextColor(LCD_COLOR_BLUE);
Alex_mln 0:4910cdb3d377 45 lcd2.FillCircle(120,235,50);
Alex_mln 0:4910cdb3d377 46 lcd2.SetBackColor(LCD_COLOR_BLUE);
Alex_mln 0:4910cdb3d377 47 lcd2.SetTextColor(LCD_COLOR_BLACK);
Alex_mln 0:4910cdb3d377 48 lcd2.DisplayStringAt(0, 230, (uint8_t *)" OK", CENTER_MODE);
Alex_mln 0:4910cdb3d377 49 }
Alex_mln 0:4910cdb3d377 50
Alex_mln 0:4910cdb3d377 51
Alex_mln 0:4910cdb3d377 52
Alex_mln 0:4910cdb3d377 53 void interface_blanc(){
Alex_mln 0:4910cdb3d377 54 lcd2.Clear(LCD_COLOR_WHITE);
Alex_mln 0:4910cdb3d377 55
Alex_mln 0:4910cdb3d377 56 lcd2.SetTextColor(LCD_COLOR_BLUE);
Alex_mln 0:4910cdb3d377 57 lcd2.FillRect(40,25,150,40);
Alex_mln 0:4910cdb3d377 58 lcd2.SetBackColor(LCD_COLOR_BLUE);
Alex_mln 0:4910cdb3d377 59 lcd2.SetTextColor(LCD_COLOR_WHITE);
Alex_mln 0:4910cdb3d377 60 lcd2.DisplayStringAt(0, LINE(2), (uint8_t *)"Calibrage", CENTER_MODE);
Alex_mln 0:4910cdb3d377 61
Alex_mln 0:4910cdb3d377 62 lcd2.SetBackColor(LCD_COLOR_WHITE);
Alex_mln 0:4910cdb3d377 63 lcd2.SetTextColor(LCD_COLOR_BLACK);
Alex_mln 0:4910cdb3d377 64 lcd2.DisplayStringAt(0, LINE(7), (uint8_t *)"Mesure du blanc", CENTER_MODE);
Alex_mln 0:4910cdb3d377 65
Alex_mln 0:4910cdb3d377 66 lcd2.SetTextColor(LCD_COLOR_BLUE);
Alex_mln 0:4910cdb3d377 67 lcd2.FillCircle(120,235,50);
Alex_mln 0:4910cdb3d377 68 lcd2.SetBackColor(LCD_COLOR_BLUE);
Alex_mln 0:4910cdb3d377 69 lcd2.SetTextColor(LCD_COLOR_BLACK);
Alex_mln 0:4910cdb3d377 70 lcd2.DisplayStringAt(0, 230, (uint8_t *)" OK", CENTER_MODE);
Alex_mln 0:4910cdb3d377 71 }
Alex_mln 0:4910cdb3d377 72
Alex_mln 0:4910cdb3d377 73 void affichage(int* pointeur){
Alex_mln 0:4910cdb3d377 74 lcd2.Clear(LCD_COLOR_WHITE);
Alex_mln 0:4910cdb3d377 75 lcd2.SetBackColor(LCD_COLOR_WHITE);
Alex_mln 0:4910cdb3d377 76 lcd2.SetTextColor(LCD_COLOR_BLACK);
Alex_mln 0:4910cdb3d377 77 for(int i=0;i<3;i++){
Alex_mln 0:4910cdb3d377 78 uint8_t text[7];
Alex_mln 0:4910cdb3d377 79 sprintf((char*)text, "%d", *(pointeur+i));
Alex_mln 0:4910cdb3d377 80 lcd2.DisplayStringAt(0, LINE(2*i), (uint8_t *)&text, LEFT_MODE);
Alex_mln 0:4910cdb3d377 81
Alex_mln 0:4910cdb3d377 82 }
Alex_mln 0:4910cdb3d377 83 wait(2);
Alex_mln 0:4910cdb3d377 84 }
Alex_mln 0:4910cdb3d377 85
Alex_mln 0:4910cdb3d377 86
Alex_mln 0:4910cdb3d377 87
Alex_mln 0:4910cdb3d377 88
Alex_mln 0:4910cdb3d377 89 int* calibrage(){
Alex_mln 0:4910cdb3d377 90 uint8_t status2= ts2.Init(lcd2.GetXSize(), lcd2.GetYSize());
Alex_mln 0:4910cdb3d377 91
Alex_mln 0:4910cdb3d377 92 ts2.GetState(&tsState2);
Alex_mln 0:4910cdb3d377 93 detectionc();
Alex_mln 0:4910cdb3d377 94 wait(0.1);
Alex_mln 0:4910cdb3d377 95 // Le but est de calculer une valeur qui servira de seuil pour savoir si le capteur est en face du noir ou du blanc, on travaille en analogique et on prend la valeur intermediaire pour chaque capteur
Alex_mln 0:4910cdb3d377 96
Alex_mln 0:4910cdb3d377 97 int * pointeur = (int*)malloc(3*sizeof(int));
Alex_mln 0:4910cdb3d377 98
Alex_mln 0:4910cdb3d377 99 interface_noir();
Alex_mln 0:4910cdb3d377 100
Alex_mln 0:4910cdb3d377 101 while((xc<72 || xc>172) || (yc>295 || yc<195)){
Alex_mln 0:4910cdb3d377 102 ts2.GetState(&tsState2);
Alex_mln 0:4910cdb3d377 103 detectionc();
Alex_mln 0:4910cdb3d377 104 wait(0.05);}
Alex_mln 0:4910cdb3d377 105
Alex_mln 0:4910cdb3d377 106 int noir1=capteur1.read()*1000;
Alex_mln 0:4910cdb3d377 107 int noir2=capteur2.read()*1000;
Alex_mln 0:4910cdb3d377 108 int noir3=capteur3.read()*1000;
Alex_mln 0:4910cdb3d377 109
Alex_mln 0:4910cdb3d377 110 wait(0.1);
Alex_mln 0:4910cdb3d377 111 lcd2.Clear(LCD_COLOR_WHITE);
Alex_mln 0:4910cdb3d377 112 lcd2.FillRect(50,50,150,50);
Alex_mln 0:4910cdb3d377 113 lcd2.SetBackColor(LCD_COLOR_BLACK);
Alex_mln 0:4910cdb3d377 114 lcd2.SetTextColor(LCD_COLOR_WHITE);
Alex_mln 0:4910cdb3d377 115 lcd2.DisplayStringAt(0, LINE(4), (uint8_t *)"Next ->", CENTER_MODE);
Alex_mln 0:4910cdb3d377 116
Alex_mln 0:4910cdb3d377 117 while((xc<47 || xc>205) || (yc>100 || yc<50)){
Alex_mln 0:4910cdb3d377 118 ts2.GetState(&tsState2);
Alex_mln 0:4910cdb3d377 119 detectionc();
Alex_mln 0:4910cdb3d377 120 wait(0.05);}
Alex_mln 0:4910cdb3d377 121
Alex_mln 0:4910cdb3d377 122 wait(0.01);
Alex_mln 0:4910cdb3d377 123 interface_blanc();
Alex_mln 0:4910cdb3d377 124
Alex_mln 0:4910cdb3d377 125 while((xc<72 || xc>172) || (yc>295 || yc<195)){
Alex_mln 0:4910cdb3d377 126 ts2.GetState(&tsState2);
Alex_mln 0:4910cdb3d377 127 detectionc();
Alex_mln 0:4910cdb3d377 128 wait(0.05);}
Alex_mln 0:4910cdb3d377 129
Alex_mln 0:4910cdb3d377 130 int blanc1=capteur1.read()*1000;
Alex_mln 0:4910cdb3d377 131 int blanc2=capteur2.read()*1000;
Alex_mln 0:4910cdb3d377 132 int blanc3=capteur3.read()*1000;
Alex_mln 0:4910cdb3d377 133
Alex_mln 0:4910cdb3d377 134
Alex_mln 0:4910cdb3d377 135
Alex_mln 0:4910cdb3d377 136 *pointeur=(blanc1+noir1)/2;
Alex_mln 0:4910cdb3d377 137 *(pointeur+1)=(blanc2+noir2)/2;
Alex_mln 0:4910cdb3d377 138 *(pointeur+2)=(blanc3+noir3)/2;
Alex_mln 0:4910cdb3d377 139
Alex_mln 0:4910cdb3d377 140 affichage(pointeur);
Alex_mln 0:4910cdb3d377 141
Alex_mln 0:4910cdb3d377 142
Alex_mln 0:4910cdb3d377 143
Alex_mln 0:4910cdb3d377 144
Alex_mln 0:4910cdb3d377 145
Alex_mln 0:4910cdb3d377 146 return(pointeur);
Alex_mln 0:4910cdb3d377 147
Alex_mln 0:4910cdb3d377 148 }