Permalink
Browse files

Arduino 1.0 compliant

1 parent edfa41c commit eaaa3bfb354ce95f99ad76980df9f06ddb9ed1f2 @PaintYourDragon PaintYourDragon committed Dec 3, 2011
Showing with 27 additions and 3 deletions.
  1. +22 −2 TSL2561.cpp
  2. +5 −1 TSL2561.h
View
@@ -36,10 +36,8 @@
/**************************************************************************/
#include <avr/pgmspace.h>
-#include <WProgram.h>
#include <util/delay.h>
#include <stdlib.h>
-#include <Wire.h>
#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();
}
View
@@ -38,8 +38,12 @@
#ifndef _TSL2561_H_
#define _TSL2561_H_
+#if ARDUINO >= 100
+ #include <Arduino.h>
+#else
+ #include <WProgram.h>
+#endif
#include <Wire.h>
-#include <WProgram.h>
#define TSL2561_VISIBLE 2 // channel 0 - channel 1
#define TSL2561_INFRARED 1 // channel 1

0 comments on commit eaaa3bf

Please sign in to comment.