#pragma once #include "Adafruit_NeoPixel.h" #include "CurieIMU.h" #include "CurieTime.h" #include // Minimal class to replace std::vector for regular Arduino's not needed for Arduino 101 #include using namespace std; #define Vector vector long lastStepCount = 0; Adafruit_NeoPixel *pixels; class Color { public: unsigned short R,G,B; Color(unsigned short newR=255,unsigned short newG=255,unsigned short newB=255) { R=newR; G=newG; B=newB; } }; class Colors { public: Vector values; void add(Color c) { values.push_back(c); } void transfigure(Colors &other,float t) { for (unsigned i=0;i255.0) r=255.0; float g=(G2-G1)*t+G1; if (g<0.0) g=0.0; if (g>255.0) g=255.0; float b=(B2-B)*t+B; if (b<0.0) b=0.0; if (b>255.0) b=255.0; // Neopixel code to set LED colors } } int size() { return values.size(); } }; class Length { public: Length(unsigned short newL) { l=newL; } unsigned short l; // in inches }; class Lengths { public: Vector values; // in inches void add(Length l) { values.push_back(l); } void transfigure(Lengths &otherValues,float t) { for (unsigned i=0;i255.0) l=255.0; Wire.write(byte(i+1)); // Transmit the interpolated lengths Wire.write(byte(l)); Wire.endTransmission(); } } int size() { return values.size(); } }; class Look { // The state of the dress/garment Colors colors; Lengths lengths; public: int getColorCount() { return colors.size(); } int getLengthCount() { return lengths.size(); } void add(Color newColor) { colors.add(newColor); } void add(Length newL) { lengths.add(newL); } void transfigure(Look *other,float t){ colors.transfigure(other->colors,t); lengths.transfigure(other->lengths,t); } }; #define PM true #define AM false #define STEP 0 #define SPIN 1 #define TIME 2 class Situation { // A situation that causes a need for a new look protected: int type, count, ghour,gminute,gsecond; bool pm; public: bool hasOccurred() { bool retval=false; switch(type) { case STEP: retval=(lastStepCount looks; Vector situations; Vector transitions; Look *current; Look *last; float t,peg,transitionTime; float getPeg() { return ((float)millis())/1000.0; } void setPeg() { peg=getPeg(); } public: Occasion(float newTransitionTime=3.0) { transitionTime=newTransitionTime; } void startWith(Look &l) { current=&l; last=&l; setPeg(); } void add(Look &l) { looks.push_back(&l); } void add(Situation &s) { situations.push_back(&s); } void loop(){ // move through the FSM for (unsigned s=0;shasOccurred()) { for (unsigned t=0;t1.0) t=1.0; current->transfigure(last,t); } void setup(){ int NumPixels=current->getColorCount(); Adafruit_NeoPixel temp=Adafruit_NeoPixel(NumPixels, 3, NEO_GRB + NEO_KHZ800); pixels=&temp; Wire.begin(); CurieIMU.begin(); CurieIMU.setStepDetectionMode(CURIE_IMU_STEP_MODE_NORMAL); CurieIMU.setStepCountEnabled(true); CurieIMU.attachInterrupt(eventCallback); CurieIMU.interrupts(CURIE_IMU_STEP); pixels->begin(); } void when(Situation &occurs,Look ¤t,Look &next) { Transition t(occurs,current,next); transitions.push_back(t); } };