Example program connecting the TCS34725 RGB color sensor to the K64F board using I2C

Dependencies:   mbed

Fork of TCS34725 by Hannes Tschofenig

Files at this revision

API Documentation at this revision

Comitter:
gscuttari
Date:
Wed Jun 13 15:51:08 2018 +0000
Parent:
0:139238e5829c
Child:
2:dfbc36bf793a
Commit message:
tcs34725

Changed in this revision

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
--- a/main.cpp	Sat May 09 08:27:06 2015 +0000
+++ b/main.cpp	Wed Jun 13 15:51:08 2018 +0000
@@ -1,33 +1,50 @@
 // Example program connecting to the TCS34725 Color Sensor to the K64F using I2C
 
 #include "mbed.h"
+#include <string.h>
+#include <stdio.h>
 
 I2C i2c(I2C_SDA, I2C_SCL); //pins for I2C communication (SDA, SCL)
-Serial pc(USBTX, USBRX);
+//Serial pc(USBTX, USBRX);
 
 int sensor_addr = 41 << 1;
+//#define sensor_addr 0x29
+#define TCS34725_COMMAND_BIT 0x80
 
-DigitalOut green(LED_GREEN);
+
+DigitalOut led(LED1);
 
 int main() {
-    pc.baud(9600);
-    green = 1; // off
+    // pc.baud(9600);
+     printf("\nStart\n");
+       wait(1);
+    led = 0; // LED OFF
     
     // Connect to the Color sensor and verify whether we connected to the correct sensor. 
     
-    i2c.frequency(200000);
+    i2c.frequency(400000);
     
     char id_regval[1] = {146};
     char data[1] = {0};
     i2c.write(sensor_addr,id_regval,1, true);
     i2c.read(sensor_addr,data,1,false);
     
+    scanf("%s", data);
+    printf("%s", data);
+    
+    
+    wait(2);
+    
     if (data[0]==68) {
-        green = 0;
+       led = 0; // LED OFF
+        printf("\n68\n");
         wait (2); 
-        green = 1;
+        led = 1; // LED ON
         } else {
-        green = 1; 
+        printf("\nNO 68\n");
+        wait (2); 
+        led = 1; // LED ON
+        
     }
     
     // Initialize color sensor
@@ -74,8 +91,10 @@
         
         // print sensor readings
         
-        pc.printf("Clear (%d), Red (%d), Green (%d), Blue (%d)\n", clear_value, red_value, green_value, blue_value);
+        printf("Clear (%d), Red (%d), Green (%d), Blue (%d)\n", clear_value, red_value, green_value, blue_value);
+        printf("\n-------------------------------------------------------------\n");
         wait(0.5);
     }
     
 }
+
--- a/mbed.bld	Sat May 09 08:27:06 2015 +0000
+++ b/mbed.bld	Wed Jun 13 15:51:08 2018 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/433970e64889
\ No newline at end of file
+https://os.mbed.com/users/mbed_official/code/mbed/builds/5aab5a7997ee
\ No newline at end of file