A library for the Avago ADJD-S311-CR999 Color Light Sensor

Dependents:   ADJD-S311_HelloWorld

Committer:
CheeseW
Date:
Mon Mar 24 04:46:51 2014 +0000
Revision:
0:d5bb69f92ea3
Come out for publication

Who changed what in which revision?

UserRevisionLine numberNew contents of line
CheeseW 0:d5bb69f92ea3 1 #include "ADJDs311.h"
CheeseW 0:d5bb69f92ea3 2 #include "mbed.h"
CheeseW 0:d5bb69f92ea3 3 #include <algorithm>
CheeseW 0:d5bb69f92ea3 4
CheeseW 0:d5bb69f92ea3 5 ADJDs311::ADJDs311(PinName sda, PinName scl, PinName led):
CheeseW 0:d5bb69f92ea3 6 _i2c(sda, scl), _led(led) {
CheeseW 0:d5bb69f92ea3 7 // hard coded value for number of capacitors
CheeseW 0:d5bb69f92ea3 8 colorCap.red = 12;
CheeseW 0:d5bb69f92ea3 9 colorCap.green = 9;
CheeseW 0:d5bb69f92ea3 10 colorCap.blue = 2;
CheeseW 0:d5bb69f92ea3 11 colorCap.clear = 9;
CheeseW 0:d5bb69f92ea3 12
CheeseW 0:d5bb69f92ea3 13 // hard coded value for number of integration time slot
CheeseW 0:d5bb69f92ea3 14 colorInt.red = 16;
CheeseW 0:d5bb69f92ea3 15 colorInt.green = 16;
CheeseW 0:d5bb69f92ea3 16 colorInt.blue = 16;
CheeseW 0:d5bb69f92ea3 17 colorInt.clear = 16;
CheeseW 0:d5bb69f92ea3 18
CheeseW 0:d5bb69f92ea3 19 colorOffset.red = readRegister(OFFSET_RED);
CheeseW 0:d5bb69f92ea3 20 colorOffset.green = readRegister(OFFSET_GREEN);
CheeseW 0:d5bb69f92ea3 21 colorOffset.blue = readRegister(OFFSET_BLUE);
CheeseW 0:d5bb69f92ea3 22 colorOffset.clear = readRegister(OFFSET_CLEAR);
CheeseW 0:d5bb69f92ea3 23
CheeseW 0:d5bb69f92ea3 24 // write number of capacitors to registers
CheeseW 0:d5bb69f92ea3 25 writeRegister(colorCap.red & 0xF, CAP_RED);
CheeseW 0:d5bb69f92ea3 26 writeRegister(colorCap.green & 0xF, CAP_GREEN);
CheeseW 0:d5bb69f92ea3 27 writeRegister(colorCap.blue & 0xF, CAP_BLUE);
CheeseW 0:d5bb69f92ea3 28 writeRegister(colorCap.clear & 0xF, CAP_CLEAR);
CheeseW 0:d5bb69f92ea3 29
CheeseW 0:d5bb69f92ea3 30 // write number of integration time slot to registers
CheeseW 0:d5bb69f92ea3 31 writeInt(colorInt.red & 0xFFF, INT_RED_LO);
CheeseW 0:d5bb69f92ea3 32 writeInt(colorInt.green & 0xFFF, INT_GREEN_LO);
CheeseW 0:d5bb69f92ea3 33 writeInt(colorInt.blue & 0xFFF, INT_BLUE_LO);
CheeseW 0:d5bb69f92ea3 34 writeInt(colorInt.clear & 0xFFF, INT_CLEAR_LO);
CheeseW 0:d5bb69f92ea3 35 }
CheeseW 0:d5bb69f92ea3 36
CheeseW 0:d5bb69f92ea3 37 // Read data regeisters and return a RGBC var
CheeseW 0:d5bb69f92ea3 38 RGBC ADJDs311::read(){
CheeseW 0:d5bb69f92ea3 39 RGBC color = RGBC();
CheeseW 0:d5bb69f92ea3 40
CheeseW 0:d5bb69f92ea3 41 performMeasurement();
CheeseW 0:d5bb69f92ea3 42
CheeseW 0:d5bb69f92ea3 43 color.red = readInt(DATA_RED_LO);
CheeseW 0:d5bb69f92ea3 44 color.green = readInt(DATA_GREEN_LO);
CheeseW 0:d5bb69f92ea3 45 color.blue = readInt(DATA_BLUE_LO);
CheeseW 0:d5bb69f92ea3 46 color.clear = readInt(DATA_CLEAR_LO);
CheeseW 0:d5bb69f92ea3 47
CheeseW 0:d5bb69f92ea3 48 return color;
CheeseW 0:d5bb69f92ea3 49 }
CheeseW 0:d5bb69f92ea3 50
CheeseW 0:d5bb69f92ea3 51 // get number of capacitor
CheeseW 0:d5bb69f92ea3 52 RGBC ADJDs311::getColorCap()
CheeseW 0:d5bb69f92ea3 53 {
CheeseW 0:d5bb69f92ea3 54 return colorCap;
CheeseW 0:d5bb69f92ea3 55 }
CheeseW 0:d5bb69f92ea3 56
CheeseW 0:d5bb69f92ea3 57 // get number of intetgration time slot
CheeseW 0:d5bb69f92ea3 58 RGBC ADJDs311::getColorInt()
CheeseW 0:d5bb69f92ea3 59 {
CheeseW 0:d5bb69f92ea3 60 return colorInt;
CheeseW 0:d5bb69f92ea3 61 }
CheeseW 0:d5bb69f92ea3 62
CheeseW 0:d5bb69f92ea3 63 // set number of capacitor
CheeseW 0:d5bb69f92ea3 64 void ADJDs311::setColorCap(int red, int green, int blue, int clear) {
CheeseW 0:d5bb69f92ea3 65 colorCap.red = red;
CheeseW 0:d5bb69f92ea3 66 colorCap.green = green;
CheeseW 0:d5bb69f92ea3 67 colorCap.blue = blue;
CheeseW 0:d5bb69f92ea3 68 colorCap.clear = clear;
CheeseW 0:d5bb69f92ea3 69
CheeseW 0:d5bb69f92ea3 70 // write number of capacitors to registers
CheeseW 0:d5bb69f92ea3 71 writeRegister(colorCap.red & 0xF, CAP_RED);
CheeseW 0:d5bb69f92ea3 72 writeRegister(colorCap.green & 0xF, CAP_GREEN);
CheeseW 0:d5bb69f92ea3 73 writeRegister(colorCap.blue & 0xF, CAP_BLUE);
CheeseW 0:d5bb69f92ea3 74 writeRegister(colorCap.clear & 0xF, CAP_CLEAR);
CheeseW 0:d5bb69f92ea3 75 }
CheeseW 0:d5bb69f92ea3 76
CheeseW 0:d5bb69f92ea3 77 // set number of integration time slot
CheeseW 0:d5bb69f92ea3 78 void ADJDs311::setColorInt(int red, int green, int blue, int clear) {
CheeseW 0:d5bb69f92ea3 79 colorInt.red = red;
CheeseW 0:d5bb69f92ea3 80 colorInt.green = green;
CheeseW 0:d5bb69f92ea3 81 colorInt.blue = blue;
CheeseW 0:d5bb69f92ea3 82 colorInt.clear = clear;
CheeseW 0:d5bb69f92ea3 83
CheeseW 0:d5bb69f92ea3 84 // write number of integration time slot to registers
CheeseW 0:d5bb69f92ea3 85 writeInt(colorInt.red & 0xFFF, INT_RED_LO);
CheeseW 0:d5bb69f92ea3 86 writeInt(colorInt.green & 0xFFF, INT_GREEN_LO);
CheeseW 0:d5bb69f92ea3 87 writeInt(colorInt.blue & 0xFFF, INT_BLUE_LO);
CheeseW 0:d5bb69f92ea3 88 writeInt(colorInt.clear & 0xFFF, INT_CLEAR_LO);
CheeseW 0:d5bb69f92ea3 89 }
CheeseW 0:d5bb69f92ea3 90
CheeseW 0:d5bb69f92ea3 91 // Perform measurement and save the result to registers
CheeseW 0:d5bb69f92ea3 92 void ADJDs311::performMeasurement(){
CheeseW 0:d5bb69f92ea3 93 writeRegister(0x01, 0x00); // start sensing
CheeseW 0:d5bb69f92ea3 94 while(readRegister(0x00) != 0)
CheeseW 0:d5bb69f92ea3 95 ; // waiting for a result
CheeseW 0:d5bb69f92ea3 96 }
CheeseW 0:d5bb69f92ea3 97
CheeseW 0:d5bb69f92ea3 98 // Write a byte of data to a specific ADJD-S311 address
CheeseW 0:d5bb69f92ea3 99 void ADJDs311::writeRegister(char data, char regAddr){
CheeseW 0:d5bb69f92ea3 100 char temp[2];
CheeseW 0:d5bb69f92ea3 101 temp[0] = regAddr; // register addresss
CheeseW 0:d5bb69f92ea3 102 temp[1] = data;
CheeseW 0:d5bb69f92ea3 103
CheeseW 0:d5bb69f92ea3 104 _i2c.write(WRITE_ADDRESS, temp, 2, false);
CheeseW 0:d5bb69f92ea3 105 }
CheeseW 0:d5bb69f92ea3 106
CheeseW 0:d5bb69f92ea3 107 // Read a byte of data from ADJD-S311 address
CheeseW 0:d5bb69f92ea3 108 char ADJDs311::readRegister(char regAddr){
CheeseW 0:d5bb69f92ea3 109 char data;
CheeseW 0:d5bb69f92ea3 110
CheeseW 0:d5bb69f92ea3 111 _i2c.write(WRITE_ADDRESS, &regAddr, 1, true);
CheeseW 0:d5bb69f92ea3 112 _i2c.read(READ_ADDRESS, &data, 1, false);
CheeseW 0:d5bb69f92ea3 113 return data;
CheeseW 0:d5bb69f92ea3 114 }
CheeseW 0:d5bb69f92ea3 115
CheeseW 0:d5bb69f92ea3 116 // Read two bytes of data from ADJD-S311 address and addres+1
CheeseW 0:d5bb69f92ea3 117 int ADJDs311::readInt(char loRegAddr)
CheeseW 0:d5bb69f92ea3 118 {
CheeseW 0:d5bb69f92ea3 119 return (unsigned char)readRegister(loRegAddr) + (((unsigned char)readRegister(loRegAddr+1))<<8);
CheeseW 0:d5bb69f92ea3 120 }
CheeseW 0:d5bb69f92ea3 121
CheeseW 0:d5bb69f92ea3 122 // Write two bytes of data to ADJD-S311 address and addres+1
CheeseW 0:d5bb69f92ea3 123 void ADJDs311::writeInt(int data, char loRegAddr)
CheeseW 0:d5bb69f92ea3 124 {
CheeseW 0:d5bb69f92ea3 125 char lobyte = data;
CheeseW 0:d5bb69f92ea3 126 char hibyte = data >> 8;
CheeseW 0:d5bb69f92ea3 127
CheeseW 0:d5bb69f92ea3 128 writeRegister(lobyte, loRegAddr);
CheeseW 0:d5bb69f92ea3 129 writeRegister(hibyte, loRegAddr+1);
CheeseW 0:d5bb69f92ea3 130 }
CheeseW 0:d5bb69f92ea3 131
CheeseW 0:d5bb69f92ea3 132 /* calibrateClear() - This function calibrates the clear integration registers
CheeseW 0:d5bb69f92ea3 133 of the ADJD-S311.
CheeseW 0:d5bb69f92ea3 134 */
CheeseW 0:d5bb69f92ea3 135 void ADJDs311::calibrateClearInt(){
CheeseW 0:d5bb69f92ea3 136 bool gainFound = false;
CheeseW 0:d5bb69f92ea3 137 int upperBox=4096;
CheeseW 0:d5bb69f92ea3 138 int lowerBox = 0;
CheeseW 0:d5bb69f92ea3 139 int half;
CheeseW 0:d5bb69f92ea3 140
CheeseW 0:d5bb69f92ea3 141 while (!gainFound){
CheeseW 0:d5bb69f92ea3 142 half = ((upperBox-lowerBox)/2)+lowerBox;
CheeseW 0:d5bb69f92ea3 143 //no further halfing possbile
CheeseW 0:d5bb69f92ea3 144
CheeseW 0:d5bb69f92ea3 145 if (half==lowerBox){
CheeseW 0:d5bb69f92ea3 146 gainFound=true;
CheeseW 0:d5bb69f92ea3 147 }else{
CheeseW 0:d5bb69f92ea3 148 colorInt.clear = half;
CheeseW 0:d5bb69f92ea3 149 writeInt(colorInt.clear & 0xFFF, INT_CLEAR_LO);
CheeseW 0:d5bb69f92ea3 150 performMeasurement();
CheeseW 0:d5bb69f92ea3 151 int halfValue = readInt(DATA_CLEAR_LO);
CheeseW 0:d5bb69f92ea3 152
CheeseW 0:d5bb69f92ea3 153 if (halfValue>800){
CheeseW 0:d5bb69f92ea3 154 upperBox=half;
CheeseW 0:d5bb69f92ea3 155 }else if (halfValue<800){
CheeseW 0:d5bb69f92ea3 156 lowerBox=half;
CheeseW 0:d5bb69f92ea3 157 }else{
CheeseW 0:d5bb69f92ea3 158 gainFound=true;
CheeseW 0:d5bb69f92ea3 159 }
CheeseW 0:d5bb69f92ea3 160 }
CheeseW 0:d5bb69f92ea3 161 }
CheeseW 0:d5bb69f92ea3 162 }
CheeseW 0:d5bb69f92ea3 163
CheeseW 0:d5bb69f92ea3 164 /* calibrateColor() - This function clalibrates the RG and B
CheeseW 0:d5bb69f92ea3 165 integration registers.
CheeseW 0:d5bb69f92ea3 166 */
CheeseW 0:d5bb69f92ea3 167 void ADJDs311::calibrateColorInt(){
CheeseW 0:d5bb69f92ea3 168 bool gainFound = false;
CheeseW 0:d5bb69f92ea3 169 int upperBox=4096;
CheeseW 0:d5bb69f92ea3 170 int lowerBox = 0;
CheeseW 0:d5bb69f92ea3 171 int half;
CheeseW 0:d5bb69f92ea3 172 int halfValue;
CheeseW 0:d5bb69f92ea3 173
CheeseW 0:d5bb69f92ea3 174 while (!gainFound)
CheeseW 0:d5bb69f92ea3 175 {
CheeseW 0:d5bb69f92ea3 176 half = ((upperBox-lowerBox)/2)+lowerBox;
CheeseW 0:d5bb69f92ea3 177 //no further halfing possbile
CheeseW 0:d5bb69f92ea3 178 if (half==lowerBox)
CheeseW 0:d5bb69f92ea3 179 {
CheeseW 0:d5bb69f92ea3 180 gainFound=true;
CheeseW 0:d5bb69f92ea3 181 }
CheeseW 0:d5bb69f92ea3 182 else {
CheeseW 0:d5bb69f92ea3 183 colorInt.red = half;
CheeseW 0:d5bb69f92ea3 184 colorInt.green = half;
CheeseW 0:d5bb69f92ea3 185 colorInt.blue = half;
CheeseW 0:d5bb69f92ea3 186
CheeseW 0:d5bb69f92ea3 187 // write number of integration time slot to registers
CheeseW 0:d5bb69f92ea3 188 writeInt(colorInt.red & 0xFFF, INT_RED_LO);
CheeseW 0:d5bb69f92ea3 189 writeInt(colorInt.green & 0xFFF, INT_GREEN_LO);
CheeseW 0:d5bb69f92ea3 190 writeInt(colorInt.blue & 0xFFF, INT_BLUE_LO);
CheeseW 0:d5bb69f92ea3 191
CheeseW 0:d5bb69f92ea3 192 performMeasurement();
CheeseW 0:d5bb69f92ea3 193 halfValue = 0;
CheeseW 0:d5bb69f92ea3 194
CheeseW 0:d5bb69f92ea3 195 halfValue=std::max(halfValue, readInt(DATA_RED_LO));
CheeseW 0:d5bb69f92ea3 196 halfValue=std::max(halfValue, readInt(DATA_GREEN_LO));
CheeseW 0:d5bb69f92ea3 197 halfValue=std::max(halfValue, readInt(DATA_BLUE_LO));
CheeseW 0:d5bb69f92ea3 198
CheeseW 0:d5bb69f92ea3 199 if (halfValue>800) {
CheeseW 0:d5bb69f92ea3 200 upperBox=half;
CheeseW 0:d5bb69f92ea3 201 }
CheeseW 0:d5bb69f92ea3 202 else if (halfValue<800) {
CheeseW 0:d5bb69f92ea3 203 lowerBox=half;
CheeseW 0:d5bb69f92ea3 204 }
CheeseW 0:d5bb69f92ea3 205 else {
CheeseW 0:d5bb69f92ea3 206 gainFound=true;
CheeseW 0:d5bb69f92ea3 207 }
CheeseW 0:d5bb69f92ea3 208 }
CheeseW 0:d5bb69f92ea3 209 }
CheeseW 0:d5bb69f92ea3 210 }
CheeseW 0:d5bb69f92ea3 211
CheeseW 0:d5bb69f92ea3 212
CheeseW 0:d5bb69f92ea3 213 /* calibrateCapacitors() - This function calibrates each of the RGB and C
CheeseW 0:d5bb69f92ea3 214 capacitor registers.
CheeseW 0:d5bb69f92ea3 215 */
CheeseW 0:d5bb69f92ea3 216 void ADJDs311::calibrateCapacitors(){
CheeseW 0:d5bb69f92ea3 217
CheeseW 0:d5bb69f92ea3 218 bool calibrated = false;
CheeseW 0:d5bb69f92ea3 219
CheeseW 0:d5bb69f92ea3 220 //need to store detect better calibration
CheeseW 0:d5bb69f92ea3 221 int diff;
CheeseW 0:d5bb69f92ea3 222 int oldDiff = 1024;
CheeseW 0:d5bb69f92ea3 223
CheeseW 0:d5bb69f92ea3 224 while (!calibrated){
CheeseW 0:d5bb69f92ea3 225 // sensor gain setting (Avago app note 5330)
CheeseW 0:d5bb69f92ea3 226 // CAPs are 4bit (higher value will result in lower output)
CheeseW 0:d5bb69f92ea3 227 writeRegister(colorCap.red & 0xF, CAP_RED);
CheeseW 0:d5bb69f92ea3 228 writeRegister(colorCap.green & 0xF, CAP_GREEN);
CheeseW 0:d5bb69f92ea3 229 writeRegister(colorCap.blue & 0xF, CAP_BLUE);
CheeseW 0:d5bb69f92ea3 230
CheeseW 0:d5bb69f92ea3 231 int maxRead = 0;
CheeseW 0:d5bb69f92ea3 232 int minRead = 1024;
CheeseW 0:d5bb69f92ea3 233 int red = 0;
CheeseW 0:d5bb69f92ea3 234 int green = 0;
CheeseW 0:d5bb69f92ea3 235 int blue = 0;
CheeseW 0:d5bb69f92ea3 236
CheeseW 0:d5bb69f92ea3 237 for (int i=0; i<4 ;i ++)
CheeseW 0:d5bb69f92ea3 238 {
CheeseW 0:d5bb69f92ea3 239 performMeasurement();
CheeseW 0:d5bb69f92ea3 240 red += readInt(DATA_RED_LO);
CheeseW 0:d5bb69f92ea3 241 green += readInt(DATA_GREEN_LO);
CheeseW 0:d5bb69f92ea3 242 blue += readInt(DATA_BLUE_LO);
CheeseW 0:d5bb69f92ea3 243 }
CheeseW 0:d5bb69f92ea3 244 red /= 4;
CheeseW 0:d5bb69f92ea3 245 green /= 4;
CheeseW 0:d5bb69f92ea3 246 blue /= 4;
CheeseW 0:d5bb69f92ea3 247
CheeseW 0:d5bb69f92ea3 248 maxRead = std::max(maxRead, red);
CheeseW 0:d5bb69f92ea3 249 maxRead = std::max(maxRead, green);
CheeseW 0:d5bb69f92ea3 250 maxRead = std::max(maxRead, blue);
CheeseW 0:d5bb69f92ea3 251
CheeseW 0:d5bb69f92ea3 252 minRead = std::min(minRead, red);
CheeseW 0:d5bb69f92ea3 253 minRead = std::min(minRead, green);
CheeseW 0:d5bb69f92ea3 254 minRead = std::min(minRead, blue);
CheeseW 0:d5bb69f92ea3 255
CheeseW 0:d5bb69f92ea3 256 diff = maxRead - minRead;
CheeseW 0:d5bb69f92ea3 257
CheeseW 0:d5bb69f92ea3 258 if (oldDiff != diff)
CheeseW 0:d5bb69f92ea3 259 {
CheeseW 0:d5bb69f92ea3 260 if ((maxRead==red) && (colorCap.red<15))
CheeseW 0:d5bb69f92ea3 261 colorCap.red++;
CheeseW 0:d5bb69f92ea3 262 else if ((maxRead == green) && (colorCap.green<15))
CheeseW 0:d5bb69f92ea3 263 colorCap.green++;
CheeseW 0:d5bb69f92ea3 264 else if ((maxRead == blue) && (colorCap.blue<15))
CheeseW 0:d5bb69f92ea3 265 colorCap.blue++;
CheeseW 0:d5bb69f92ea3 266 }
CheeseW 0:d5bb69f92ea3 267 else
CheeseW 0:d5bb69f92ea3 268 calibrated = true;
CheeseW 0:d5bb69f92ea3 269
CheeseW 0:d5bb69f92ea3 270 oldDiff=diff;
CheeseW 0:d5bb69f92ea3 271
CheeseW 0:d5bb69f92ea3 272 }
CheeseW 0:d5bb69f92ea3 273
CheeseW 0:d5bb69f92ea3 274 }
CheeseW 0:d5bb69f92ea3 275
CheeseW 0:d5bb69f92ea3 276 void ADJDs311::calibrate(){
CheeseW 0:d5bb69f92ea3 277 setColorCap(0, 0, 0, 8);
CheeseW 0:d5bb69f92ea3 278 calibrateColorInt(); // This calibrates R, G, and B int registers
CheeseW 0:d5bb69f92ea3 279 calibrateClearInt(); // This calibrates the C int registers
CheeseW 0:d5bb69f92ea3 280 calibrateCapacitors(); // This calibrates the RGB, and C cap registers
CheeseW 0:d5bb69f92ea3 281 calibrateColorInt();
CheeseW 0:d5bb69f92ea3 282 }
CheeseW 0:d5bb69f92ea3 283
CheeseW 0:d5bb69f92ea3 284
CheeseW 0:d5bb69f92ea3 285 void ADJDs311::ledMode(bool ledOn)
CheeseW 0:d5bb69f92ea3 286 {
CheeseW 0:d5bb69f92ea3 287 _led = ledOn;
CheeseW 0:d5bb69f92ea3 288 }
CheeseW 0:d5bb69f92ea3 289
CheeseW 0:d5bb69f92ea3 290 void ADJDs311::offsetMode(bool useOffset)
CheeseW 0:d5bb69f92ea3 291 {
CheeseW 0:d5bb69f92ea3 292 if (useOffset)
CheeseW 0:d5bb69f92ea3 293 {
CheeseW 0:d5bb69f92ea3 294 writeRegister(0x01, CONFIG);
CheeseW 0:d5bb69f92ea3 295 } else
CheeseW 0:d5bb69f92ea3 296 {
CheeseW 0:d5bb69f92ea3 297 writeRegister(0x00, CONFIG);
CheeseW 0:d5bb69f92ea3 298 }
CheeseW 0:d5bb69f92ea3 299 }
CheeseW 0:d5bb69f92ea3 300
CheeseW 0:d5bb69f92ea3 301 RGBC ADJDs311::getOffset()
CheeseW 0:d5bb69f92ea3 302 {
CheeseW 0:d5bb69f92ea3 303 return colorOffset;
CheeseW 0:d5bb69f92ea3 304 }
CheeseW 0:d5bb69f92ea3 305
CheeseW 0:d5bb69f92ea3 306 RGBC ADJDs311::setOffset(bool useOffset)
CheeseW 0:d5bb69f92ea3 307 {
CheeseW 0:d5bb69f92ea3 308 _led = 0;
CheeseW 0:d5bb69f92ea3 309
CheeseW 0:d5bb69f92ea3 310 writeRegister(0x02, CTRL);
CheeseW 0:d5bb69f92ea3 311 while(readRegister(CTRL));
CheeseW 0:d5bb69f92ea3 312 colorOffset.red = readRegister(OFFSET_RED);
CheeseW 0:d5bb69f92ea3 313 colorOffset.green = readRegister(OFFSET_GREEN);
CheeseW 0:d5bb69f92ea3 314 colorOffset.blue = readRegister(OFFSET_BLUE);
CheeseW 0:d5bb69f92ea3 315 colorOffset.clear = readRegister(OFFSET_CLEAR);
CheeseW 0:d5bb69f92ea3 316
CheeseW 0:d5bb69f92ea3 317 offsetMode(useOffset);
CheeseW 0:d5bb69f92ea3 318
CheeseW 0:d5bb69f92ea3 319 return colorOffset;
CheeseW 0:d5bb69f92ea3 320 }