Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Nathan Braaten
Published

Weasley Clock (Magical Location Clock)

Inspired by the Weasley Clock from Harry Potter, track your family using their phones' GPS! Create using limited programming knowledge.

IntermediateFull instructions provided12 hours2,422
Weasley Clock (Magical Location Clock)

Things used in this project

Hardware components

Photon
Particle Photon
I would suggest purchasing their beginners pack. The pack includes the small wires you will need. Also, the book gives you a good overview if you are new to programming and electronics.
×1
Clock
Choose one which you like. I suggest looking for broken clocks at your local thrift stores.
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
Also, a corresponding wall charger.
×1
Foam board
Size it to your clock.
×1
Spray Paint
Both white and black cans, one of each.
×1
Foam Alphabet Stickers
The foam allows for easy removal.
×1

Software apps and online services

Maker service
IFTTT Maker service

Hand tools and fabrication machines

Hand Drill
Soldering iron (generic)
Soldering iron (generic)
Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Schematics

Weasley Clock Circuit

Red is power. Blue is Ground. White is Data.

Code

Weasley Clock

C/C++
Use in build.particle.io

This code is modified from tbornottb 's original code.

https://github.com/tbornottb/Weasley-Clock
// This #include statement was automatically added by the Particle IDE.
#include "neopixel/neopixel.h"
#include <stdio.h>
#include <string.h>
#include <math.h>

int number_for_key(String key, struct entry dict[]);

#define PIXEL_COUNT 50


Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, D3, WS2812B);
int brite = 3;

struct entry {
    String str;
    int n;
};

struct entry places[] = { //After the first letter and a space, write this word in IFTTT
    "peril", 1,
    "lost", 2,
    "school", 3,
    "home", 4,
	"church", 5,
	"work", 6,
    0,0
};

struct entry people[] = { //This letter should be first character in IFTTT
    "I", 1,
    "E", 2,
    "B", 3,
    "A", 4,
	"M", 5,
	"D", 6,
    0,0
};

struct entry colors[] = { //Defines the color for each name.
    "I", 0x00ff00,
    "E", 0xff0000,
    "B", 0xffff00,
    "A", 0x00ff80,
	"M", 0xff00ff,
	"D", 0x0000ff,
    0,0
};

//name=people=capitalized letters

int updateClock(String command) {
  int commaIndex = command.indexOf(' '); //locate the space
  int secondCommaIndex = command.indexOf(' ', commaIndex+1); //locate the second space, starting one character after the first space
  String name = command.substring(0, commaIndex); //name's value is the string starting at the beginning and ending before the space
  String loc = command.substring(commaIndex+1, secondCommaIndex); //loc's value is the string starting after the space and ending before the second space
  int person = number_for_key(name, people); //check for match between the string, name, and people then record the number of the person
  if(person != 0){
	  flashB(number_for_key(name, colors)); //send color code to flash B for name
	  int place = number_for_key(loc, places);
	  if(place != 0){
	      
		  allMineOff(person);
		    int personcolor = number_for_key(name, colors);
		  	int red = floor(personcolor / (256*256));
            int green = (int)floor(personcolor / 256) % 256;
            int blue = personcolor % 256;
		  strip.setPixelColor(7+person+6*place, strip.Color(green, red, blue));
		  strip.show();
	  }
  }
  return 1;
}

void setup() {
    Particle.function("updateClock", updateClock);
    //pinMode(buttonPin, INPUT);
	strip.begin();
    strip.show();
	startupSwirl();
	strip.setBrightness(80);
	allOff();
	for(int j=1; j<=6; j++) { // set everyone to home
	    strip.setPixelColor(7+j+6*4, strip.Color(255, 255, 255));
	}
}

void loop() {
    strip.show();
    strip.setBrightness(50);
}

int number_for_key(String key, struct entry dict[]){ //checks the given name with the list of names allowed, returns number of match
    for(int j=0; j<6; j++) {
        String name = dict[j].str;
        if (strcmp(name, key) == 0)
            return dict[j].n;
    }
    return 0;
}

//This swirl is just for flashiness, only occurs on start up.
void startupSwirl() { // outer hands counterclockwise, inner hands clockwise
	int swirldelay = 50;
	for(int j=0; j<2; j++) {
    	for(int i=14; i<50; i+=3) {
    		allOff();
    		strip.setPixelColor(i, strip.Color(255, 255, 255));
    		strip.setPixelColor(62-i, strip.Color(255, 255, 255));
    		strip.show();
    		delay(swirldelay);
    		
    		allOff();
    		strip.setPixelColor(i+2, strip.Color(255, 255, 255));
    		strip.setPixelColor(62-i, strip.Color(255, 255, 255));
    		strip.show();
    		delay(swirldelay);
    	}
	}
}


void flashB(int hexValue){
	int red = floor(hexValue / (256*256));
    int green = (int)floor(hexValue / 256) % 256;
    int blue = hexValue % 256;
	for(int j=0; j<5; j++) {
		for(int i=0; i<14; i++) {
			strip.setPixelColor(i, strip.Color(green, red, blue));
		}
		strip.show();
		delay(300);
		for(int i=0; i<14; i++) {
			strip.setPixelColor(i, strip.Color(0,0,0));
		}
		strip.show();
		delay(300);
	}
}

void allMineOff(int n) {
	for(int i=7+n; i<PIXEL_COUNT; i+=6) {
		strip.setPixelColor(i, strip.Color(0, 0, 0));
	}
	strip.show();
}

void allOff() {
	for(int i=0; i<PIXEL_COUNT; i++) {
		strip.setPixelColor(i, strip.Color(0, 0, 0));
	}
	strip.show();
}

void debug(String message, int value) {
    char msg [50];
    sprintf(msg, message.c_str(), value);
    Spark.publish("DEBUG", msg);
}

Credits

Nathan Braaten

Nathan Braaten

1 project • 1 follower

Comments