Prezi-tation

Some images from the presentation:

Revolving Games_bb

door

//Revolving Games by Michelle Ma
//Revolving Games by Michelle Ma

#include 
#include 
#include "RTClib.h"
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
#include 
#include 

Adafruit_7segment matrix1 = Adafruit_7segment();
Adafruit_7segment matrix2 = Adafruit_7segment();
Adafruit_ADXL345 accel = Adafruit_ADXL345(12345);

RTC_DS1307 RTC; // Real Time Clock

const int chipSelect = 10; //for data logging
const int distancePin = 0; //A0 for IR sensor

const int threshold = 100; //collect data when someone near
const float radius = 0.65; //radius of door in meters
const float pi = 3.1415926;

File logfile;

int highScore;

void setup() {
  Serial.begin(9600);
  SD.begin(chipSelect);
  createFile();
  accel.begin();
  matrix1.begin(0x70);
  matrix2.begin(0x71);
  
  if (!RTC.isrunning()) {
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
  
  accel.setRange(ADXL345_RANGE_16_G);
  
  highScore = 0;
}

void createFile() {
  char filename[] = "LOGGER00.CSV";
  for (uint8_t i=0; i<100; i++) {
    filename[6] = i/10 + '0';
    filename[7] = i%10 + '0';
    if (!SD.exists(filename)) {
      logfile = SD.open(filename, FILE_WRITE);
      break;
    }
  }
  
  if (!logfile) {
    Serial.print("Couldn't create file");
    Serial.println();
    while(true);
  }
  Serial.print("Logging to: ");
  Serial.println(filename);
  
  Wire.begin();
  
  if (!RTC.begin()) {
    Serial.println("RTC error");
  }
  logfile.println("TimeStamp,IR Distance,Accel (m/s^2),RPM");
}

void loop() {
  
  DateTime now = RTC.now();
  sensors_event_t event; 
  accel.getEvent(&event);
  
  float distance = analogRead(distancePin);
  float acceleration = event.acceleration.z;
  float rpm;
  
  if (distance > threshold) {
    rpm = computeRpm();
  } else {
    rpm = 0;
  }
  
  if (rpm > highScore) {
    highScore = rpm;
  }
  
  logData(now, distance, acceleration, rpm);
  serialData(now, distance, acceleration, rpm);
  writeMatrices(int(rpm), int(highScore));
  
  Serial.println("Saved...");
  logfile.flush();
}

float computeRpm() {
  float velocity = computeVelocity();
  float result = abs(60.0*velocity)/(2.0*pi*radius);
  return result;
}

float computeVelocity() {
  float acceleration;
  float sum = 0;
  int samples = 100;
  int dt = 10; //millis
  for (int i=0; i

One comment

  1. admin

    Very nicely designed box

    instead of double-sided-tape or magic arm use suction cups
    look at museums like the “exploratorium” or the saint paul science museum
    faster harder further or slower softer closer

    Great how you were able to persevere and get it to work in the end!

    very thorough documentation so far

    Michelle, your little cardboard box is adorable/fab 🙂

    Michelle, this is amazing, it looks adorable and you deserve mad props

    Would recommend using git (+ github) or dropbox or google drive to back up data, so crashes are not so deadly
    ^ yup.
    Dropbox: https://www.dropbox.com/home, https://www.dropbox.com/help/11/en
    (dropbox is the easy way to solve this, git is worth learning if you’re going to keep doing big coding projects)

    Git links:
    http://betterexplained.com/articles/a-visual-guide-to-version-control/
    http://chronicle.com/blogs/profhacker/a-gentle-introduction-to-version-control
    http://git-scm.com/book/en/Getting-Started-About-Version-Control
    https://github.com/andreaskoch/Introduction-to-Distributed-Source-Code-Management-with-git

    Data logging is a hidden gem of this project, fascinating to see door usage over time