I have the ADAFRUIT TCS34725 RGB Sensor and a XC3728 Oled Display. I would like to display the Color Temperature on the OLED Display but just cant work out how to do it.
I have attached my code that compiles OK showing the Color Temperature on the Serial Monitor and a standard Hello World on the OLED.
What I cant work out is how to get the color temperature value to be displayed on the OLED. I have been searching and trying all sorts of things but cant nut it out (it’s been about 10 years since I last played with Arduino and I have forgotten all the basics).
Could somebody please assist by providing the necessary code to insert so that I can get this working. Many thanks in advance, your assistance is most appreciated.
Code: Select all
[code]
/* Adafruit TCS34725 and XC3728 OLED Display */
/* Integrate OLED Code */
#include "U8glib.h"
U8GLIB_SH1106_128X64 u8g(13, 11, 10, 9); // SCK = 13, MOSI = 11, CS = 10, A0 = 9
/* 34725 Code */
#include <Wire.h>
#include "Adafruit_TCS34725.h"
/* Initialise with default values (int time = 2.4ms, gain = 1x) */
// Adafruit_TCS34725 tcs = Adafruit_TCS34725();
/* Initialise with specific int time and gain values */
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_614MS, TCS34725_GAIN_1X);
void setup(void)
{
/* OLED Code */
// flip screen, if required
//u8g.setRot180();
// set SPI backup if required
//u8g.setHardwareBackup(u8g_backup_avr_spi);
// assign default color value
if ( u8g.getMode() == U8G_MODE_R3G3B2 )
{
u8g.setColorIndex(255); // white
}
else if ( u8g.getMode() == U8G_MODE_GRAY2BIT )
{
u8g.setColorIndex(3); // max intensity
}
else if ( u8g.getMode() == U8G_MODE_BW )
{
u8g.setColorIndex(1); // pixel on
}
else if ( u8g.getMode() == U8G_MODE_HICOLOR )
{
u8g.setHiColorByRGB(255,255,255);
}
/* 3745 code */
{
Serial.begin(9600);
if (tcs.begin()) {
Serial.println("Found sensor");
} else {
Serial.println("No TCS34725 found ... check your connections");
while (1);
}}}
void loop(void) {
uint16_t r, g, b, c, colorTemp, lux;
tcs.getRawData(&r, &g, &b, &c);
// colorTemp = tcs.calculateColorTemperature(r, g, b);
colorTemp = tcs.calculateColorTemperature_dn40(r, g, b, c);
lux = tcs.calculateLux(r, g, b);
Serial.print("Color Temp: "); Serial.print(colorTemp, DEC);
Serial.println(" ");
// picture loop
u8g.firstPage();
do
{
draw();
}
while( u8g.nextPage() );
// rebuild the picture after some delay
delay(50);
}
void draw(void) {
u8g.setFont(u8g_font_unifont);
u8g.drawStr( 0, 22, "HELLO WORLD");
}