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.
Diff: main.cpp
- Revision:
- 1:7cd9426abb58
- Parent:
- 0:eace82fb39de
- Child:
- 2:924e2280acf4
--- a/main.cpp Thu Nov 14 21:31:52 2019 +0000 +++ b/main.cpp Fri Nov 22 14:05:34 2019 +0000 @@ -1,33 +1,63 @@ #include "mbed.h" #include "glibr.h" - + Serial USB_link(USBTX, USBRX); // USB initialization -glibr GSensor(D4,D5); // I²C initialization : D4 = SDA ; D5 = SCL +glibr GSensor(D4,D5); // I²C initialization : D4 = SDA ; D5 = SCL - int main (void) { - +int main (void) +{ + USB_link.baud(115200); USB_link.format(8, SerialBase::None, 1); - uint16_t r=0,g=0; - if (GSensor.ginit()) { + uint16_t r,g,b; + if (GSensor.ginit()) { USB_link.printf("APDS-9960 initialization complete\n\r"); - } - else { + } else { USB_link.printf("Something went wrong during APDS-9960 init\n\r"); } - if(GSensor.setLEDDrive(0x00)){ // led current : 100mA - USB_link.printf("led current set at 100 mA\n\r"); +// GSensor.disableGestureSensor(); +// GSensor.disableProximitySensor(); + if( GSensor.enableLightSensor(true)) { // enables light sensor + USB_link.printf("light sensor enabled\n\r"); + } else { + USB_link.printf("Something went wrong with the light sensor\n\r"); + } + /* if(GSensor.setLEDDrive(0x00)) { // led current : 100mA + USB_link.printf("led current set at 100 mA\n\r"); } else { - USB_link.printf("Something went wrong during LED initialization\n\r"); - } + USB_link.printf("Something went wrong during LED initialization\n\r"); + }*/ while(1) { - if (GSensor.readRedLight(r)){ - USB_link.printf("red value was aquired\n\r"); - } else { - USB_link.printf("Something went wrong during red value reading\n\r"); - } - USB_link.printf("red :%d\r\n",r); + //r = GSensor.getMode(); + // USB_link.printf("mode :%hx ",r); + if (GSensor.readRedLight(r)) { + // USB_link.printf(" R :%4hu ",r); + } else { + USB_link.printf("Something went wrong during red value reading\n\r"); + } + if (GSensor.readGreenLight(g)) { + //USB_link.printf(" G :%4hu ",r); + } else { + USB_link.printf("Something went wrong during green value reading\n\r"); + } + if (GSensor.readBlueLight(b)) { + // USB_link.printf(" B :%4hu\r\n",r); + } else { + USB_link.printf("Something went wrong during blue value reading\n\r"); + } + // affichage couleur + if (r >30) { + USB_link.printf("red \r\n"); + } + if (g >30) { + USB_link.printf("green \r\n"); + } + if ((g<30)&&(r<30)) { + USB_link.printf("no color \r\n"); + } + } + return 0; - } \ No newline at end of file +} \ No newline at end of file