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@1:7cd9426abb58, 2019-11-22 (annotated)
- Committer:
- guilhemMBED
- Date:
- Fri Nov 22 14:05:34 2019 +0000
- Revision:
- 1:7cd9426abb58
- Parent:
- 0:eace82fb39de
- Child:
- 2:924e2280acf4
fonctionnel avec detection de couleur
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 | 1:7cd9426abb58 | 13 | uint16_t r,g,b; |
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 | 1:7cd9426abb58 | 26 | /* if(GSensor.setLEDDrive(0x00)) { // led current : 100mA |
guilhemMBED | 1:7cd9426abb58 | 27 | USB_link.printf("led current set at 100 mA\n\r"); |
guilhemMBED | 0:eace82fb39de | 28 | } else { |
guilhemMBED | 1:7cd9426abb58 | 29 | USB_link.printf("Something went wrong during LED initialization\n\r"); |
guilhemMBED | 1:7cd9426abb58 | 30 | }*/ |
guilhemMBED | 0:eace82fb39de | 31 | while(1) { |
guilhemMBED | 1:7cd9426abb58 | 32 | //r = GSensor.getMode(); |
guilhemMBED | 1:7cd9426abb58 | 33 | // USB_link.printf("mode :%hx ",r); |
guilhemMBED | 1:7cd9426abb58 | 34 | if (GSensor.readRedLight(r)) { |
guilhemMBED | 1:7cd9426abb58 | 35 | // USB_link.printf(" R :%4hu ",r); |
guilhemMBED | 1:7cd9426abb58 | 36 | } else { |
guilhemMBED | 1:7cd9426abb58 | 37 | USB_link.printf("Something went wrong during red value reading\n\r"); |
guilhemMBED | 1:7cd9426abb58 | 38 | } |
guilhemMBED | 1:7cd9426abb58 | 39 | if (GSensor.readGreenLight(g)) { |
guilhemMBED | 1:7cd9426abb58 | 40 | //USB_link.printf(" G :%4hu ",r); |
guilhemMBED | 1:7cd9426abb58 | 41 | } else { |
guilhemMBED | 1:7cd9426abb58 | 42 | USB_link.printf("Something went wrong during green value reading\n\r"); |
guilhemMBED | 1:7cd9426abb58 | 43 | } |
guilhemMBED | 1:7cd9426abb58 | 44 | if (GSensor.readBlueLight(b)) { |
guilhemMBED | 1:7cd9426abb58 | 45 | // USB_link.printf(" B :%4hu\r\n",r); |
guilhemMBED | 1:7cd9426abb58 | 46 | } else { |
guilhemMBED | 1:7cd9426abb58 | 47 | USB_link.printf("Something went wrong during blue value reading\n\r"); |
guilhemMBED | 1:7cd9426abb58 | 48 | } |
guilhemMBED | 1:7cd9426abb58 | 49 | // affichage couleur |
guilhemMBED | 1:7cd9426abb58 | 50 | if (r >30) { |
guilhemMBED | 1:7cd9426abb58 | 51 | USB_link.printf("red \r\n"); |
guilhemMBED | 1:7cd9426abb58 | 52 | } |
guilhemMBED | 1:7cd9426abb58 | 53 | if (g >30) { |
guilhemMBED | 1:7cd9426abb58 | 54 | USB_link.printf("green \r\n"); |
guilhemMBED | 1:7cd9426abb58 | 55 | } |
guilhemMBED | 1:7cd9426abb58 | 56 | if ((g<30)&&(r<30)) { |
guilhemMBED | 1:7cd9426abb58 | 57 | USB_link.printf("no color \r\n"); |
guilhemMBED | 1:7cd9426abb58 | 58 | } |
guilhemMBED | 1:7cd9426abb58 | 59 | |
guilhemMBED | 0:eace82fb39de | 60 | } |
guilhemMBED | 1:7cd9426abb58 | 61 | |
guilhemMBED | 0:eace82fb39de | 62 | return 0; |
guilhemMBED | 1:7cd9426abb58 | 63 | } |