Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@3:f41f244de0b3, 2019-11-29 (annotated)
- Committer:
- guilhemMBED
- Date:
- Fri Nov 29 12:46:05 2019 +0000
- Revision:
- 3:f41f244de0b3
- Parent:
- 2:924e2280acf4
- Child:
- 4:28185f157011
- Child:
- 5:7a63cb7ec666
prog test 3 capteurs
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
guilhemMBED | 0:eace82fb39de | 1 | #include "mbed.h" |
guilhemMBED | 0:eace82fb39de | 2 | #include "glibr.h" |
guilhemMBED | 1:7cd9426abb58 | 3 | |
guilhemMBED | 0:eace82fb39de | 4 | Serial USB_link(USBTX, USBRX); // USB initialization |
guilhemMBED | 3:f41f244de0b3 | 5 | |
guilhemMBED | 3:f41f244de0b3 | 6 | glibr capt1(D4,D5); // I²C initialization : D4 = SDA ; D5 = SCL |
guilhemMBED | 3:f41f244de0b3 | 7 | glibr capt2(D6,D7); // D6 = SDA ; D7 = SCL |
guilhemMBED | 3:f41f244de0b3 | 8 | glibr capt3(D8,D9); // D8 = SDA ; D9 = SCL |
guilhemMBED | 0:eace82fb39de | 9 | |
guilhemMBED | 3:f41f244de0b3 | 10 | bool initialization(void) |
guilhemMBED | 3:f41f244de0b3 | 11 | { |
guilhemMBED | 3:f41f244de0b3 | 12 | // USB initialization |
guilhemMBED | 3:f41f244de0b3 | 13 | USB_link.baud(115200); |
guilhemMBED | 3:f41f244de0b3 | 14 | USB_link.format(8, SerialBase::None, 1); |
guilhemMBED | 3:f41f244de0b3 | 15 | |
guilhemMBED | 3:f41f244de0b3 | 16 | // sensors initalization |
guilhemMBED | 3:f41f244de0b3 | 17 | if( (capt1.ginit())&& (capt1.enableLightSensor(true))&& (capt2.ginit())&& (capt2.enableLightSensor(true)) && (capt3.ginit())&& (capt3.enableLightSensor(true)) ) { |
guilhemMBED | 3:f41f244de0b3 | 18 | return true; |
guilhemMBED | 3:f41f244de0b3 | 19 | } else { |
guilhemMBED | 3:f41f244de0b3 | 20 | return false; |
guilhemMBED | 3:f41f244de0b3 | 21 | } |
guilhemMBED | 3:f41f244de0b3 | 22 | } |
guilhemMBED | 0:eace82fb39de | 23 | |
guilhemMBED | 1:7cd9426abb58 | 24 | int main (void) |
guilhemMBED | 1:7cd9426abb58 | 25 | { |
guilhemMBED | 3:f41f244de0b3 | 26 | int i; |
guilhemMBED | 3:f41f244de0b3 | 27 | uint16_t r[3],g[3],b[3],a[3]; |
guilhemMBED | 3:f41f244de0b3 | 28 | if (initialization()) { |
guilhemMBED | 3:f41f244de0b3 | 29 | USB_link.printf("Initialization complete \r\n"); |
guilhemMBED | 1:7cd9426abb58 | 30 | } else { |
guilhemMBED | 3:f41f244de0b3 | 31 | USB_link.printf("Error during initialization\r\n"); |
guilhemMBED | 1:7cd9426abb58 | 32 | } |
guilhemMBED | 2:924e2280acf4 | 33 | |
guilhemMBED | 0:eace82fb39de | 34 | while(1) { |
guilhemMBED | 3:f41f244de0b3 | 35 | capt1.readRedLight(r[0]); |
guilhemMBED | 3:f41f244de0b3 | 36 | capt1.readGreenLight(g[0]); |
guilhemMBED | 3:f41f244de0b3 | 37 | capt1.readBlueLight(b[0]) ; |
guilhemMBED | 3:f41f244de0b3 | 38 | capt1.readAmbientLight(a[0]); |
guilhemMBED | 3:f41f244de0b3 | 39 | |
guilhemMBED | 3:f41f244de0b3 | 40 | capt2.readRedLight(r[1]); |
guilhemMBED | 3:f41f244de0b3 | 41 | capt2.readGreenLight(g[1]); |
guilhemMBED | 3:f41f244de0b3 | 42 | capt2.readBlueLight(b[1]) ; |
guilhemMBED | 3:f41f244de0b3 | 43 | capt2.readAmbientLight(a[1]); |
guilhemMBED | 3:f41f244de0b3 | 44 | |
guilhemMBED | 3:f41f244de0b3 | 45 | capt3.readRedLight(r[2]); |
guilhemMBED | 3:f41f244de0b3 | 46 | capt3.readGreenLight(g[2]); |
guilhemMBED | 3:f41f244de0b3 | 47 | capt3.readBlueLight(b[2]) ; |
guilhemMBED | 3:f41f244de0b3 | 48 | capt3.readAmbientLight(a[2]); |
guilhemMBED | 3:f41f244de0b3 | 49 | |
guilhemMBED | 3:f41f244de0b3 | 50 | // display of color |
guilhemMBED | 3:f41f244de0b3 | 51 | /*for(i=0; i<3; i++) { |
guilhemMBED | 3:f41f244de0b3 | 52 | if (a[i]>100) { |
guilhemMBED | 3:f41f244de0b3 | 53 | USB_link.printf("n ||"); |
guilhemMBED | 3:f41f244de0b3 | 54 | } else if (r[i] > g[i] ) { |
guilhemMBED | 3:f41f244de0b3 | 55 | USB_link.printf("r ||"); |
guilhemMBED | 3:f41f244de0b3 | 56 | } else if (g[i] > r[i] ) { |
guilhemMBED | 3:f41f244de0b3 | 57 | USB_link.printf("g ||"); |
guilhemMBED | 3:f41f244de0b3 | 58 | } |
guilhemMBED | 1:7cd9426abb58 | 59 | } |
guilhemMBED | 3:f41f244de0b3 | 60 | USB_link.printf("\r\n");*/ |
guilhemMBED | 2:924e2280acf4 | 61 | |
guilhemMBED | 3:f41f244de0b3 | 62 | //display of red and green variables |
guilhemMBED | 3:f41f244de0b3 | 63 | for(i=0; i<3; i++) { |
guilhemMBED | 3:f41f244de0b3 | 64 | USB_link.printf("Capt%d r: %hu g : %hu || ",i,r[i],g[i]); |
guilhemMBED | 1:7cd9426abb58 | 65 | } |
guilhemMBED | 3:f41f244de0b3 | 66 | USB_link.printf("\r\n"); |
guilhemMBED | 0:eace82fb39de | 67 | } |
guilhemMBED | 0:eace82fb39de | 68 | return 0; |
guilhemMBED | 1:7cd9426abb58 | 69 | } |