7Robot_Freescale / Mbed 2 deprecated freescal_cup_k22f

Dependencies:   mbed freescal_cup_k22f

Dependents:   freescal_cup_k22f

Committer:
AlexandreN7
Date:
Tue Jan 13 16:53:09 2015 +0000
Revision:
10:3424e7b66671
Parent:
8:8f886cd6a59f
Parent:
4:9730c81e3121
Child:
15:b77dc649e4f3
merge

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RobinN7 0:3af30bfbc3e5 1 #include "mbed.h"
RobinN7 0:3af30bfbc3e5 2 #include "Camera.h"
RobinN7 0:3af30bfbc3e5 3
RobinN7 0:3af30bfbc3e5 4 DigitalOut clk(PTC2);
RobinN7 0:3af30bfbc3e5 5 DigitalOut si(PTB3);
RobinN7 0:3af30bfbc3e5 6 AnalogIn pix(PTB2);
RobinN7 0:3af30bfbc3e5 7
RobinN7 0:3af30bfbc3e5 8
AlexandreN7 8:8f886cd6a59f 9 extern unsigned int pixel[128]= {0}; //
RobinN7 0:3af30bfbc3e5 10
AlexandreN7 8:8f886cd6a59f 11 void readline(void) // fonction de détection de la ligne
RobinN7 0:3af30bfbc3e5 12 {
RobinN7 0:3af30bfbc3e5 13 clk=0; // la clock est nulle au départ
RobinN7 0:3af30bfbc3e5 14 int compteur = 0,index_pixel = 0, capture_finie = 0;
AlexandreN7 8:8f886cd6a59f 15
AlexandreN7 8:8f886cd6a59f 16 while (!capture_finie) {
RobinN7 0:3af30bfbc3e5 17 if (compteur & 1) // si compteur impair => front descendant
RobinN7 0:3af30bfbc3e5 18 clk = 0;
RobinN7 0:3af30bfbc3e5 19 else // compteur pair => montant
RobinN7 0:3af30bfbc3e5 20 clk = 1;
RobinN7 0:3af30bfbc3e5 21 if(compteur == 5)
RobinN7 0:3af30bfbc3e5 22 si = 1;
AlexandreN7 8:8f886cd6a59f 23
RobinN7 0:3af30bfbc3e5 24 if (compteur == 7)
AlexandreN7 8:8f886cd6a59f 25 si=0;
AlexandreN7 8:8f886cd6a59f 26 if ( (compteur & 1) && compteur >= 7) { // mesure sur front descendant,
RobinN7 0:3af30bfbc3e5 27 // pc.printf("lecture pixel\n");
RobinN7 0:3af30bfbc3e5 28 pixel[index_pixel]=pix.read_u16();
RobinN7 0:3af30bfbc3e5 29 index_pixel ++;
RobinN7 0:3af30bfbc3e5 30 }
RobinN7 0:3af30bfbc3e5 31 wait_us(10);
RobinN7 0:3af30bfbc3e5 32 compteur++;
AlexandreN7 8:8f886cd6a59f 33
RobinN7 0:3af30bfbc3e5 34 if (index_pixel == 128)
AlexandreN7 8:8f886cd6a59f 35 capture_finie = 1;
RobinN7 0:3af30bfbc3e5 36 }
RobinN7 0:3af30bfbc3e5 37 wait_ms(1);
RobinN7 0:3af30bfbc3e5 38 }
RobinN7 0:3af30bfbc3e5 39
RobinN7 0:3af30bfbc3e5 40 void passebas()
RobinN7 0:3af30bfbc3e5 41 {
AlexandreN7 10:3424e7b66671 42
AlexandreN7 8:8f886cd6a59f 43 unsigned int tamponpixel[256] = {0};
RobinN7 3:f6a91455109c 44 int ordre=7, i=0;
AlexandreN7 8:8f886cd6a59f 45
AlexandreN7 10:3424e7b66671 46
RobinN7 2:804797b0b298 47 // Passe bas en partant de la gauche sur tamponpixel[0:127]
AlexandreN7 8:8f886cd6a59f 48 for (i=ordre; i<128; i++) {
AlexandreN7 8:8f886cd6a59f 49 for (int a=0; a<ordre; a++) {
RobinN7 0:3af30bfbc3e5 50 tamponpixel[i]+=pixel[i-a];
RobinN7 0:3af30bfbc3e5 51 }
RobinN7 0:3af30bfbc3e5 52 tamponpixel[i]/=ordre;
RobinN7 0:3af30bfbc3e5 53 }
AlexandreN7 8:8f886cd6a59f 54
RobinN7 2:804797b0b298 55 // Passe bas en partant de la droite sur tamponpixel[128:255]
AlexandreN7 8:8f886cd6a59f 56 for (i=127-ordre; i>=0; i--) {
AlexandreN7 8:8f886cd6a59f 57 for (int a=0; a<ordre; a++) {
RobinN7 2:804797b0b298 58 tamponpixel[255-i]+=pixel[i+a];
RobinN7 0:3af30bfbc3e5 59 }
RobinN7 2:804797b0b298 60 tamponpixel[255-i]/=ordre;
RobinN7 0:3af30bfbc3e5 61 }
AlexandreN7 8:8f886cd6a59f 62
AlexandreN7 8:8f886cd6a59f 63
RobinN7 0:3af30bfbc3e5 64 // Actualisation de l'image filtrée
AlexandreN7 10:3424e7b66671 65
RobinN7 0:3af30bfbc3e5 66 for (i=0;i<128;i++)
RobinN7 0:3af30bfbc3e5 67 {
RobinN7 4:9730c81e3121 68 pixel[i]=(tamponpixel[i]+tamponpixel[255-i])/2;
AlexandreN7 10:3424e7b66671 69
RobinN7 0:3af30bfbc3e5 70 }
AlexandreN7 8:8f886cd6a59f 71 }
AlexandreN7 8:8f886cd6a59f 72
AlexandreN7 8:8f886cd6a59f 73 //fonction qui dérive le signal de la camera
AlexandreN7 8:8f886cd6a59f 74 void derivation()
AlexandreN7 8:8f886cd6a59f 75 {
AlexandreN7 8:8f886cd6a59f 76 unsigned int tamponpixel[256] = {0};
AlexandreN7 8:8f886cd6a59f 77
AlexandreN7 8:8f886cd6a59f 78 for (int i=1; i<128; i++) {
AlexandreN7 8:8f886cd6a59f 79 tamponpixel[i]=pixel[i-1]-pixel[i];
AlexandreN7 8:8f886cd6a59f 80 }
AlexandreN7 8:8f886cd6a59f 81
AlexandreN7 8:8f886cd6a59f 82 // Actualisation de l'image filtrée
AlexandreN7 8:8f886cd6a59f 83 for (int i=0; i<128; i++) {
AlexandreN7 8:8f886cd6a59f 84 pixel[i]=tamponpixel[i];
AlexandreN7 8:8f886cd6a59f 85 }
AlexandreN7 8:8f886cd6a59f 86
RobinN7 0:3af30bfbc3e5 87 }