Skip to content
This repository has been archived by the owner on May 7, 2019. It is now read-only.

Commit

Permalink
Arduino 1.0 compliant
Browse files Browse the repository at this point in the history
  • Loading branch information
PaintYourDragon committed Dec 3, 2011
1 parent edfa41c commit eaaa3bf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
24 changes: 22 additions & 2 deletions TSL2561.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@
/**************************************************************************/

#include <avr/pgmspace.h>
#include <WProgram.h>
#include <util/delay.h>
#include <stdlib.h>
#include <Wire.h>

#include "TSL2561.h"

Expand All @@ -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");
Expand Down Expand Up @@ -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;
Expand All @@ -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();
}
6 changes: 5 additions & 1 deletion TSL2561.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eaaa3bf

Please sign in to comment.