Mike Westman
Published © GPL3+

Weasley Clock

An analog clock that uses hands to show the physical location of family members.

IntermediateShowcase (no instructions)Over 3 days1,376
Weasley Clock

Things used in this project

Hardware components

Photon
Particle Photon
×1
SparkFun Easy Driver
×2
Coaxial stepper motor
×1

Software apps and online services

Tasker

Story

Read more

Schematics

Device layout

Code

Particle code

Arduino
This is the code that runs on the Photon
// This #include statement was automatically added by the Particle IDE.
#include "AccelStepperSpark/AccelStepperSpark.h"

const int traveling = 480;
const int library = 955;
const int home = 1430;
const int starbucks = 1905;
const int mortalperil = 2380;
const int parents = 2855;
const int knitting = 3330;
const int work = 3805;
const int friends = 4280;



// Define two steppers and the pins they will use
AccelStepper stepper1(1, D1, D0);
AccelStepper stepper2(1, D3, D2);

void setup()
{  
  stepper1.setMaxSpeed(500);
  stepper1.setAcceleration(10);
  stepper1.runToNewPosition(-6000);
  stepper1.setCurrentPosition(0); 
  stepper1.runToNewPosition(mortalperil);

  stepper2.setMaxSpeed(500);
  stepper2.setAcceleration(10);
  stepper2.runToNewPosition(-6000);
  stepper2.setCurrentPosition(0); 
  stepper2.runToNewPosition(mortalperil);

  digitalWrite(D7, HIGH);

  bool success1 = Particle.function("resetClock", resetClock);
  bool success2 = Particle.function("personMove", personMove);
}

void loop()
{
    stepper1.run();
    stepper2.run();
}

int resetClock(String newPos)
{
    System.reset();
}

int personMove(String dataIn)
{
    int newLoc=0;
    String member="";
    String place="";
    dataIn = dataIn.replace("%3A", ":");
    member=getValue(dataIn, ':', 0);
    place=getValue(dataIn, ':', 1);
    
    if ( place == "traveling" ) newLoc = traveling;
    if ( place == "library") newLoc = library;
    if ( place == "home") newLoc = home;
    if ( place == "starbucks") newLoc = starbucks;
    if ( place == "mortalperil") newLoc = mortalperil;
    if ( place == "parents") newLoc = parents;
    if ( place == "knitting") newLoc = knitting;
    if ( place == "work" ) newLoc = work;
    if ( place == "friends") newLoc = friends;
    
    if ( newLoc != 0 && member == "mike")
    {
        stepper1.moveTo(newLoc);
        return(stepper1.distanceToGo());
    }

    if ( newLoc != 0 && member == "tina" ) {
        stepper2.moveTo(newLoc);
        return(stepper2.distanceToGo());
    }
}


String getValue(String data, char separator, int index)
{
 int found = 0;
  int strIndex[] = {0, -1  };
  int maxIndex = data.length()-1;
  for(int i=0; i<=maxIndex && found<=index; i++){
  if(data.charAt(i)==separator || i==maxIndex){
  found++;
  strIndex[0] = strIndex[1]+1;
  strIndex[1] = (i == maxIndex) ? i+1 : i;
  }
 }
  return found>index ? data.substring(strIndex[0], strIndex[1]) : "";
}

Credits

Mike Westman

Mike Westman

1 project • 1 follower

Comments

Add projectSign up / Login