From eaaa3bfb354ce95f99ad76980df9f06ddb9ed1f2 Mon Sep 17 00:00:00 2001 From: Paint Your Dragon Date: Fri, 2 Dec 2011 23:54:48 -0800 Subject: [PATCH] Arduino 1.0 compliant --- TSL2561.cpp | 24 ++++++++++++++++++++++-- TSL2561.h | 6 +++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/TSL2561.cpp b/TSL2561.cpp index 5bdb518..848cf67 100644 --- a/TSL2561.cpp +++ b/TSL2561.cpp @@ -36,10 +36,8 @@ /**************************************************************************/ #include -#include #include #include -#include #include "TSL2561.h" @@ -57,10 +55,18 @@ boolean TSL2561::begin(void) { // Initialise I2C Wire.beginTransmission(_addr); +#if ARDUINO >= 100 + Wire.write(TSL2561_REGISTER_ID); +#else Wire.send(TSL2561_REGISTER_ID); +#endif Wire.endTransmission(); Wire.requestFrom(_addr, 1); +#if ARDUINO >= 100 + int x = Wire.read(); +#else int x = Wire.receive(); +#endif //Serial.print("0x"); Serial.println(x, HEX); if (x & 0x0A ) { //Serial.println("Found TSL2561"); @@ -256,12 +262,21 @@ uint16_t TSL2561::read16(uint8_t reg) uint16_t x; uint16_t t; Wire.beginTransmission(_addr); +#if ARDUINO >= 100 + Wire.write(reg); +#else Wire.send(reg); +#endif Wire.endTransmission(); Wire.requestFrom(_addr, 2); +#if ARDUINO >= 100 + t = Wire.read(); + x = Wire.read(); +#else t = Wire.receive(); x = Wire.receive(); +#endif x <<= 8; x |= t; return x; @@ -272,7 +287,12 @@ uint16_t TSL2561::read16(uint8_t reg) void TSL2561::write8 (uint8_t reg, uint8_t value) { Wire.beginTransmission(_addr); +#if ARDUINO >= 100 + Wire.write(reg); + Wire.write(value); +#else Wire.send(reg); Wire.send(value); +#endif Wire.endTransmission(); } diff --git a/TSL2561.h b/TSL2561.h index 77eb9a7..2750f2b 100644 --- a/TSL2561.h +++ b/TSL2561.h @@ -38,8 +38,12 @@ #ifndef _TSL2561_H_ #define _TSL2561_H_ +#if ARDUINO >= 100 + #include +#else + #include +#endif #include -#include #define TSL2561_VISIBLE 2 // channel 0 - channel 1 #define TSL2561_INFRARED 1 // channel 1