Permalink
Browse files

Clarified I2C/SPI selection

  • Loading branch information...
1 parent 817f3b4 commit e4e9397fb68b5f119c61444b8da51c7d9e100ab5 K.Townsend committed Jan 2, 2013
Showing with 15 additions and 9 deletions.
  1. +15 −9 examples/Adafruit_L3GD20_test/Adafruit_L3GD20_test.ino
@@ -18,14 +18,20 @@
#include <Wire.h>
#include <Adafruit_L3GD20.h>
-// By default, uses I2C
-//Adafruit_L3GD20 gyro;
-// Alternately, you can use SPI, but you have to define the pins
-#define GYRO_CS 4 // labeled CS
-#define GYRO_DO 5 // labeled SA0
-#define GYRO_DI 6 // labeled SDA
-#define GYRO_CLK 7 // labeled SCL
-Adafruit_L3GD20 gyro(GYRO_CS, GYRO_DO, GYRO_DI, GYRO_CLK);
+// Comment this next line to use SPI
+//#define USE_I2C
+
+#ifdef USE_I2C
+ // The default constructor uses I2C
+ Adafruit_L3GD20 gyro;
+#else
+ // To use SPI, you have to define the pins
+ #define GYRO_CS 4 // labeled CS
+ #define GYRO_DO 5 // labeled SA0
+ #define GYRO_DI 6 // labeled SDA
+ #define GYRO_CLK 7 // labeled SCL
+ Adafruit_L3GD20 gyro(GYRO_CS, GYRO_DO, GYRO_DI, GYRO_CLK);
+#endif
void setup()
{
@@ -48,4 +54,4 @@ void loop()
Serial.print("Y: "); Serial.print((int)gyro.data.y); Serial.print(" ");
Serial.print("Z: "); Serial.println((int)gyro.data.z); Serial.print(" ");
delay(100);
-}
+}

0 comments on commit e4e9397

Please sign in to comment.