Bryant Patten
Published © CC BY-NC-SA

Just Checking In

A gentle way of letting someone know you are thinking of them and, with a simple button push, they can let you know they are fine.

IntermediateShowcase (no instructions)4 hours721
Just Checking In

Things used in this project

Hardware components

Photon
Particle Photon
×1
Adafruit perma-proto quarter size board
×1
Adafruit NeoPixel Ring 12
×1
Adafruit Rugged Metal Pushbutton LED
×1
Adafruit 6-pin JST SM Plug and Receptacle Cable set
×1
Resistor 221 ohm
Resistor 221 ohm
×3

Story

Read more

Custom parts and enclosures

Check In Box

This is the top of the device that holds the button

Check In Base

This is the base of the device which holds the Photon and NeoPixel ring

Schematics

CheckIn Schematic

Code

Check In V4

Arduino
// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>


/******************************************************************************
checkIn V4
  BMP 2019-09-02
  BMP 2019-09-14  - changed PIR sensors so now detecting HIGH
  BMP 2019-11-30  - Added multiple users
  
  This code is designed to work on the Particle Photon
  The purpose of this system is to allow people to easily check in with someone else and to have that person easily respond.
  Person A presses a button on one of the devices.  This causes the all devices to light up.  
  Person B can then push the button on their device and the color will change to green, indicating they are fine.
  
  Things still to do:  If any box is offline, it will miss a published event and be out of sync
    - Functionality should be added to periodically check state
******************************************************************************/
#define PIXEL_COUNT 12						// 12 Pixels on our ring
#define PIXEL_PIN D4						// Ring uses D4 as default pin
#define PIXEL_TYPE WS2812B					// Ring uses WS2812 Pixels

Adafruit_NeoPixel ring(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);	// Create out “ring” object	



const int BUTTON_RED_PIN = 0; // Pin connected to Red pin on RGB LED Button 
const int BUTTON_GREEN_PIN = 1; // Pin connected to Green pin on RGB LED Button 
const int BUTTON_BLUE_PIN = 2; // Pin connected to Blue pin on RGB LED Button 

const int NEOPIXEL_DATA = 4; // NeoPixel data in pin - active-high
const int BUTTON_PIN = 5; // LED pin - active-high

const int GMT_OFFSET = 5; // 5:00 AM = Midnight Eastern  and 1 AM DST
const unsigned long CHECK_DELAY = 900000; // 900000 milliseconds = 15 minutes

//Box IDs
String Box1_ID = "2c";  
String Box2_ID = "31";  
String Box3_ID = "34";  
String Box4_ID = "2f";  



String CurrentState;  //three states are: off / white | check in (red / pink / aqua) | green
String myID;  //used to identify which box is pressed
String localColor;  // Check In color specific to local machine

unsigned long LastCheck;

void setup() {

  pinMode(BUTTON_RED_PIN, OUTPUT);
  pinMode(BUTTON_GREEN_PIN, OUTPUT);
  pinMode(BUTTON_BLUE_PIN, OUTPUT);
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  pinMode(NEOPIXEL_DATA, OUTPUT);

  
  // Start the NeoPixel object
  ring.begin();       
  ring.setBrightness(125);  
  
  setRingColor("off");
  
  CurrentState = "white";
  
  
  CheckNetwork();
  LastCheck = millis();
  
  Time.zone(-4);
  
   //Set up messaging system between machines
  Particle.subscribe("CheckIn",CheckIn_Respond, MY_DEVICES);
  
  //Grab enough of the Device ID to make each box unique.
  myID = System.deviceID();
  myID = myID.substring(0, 2);
  
   setLocalColor(myID);

}

void loop() {
                                                                                                                                                                                            
  
  delay(550);
  
  if ((millis() - LastCheck) > CHECK_DELAY) { // check network connection and 'is it a new day' every 15 minutes
      CheckNetwork();
      CheckMidnightReset();
      LastCheck = millis();  // reset the delay check value
     
  }
  
 
 CheckButton();
}



void CheckButton() {
    // This routine deals with the button press.  What it does depends upon the state of the system
    int buttonState = digitalRead(BUTTON_PIN);
    if (buttonState == LOW) {// button is pressed
    Serial.println("button press!");
        if(CurrentState == "white"){  // Requesting a 'checkin'
            setButtonColor(localColor);  // Set to red
            setRingColor(localColor);
            Particle.publish("CheckIn",localColor, PRIVATE);
            CurrentState = localColor;  //temp until subscribe ?
            delay(550);
        }
        else if((CurrentState == "red") || (CurrentState == "pink") || (CurrentState == "aqua")){  // Responding to a 'checkin' request with 'I am fine'
            setButtonColor("green");  // Set to green
            setRingColor("green");
            Particle.publish("CheckIn","green", PRIVATE);
            CurrentState = "green";  //temp until subscribe ?
            delay(550);
        }
        else if(CurrentState == "green"){  // Responding to response
            setButtonColor("white");  // Set to white
            setRingColor("white");
            Particle.publish("CheckIn","white", PRIVATE);
            CurrentState = "white";  //temp until subscribe ?
            delay(550);
        }
          
    }
}
 
void CheckNetwork() {
    //This routine checks whether the Photon is still connected.  If yes, light the lED in the switch.  If not, turn off LED
    // This routine is checked every 15 minutes
  if(Particle.connected()){
      setButtonColor("white");  // Set to White
    }
  else {
      setButtonColor("blue");  // Blue = no network 
        }
}
  
void CheckMidnightReset() {
    //This routine checks whether a new day have begun (midnight) and therefore the unit should be reset
    // This routine is checked every
    int localHour;
    
    localHour = Time.hour(Time.now());

    if((localHour  < 2) && (CurrentState != "white")){
        setRingColor("white");
        setButtonColor("white");  // Set to white
        Particle.publish("CheckIn","white", PRIVATE);
        CurrentState = "off";  //temp until subscribe ?
    }
    else{
        Serial.print(String(localHour));
        Serial.print(" > ");
        Serial.println(String(2));
    
    }
  }
  
  
void CheckIn_Respond(const char *event, const char *data){
     String passedString;
   
    passedString = data;

    if(passedString == "red"){
        setButtonColor("red");  // Set to red
        setRingColor("red");
        CurrentState = "red"; 
    }
    else if (passedString == "green"){
        setButtonColor("green");  // Set to green
        setRingColor("green");
        CurrentState = "green";  
    }
    else if(passedString == "white"){
        setButtonColor("white");  // Set to white
        setRingColor("white");
        CurrentState = "white";  
    }
     else if(passedString == "aqua"){
        setButtonColor("aqua");  // Set to aqua
        setRingColor("aqua");
        CurrentState = "aqua";  
    }
     else if(passedString == "pink"){
        setButtonColor("pink");  // Set to pink
        setRingColor("pink");
        CurrentState = "pink";  
    }

}

void setButtonColor(String curColor)
{
     int red;
    int green;
    int blue;

    if(curColor == "white"){  // Set to red
        red = 255;
        green = 255;
        blue = 255;
        }
        else if(curColor == "red"){  // Requesting a 'checkin'
            red = 255;
            green = 0;
            blue = 0;
        }
        else if(curColor == "green"){  // Checking In
            red = 0;
            green = 255;
            blue = 0;
        }
        else if(curColor == "aqua"){  // Checking In
            red = 0;
            green = 255;
            blue = 255;
        }
        else if(curColor == "pink"){  // Checking In
            red = 255;
            green = 0;
            blue = 204;
        }
        else if(curColor == "blue"){  // Checking In
            red = 0;
            green = 0;
            blue = 255;
        }
        
   //because COMMON_ANODE
    red = 255 - red;
    green = 255 - green;
    blue = 255 - blue;

  
  analogWrite(BUTTON_RED_PIN, red);
  analogWrite(BUTTON_GREEN_PIN, green);
  analogWrite(BUTTON_BLUE_PIN, blue);  
}

void setLocalColor(String curID){
     
     if(curID == Box1_ID){  
        localColor = "red";
        }
        else if(curID == Box2_ID){  
            localColor = "pink";
        }
        else if(curID == Box3_ID){  
            localColor = "red";
        }
        else if(curID == Box4_ID){  
            localColor = "aqua";
        }
}

void setRingColor(String curColor){
    int curRED;
    int curGreen;
    int curBlue;
    int pixelCounter;
    
    
    if(curColor == "white"){  // Set to red
        curRED = 0;
        curGreen = 0;
        curBlue = 0;
        }
        else if(curColor == "red"){  // Requesting a 'checkin'
            curRED = 255;
            curGreen = 0;
            curBlue = 0;
        }
        else if(curColor == "green"){  // Checking In
            curRED = 0;
            curGreen = 255;
            curBlue = 0;
        }
        else if(curColor == "aqua"){  // Checking In
            curRED = 0;
            curGreen = 255;
            curBlue = 255;
        }
        else if(curColor == "pink"){  // Checking In
            curRED = 255;
            curGreen = 0;
            curBlue = 204;
        }
        

      for(int i = 0; i < PIXEL_COUNT; i ++) {
        if(i == pixelCounter)
            // Clear the LED
           // ring.setPixelColor(i, 0, 0, 0);  
            ring.setPixelColor(i, curRED, curGreen, curBlue); 
            // Update the NeoPixel
            pixelCounter ++;
             delay(50);
    
            // Update the NeoPixel
            ring.show();  
      }
    

}

Credits

Bryant Patten

Bryant Patten

3 projects • 3 followers

Comments

Add projectSign up / Login