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@2:924e2280acf4, 2019-11-22 (annotated)
- Committer:
- guilhemMBED
- Date:
- Fri Nov 22 15:14:38 2019 +0000
- Revision:
- 2:924e2280acf4
- Parent:
- 1:7cd9426abb58
- Child:
- 3:f41f244de0b3
marche mieux ;
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 | 1:7cd9426abb58 | 5 | glibr GSensor(D4,D5); // I²C initialization : D4 = SDA ; D5 = SCL |
guilhemMBED | 0:eace82fb39de | 6 | |
guilhemMBED | 0:eace82fb39de | 7 | |
guilhemMBED | 1:7cd9426abb58 | 8 | int main (void) |
guilhemMBED | 1:7cd9426abb58 | 9 | { |
guilhemMBED | 1:7cd9426abb58 | 10 | |
guilhemMBED | 0:eace82fb39de | 11 | USB_link.baud(115200); |
guilhemMBED | 0:eace82fb39de | 12 | USB_link.format(8, SerialBase::None, 1); |
guilhemMBED | 2:924e2280acf4 | 13 | uint16_t r,g,b,a; |
guilhemMBED | 1:7cd9426abb58 | 14 | if (GSensor.ginit()) { |
guilhemMBED | 0:eace82fb39de | 15 | USB_link.printf("APDS-9960 initialization complete\n\r"); |
guilhemMBED | 1:7cd9426abb58 | 16 | } else { |
guilhemMBED | 0:eace82fb39de | 17 | USB_link.printf("Something went wrong during APDS-9960 init\n\r"); |
guilhemMBED | 0:eace82fb39de | 18 | } |
guilhemMBED | 1:7cd9426abb58 | 19 | // GSensor.disableGestureSensor(); |
guilhemMBED | 1:7cd9426abb58 | 20 | // GSensor.disableProximitySensor(); |
guilhemMBED | 1:7cd9426abb58 | 21 | if( GSensor.enableLightSensor(true)) { // enables light sensor |
guilhemMBED | 1:7cd9426abb58 | 22 | USB_link.printf("light sensor enabled\n\r"); |
guilhemMBED | 1:7cd9426abb58 | 23 | } else { |
guilhemMBED | 1:7cd9426abb58 | 24 | USB_link.printf("Something went wrong with the light sensor\n\r"); |
guilhemMBED | 1:7cd9426abb58 | 25 | } |
guilhemMBED | 2:924e2280acf4 | 26 | |
guilhemMBED | 1:7cd9426abb58 | 27 | /* if(GSensor.setLEDDrive(0x00)) { // led current : 100mA |
guilhemMBED | 1:7cd9426abb58 | 28 | USB_link.printf("led current set at 100 mA\n\r"); |
guilhemMBED | 0:eace82fb39de | 29 | } else { |
guilhemMBED | 1:7cd9426abb58 | 30 | USB_link.printf("Something went wrong during LED initialization\n\r"); |
guilhemMBED | 1:7cd9426abb58 | 31 | }*/ |
guilhemMBED | 0:eace82fb39de | 32 | while(1) { |
guilhemMBED | 1:7cd9426abb58 | 33 | //r = GSensor.getMode(); |
guilhemMBED | 1:7cd9426abb58 | 34 | // USB_link.printf("mode :%hx ",r); |
guilhemMBED | 1:7cd9426abb58 | 35 | if (GSensor.readRedLight(r)) { |
guilhemMBED | 2:924e2280acf4 | 36 | // USB_link.printf("R:%4hu ",r); |
guilhemMBED | 1:7cd9426abb58 | 37 | } else { |
guilhemMBED | 1:7cd9426abb58 | 38 | USB_link.printf("Something went wrong during red value reading\n\r"); |
guilhemMBED | 1:7cd9426abb58 | 39 | } |
guilhemMBED | 2:924e2280acf4 | 40 | |
guilhemMBED | 1:7cd9426abb58 | 41 | if (GSensor.readGreenLight(g)) { |
guilhemMBED | 2:924e2280acf4 | 42 | //USB_link.printf("G:%4hu ",g); |
guilhemMBED | 1:7cd9426abb58 | 43 | } else { |
guilhemMBED | 1:7cd9426abb58 | 44 | USB_link.printf("Something went wrong during green value reading\n\r"); |
guilhemMBED | 1:7cd9426abb58 | 45 | } |
guilhemMBED | 2:924e2280acf4 | 46 | |
guilhemMBED | 1:7cd9426abb58 | 47 | if (GSensor.readBlueLight(b)) { |
guilhemMBED | 2:924e2280acf4 | 48 | // USB_link.printf("B:%4hu ",b); |
guilhemMBED | 2:924e2280acf4 | 49 | } else { |
guilhemMBED | 2:924e2280acf4 | 50 | USB_link.printf("Something went wrong during blue value reading\n\r"); |
guilhemMBED | 2:924e2280acf4 | 51 | } |
guilhemMBED | 2:924e2280acf4 | 52 | |
guilhemMBED | 2:924e2280acf4 | 53 | if (GSensor.readAmbientLight(a)) { |
guilhemMBED | 2:924e2280acf4 | 54 | // USB_link.printf("light:%4hu\r\n",a); |
guilhemMBED | 1:7cd9426abb58 | 55 | } else { |
guilhemMBED | 1:7cd9426abb58 | 56 | USB_link.printf("Something went wrong during blue value reading\n\r"); |
guilhemMBED | 1:7cd9426abb58 | 57 | } |
guilhemMBED | 2:924e2280acf4 | 58 | |
guilhemMBED | 1:7cd9426abb58 | 59 | // affichage couleur |
guilhemMBED | 2:924e2280acf4 | 60 | if (a>100) { |
guilhemMBED | 2:924e2280acf4 | 61 | USB_link.printf("no color \r\n"); |
guilhemMBED | 2:924e2280acf4 | 62 | } |
guilhemMBED | 2:924e2280acf4 | 63 | else if (r > g ) { |
guilhemMBED | 1:7cd9426abb58 | 64 | USB_link.printf("red \r\n"); |
guilhemMBED | 1:7cd9426abb58 | 65 | } |
guilhemMBED | 2:924e2280acf4 | 66 | else if (g > r ) { |
guilhemMBED | 1:7cd9426abb58 | 67 | USB_link.printf("green \r\n"); |
guilhemMBED | 1:7cd9426abb58 | 68 | } |
guilhemMBED | 2:924e2280acf4 | 69 | |
guilhemMBED | 1:7cd9426abb58 | 70 | |
guilhemMBED | 0:eace82fb39de | 71 | } |
guilhemMBED | 1:7cd9426abb58 | 72 | |
guilhemMBED | 0:eace82fb39de | 73 | return 0; |
guilhemMBED | 1:7cd9426abb58 | 74 | } |