A simple hello_world program for the ADJD-S311 color sensor

Dependencies:   ADJDs311 mbed

Files at this revision

API Documentation at this revision

Comitter:
CheeseW
Date:
Mon Mar 24 05:33:13 2014 +0000
Child:
1:01a7d7326f80
Commit message:
Out for publication!

Changed in this revision

ADJDs311.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ADJDs311.lib	Mon Mar 24 05:33:13 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/CheeseW/code/ADJDs311/#5d0bc4df0701
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Mar 24 05:33:13 2014 +0000
@@ -0,0 +1,54 @@
+#include "mbed.h"
+#include "ADJDs311.h"
+
+ADJDs311 colorSensor(p28, p27, p23);
+Serial pc(USBTX, USBRX);
+
+int main() {
+RGBC color;
+RGBC cap;
+RGBC inte;
+RGBC offset;
+    
+    
+    colorSensor.ledMode(true);  // turn on the on board led
+    pc.printf("Calibartion started.\n\rPress any key to continue...\n\r");
+    
+    while(!pc.readable());     // waiting for the setup of calibration (the brightest condition to be measued)
+   
+    colorSensor.calibrate();   // calibrate the sensor to get the optimised gain
+
+   while(pc.readable())         // discard extra char input
+    {
+        pc.getc();
+    }
+   
+    pc.printf("Getting offset\n\rPress any key to continue...\n\r");
+     while(!pc.readable());     // waiting for the set up of calibration (the brightest condition to be measued)
+    
+    offset = colorSensor.setOffset();   // get and set the color offset to compensate on board LED color
+    
+    while(pc.readable())        // discard extra char input
+    {
+        pc.getc();
+    }
+    
+    cap = colorSensor.getColorCap();    // get the gain of the capacitors
+    inte = colorSensor.getColorInt();   // get the gain of integration time slot
+    pc.printf("\n\n\n\rCalibartion completed.\n\r");
+    pc.printf("\nCaps:\t\tr: %4d,\tg: %4d,\tb: %4d,\tc: %4d\n\r", cap.red, cap.green, cap.blue, cap.clear);
+    pc.printf("Ints:\t\tr: %4d,\tg: %4d,\tb: %4d,\tc: %4d\n\r", inte.red, inte.green, inte.blue, inte.clear);
+   pc.printf("Offsets:\tr: %4d,\tg: %4d,\tb: %4d,\tc: %4d\n\r", offset.red, offset.green, offset.blue, offset.clear);
+    pc.printf("\nPress any key to continue\n\r");
+    while(!pc.readable());  // waiting calibration and offset info confirmation
+    while(pc.readable())    // discard extra char input
+    {
+        pc.getc();      
+    }
+    colorSensor.ledMode(true);  // node that wetOffset will turn off the on board LED automatically. Need to turn it on again
+    while(1) {
+        color = colorSensor.read();     // get the rgb and clear data from sensor
+        pc.printf("red: %4d,\tgreen: %4d,\tblue: %4d,\tclear: %4d\r", color.red, color.green, color.blue, color.clear);
+        wait(0.15);
+    }    
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Mar 24 05:33:13 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/8e73be2a2ac1
\ No newline at end of file