Skip to content

Instantly share code, notes, and snippets.

@lyneca
Created September 3, 2018 06:20
Show Gist options
  • Save lyneca/600a364e35b518ec39627e55132c8a1f to your computer and use it in GitHub Desktop.
Save lyneca/600a364e35b518ec39627e55132c8a1f to your computer and use it in GitHub Desktop.
LED IMU Toggle
// LED Toggle
// Luke Tuthill for the University of Sydney
#include "CurieIMU.h"
// Green LED on pin 3
#define GREEN 3
void setup() {
// Setup the IMU
CurieIMU.begin();
// Set the Accelerometer range - how fast you can move it
// without it capping
CurieIMU.setAccelerometerRange(2);
// Begin debug serial print
Serial.begin(9600);
// Output pin
pinMode(GREEN, OUTPUT);
}
void loop() {
// Three ints to store the position
int ax, ay, az;
// This function fills ax, ay, and az with the values it needs
// (after calling this function, ax ay and az will have changed
CurieIMU.readAccelerometer(ax, ay, az);
// Print to serial
Serial.print(ax);
Serial.print(" ");
Serial.print(ay);
Serial.print(" ");
Serial.println(az);
if (az < 0) {
// If az is less than zero (right way up), turn on the LED
digitalWrite(GREEN, HIGH);
} else {
// Else, turn it off
digitalWrite(GREEN, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment