Permalink
Browse files

First commit

  • Loading branch information...
0 parents commit 7be4b28fd92a2db95a3aa54f4f5283c9bfa15581 @tylerdcooper tylerdcooper committed Feb 13, 2013
Showing with 133 additions and 0 deletions.
  1. +95 −0 Flora_Brakelight_Backpack/Flora_Brakelight_Backpack.ino
  2. +12 −0 README.txt
  3. +26 −0 license.txt
@@ -0,0 +1,95 @@
+#include <Wire.h>
+#include <Adafruit_LSM303.h>
+
+Adafruit_LSM303 lsm;
+
+#define BRAKETHRESHOLD 350
+#define BRAKETIMETHRESHOLD 200
+
+int start = 0;
+
+int prevX = 0;
+int currentX = 0;
+
+int speakerPin = 11;
+long brakeTime = 0;
+
+void setup()
+{
+ Serial.begin(9600);
+
+ // Try to initialise and warn if we couldn't detect the chip
+ if (!lsm.begin())
+ {
+ Serial.println("Oops ... unable to initialize the LSM303. Check your wiring!");
+ while (1);
+ }
+ pinMode(speakerPin, OUTPUT);
+}
+
+void loop()
+{
+ lsm.read();
+ currentX = abs(lsm.accelData.x);
+
+ if (start == 0){
+ Serial.println("In start");
+ prevX = currentX;
+ start = 1;
+ }
+
+ int i = currentX - prevX;
+ Serial.print("Outer Loop: ");
+ Serial.println(i);
+ //Serial.print("currentx: ");
+ //Serial.println(currentX);
+ //Serial.print("prevX: ");
+ //Serial.println(prevX);
+ if (abs(i) > BRAKETHRESHOLD) {
+ Serial.print("In outside IF: ");
+ Serial.println(abs(i));
+ brakeTime = millis();
+ int strikes = 0;
+ while ((abs(i) > BRAKETHRESHOLD) && (strikes < 3)) {
+ //Serial.println("In While");
+ if (abs(i) < BRAKETHRESHOLD) {
+ strikes = strikes + 1;
+ }
+ //Serial.print("strikes: ");
+ //Serial.println(strikes);
+ //Serial.println(millis() - brakeTime);
+ //Serial.println("After Break IF");
+ lsm.read();
+ currentX = abs(lsm.accelData.z);
+
+
+ i = currentX - prevX;
+ //prevX = currentX;
+ //Serial.println(abs(i));
+
+ if ((millis() - brakeTime) > BRAKETIMETHRESHOLD) {
+ //Serial.print("Calculated time: ");
+ //Serial.println(millis() - brakeTime);
+ analogWrite(speakerPin, 100);
+ while (abs(i) > BRAKETHRESHOLD) {
+ lsm.read();
+ currentX = abs(lsm.accelData.x);
+ i = currentX - prevX;
+ Serial.print("In Inner While: ");
+ Serial.println(i);
+ delay(100);
+ }
+ delay(2000);
+ analogWrite(speakerPin, 0);
+ brakeTime = millis();
+ i = 0;
+ lsm.read();
+ currentX = abs(lsm.accelData.x);
+ }
+ }
+ }
+
+ //brakeTime = millis();
+ prevX = currentX;
+ delay(200);
+}
@@ -0,0 +1,12 @@
+The Flora GPS Jacket is a project created by Becky Stern and Tyler Cooper. For more details on the project, please visit http://learn.adafruit.com/flora-gps-jacket/.
+
+Adafruit invests time and resources providing this open source design, please support Adafruit and open-source hardware by purchasing products from Adafruit!
+
+Written by Tyler Cooper for Adafruit Industries.
+BSD license, check license.txt for more information
+
+To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Flora_GPS_Jacket. Check that the Flora_GPS_Jacket folder contains Flora_GPS_Jacket.ino.
+
+This code example requires the Adafruit GPS library which can be downloaded from https://github.com/adafruit/Adafruit-GPS-Library
+
+This code example also requires the Adafruit Flora Pixel library which can be downloaded from https://github.com/adafruit/Adafruit-Flora-Pixel-Library
@@ -0,0 +1,26 @@
+Software License Agreement (BSD License)
+
+Copyright (c) 2012, Adafruit Industries
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+1. Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+3. Neither the name of the copyright holders nor the
+names of its contributors may be used to endorse or promote products
+derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

0 comments on commit 7be4b28

Please sign in to comment.