Things used in this project

Schematics

Photon 1
Particle Photon is responsible for starting the timer upon press of a button. When the button is pressed the LED on the breadboard is activated to let the user know the button pressed command will be sent up to the cloud.
Photon 1 e7ddaf62ev
Photon 2
The second photon is inserted in the Internet Button. The internet button consist of 11 LEDs, accelerometer, and buzzer. For the purpose of this project we only used the 11 LEDs lights and buzzer/speaker.
Internet button fqdmybiibf

Code

Photon 1: The Button (Signal)C/C++
This photon 1 has a button that is pressed and sends a signal to the cloud so photon 2 can respond by turning on the timer.
// We will be using D1 to control our LED
int ledPin = D1;

// Our button wired to D0
int buttonPin = D0;

void setup()
{

  // For input, we define the
  // pushbutton as an input-pullup
  // this uses an internal pullup resistor
  // to manage consistent reads from the device

  pinMode( buttonPin , INPUT_PULLUP); // sets pin as input

  // We also want to use the LED

  pinMode( ledPin , OUTPUT ); // sets pin as output

}

void loop()
{
   // find out if the button is pushed
   // or not by reading from it.
   int buttonState = digitalRead( buttonPin );
   

  

  // remember that we have wired the pushbutton to
  // ground and are using a pulldown resistor
  // that means, when the button is pushed,
  // we will get a LOW signal
  // when the button is not pushed we'll get a HIGH

  // let's use that to set our LED on or off
  delay(300);
 if( buttonState == LOW ){
     if (Particle.connected()) {
    Particle.publish("Button_Pressed", "2");
    
    // turn the LED On
    digitalWrite( ledPin, HIGH);}
  }else{
    // otherwise
    // turn the LED Off
    digitalWrite( ledPin, LOW);
 
  }


}
Photon 2: Timer (10 seconds and 1 minute)C/C++
This photon (Internet Button) gets the signal from the cloud and starts the 10 second timer. If button three is pressed on photon 2 (Internet Button) a 1 minute timer will start. Hold buttons 2 and 3 to cut the timer off once finished.
// This #include statement was automatically added by the Particle IDE.
#include <InternetButton.h>

// This #include statement was automatically added by the Particle IDE.
SYSTEM_THREAD(ENABLED);

InternetButton b = InternetButton();

unsigned long startTime = 0;
int ledNum = 0;
bool checkFlag = false;
bool subFlag = false;
int Butt = D7;


void setup() {
    //initiating Internet button
    b.allLedsOff();
    b.begin();
    initPomo();
    pinMode(Butt, OUTPUT);
    digitalWrite(Butt, LOW);
    

    Particle.subscribe("Button_Pressed", DatThang, "2a003e000d47343438323536");
   }

void DatThang(const char *event, const char *data){
    
    b.ledOn(1,255,0,0);
    delay(1000);
    //b.ledOff(1);
    //delay(10);
    
    b.ledOn(2,255,69,0);
    delay(1000);
    //b.ledOff(2);
    //delay(20);
    
    b.ledOn(3,255,215,0);
    delay(1000);
    //b.ledOff(3);
    //delay(30);
    
    b.ledOn(4,188,143,143);
    delay(1000);
    //b.ledOff(4);
    //delay(10);
    
    b.ledOn(5,148,0,211);
    delay(1000);
    //b.ledOff(5);
    //delay(10);
    
    b.ledOn(6,0,0,139);
    delay(1000);
    //b.ledOff(6);
    //delay(10);
    
    b.ledOn(7,65,105,225);
    delay(1000);
    //b.ledOff(7);
    //delay(10);
    
    b.ledOn(8,64,224,208);
    delay(1000);
    //b.ledOff(8);
    //delay(10);
    
    b.ledOn(9,34,139,34);
    delay(1000);
    //b.ledOff(9);
    //delay(10);
    
    b.ledOn(10,127,255,0);
    delay(1000);
    //b.ledOff(10);
    //delay(10);
    
    b.ledOn(11,3,255,0);
    delay(1000);
    //b.ledOff(11);
    //delay(10);
    
    b.rainbow(10);
    delay(5000);
    b.allLedsOff();
    b.playSong("E5,2,G5,8,E6,8,C6,4,D6,8,G6,8");
    
  
    //digitalWrite(Butt, HIGH);
    //pomoMain();
}
void loop() {
    checkButton();
    pomoMain();
}//main Application Loop


void pomoMain(){
    if(millis()-startTime > 10000UL && checkFlag){//750UL = .75seconds, ex: 327000UL = 5.45 minutes (at 5.45 minutes this will make a work session around 45 minutes with a 15 minute break)
        if(ledNum > 10){
            checkFlag = false;
            subFlag = true;
            partiTime();
        }else if(ledNum > 7){
            b.ledOn(++ledNum, 0,53,60); //ex: b.ledOn(ledNumber, red, green, blue) feel free to Modify these colors
        }else{
            b.ledOn(++ledNum, 200, 50, 100); // feel free to modify these colors :)
        }
        
        startTime = millis();
        
    }
}//pomoMain() is end of "work" cycle

void partiTime(){
    
    while(b.buttonOn(3) == 0 && subFlag){
        b.rainbow(8);
        Particle.process();
    }
    b.allLedsOff();
    b.playSong("E5,2,G5,8,E6,8,C6,4,D6,8,G6,8"); //song that plays at Reset
    initPomo();
    
}//partiTime function = end of full cycle

void initPomo(){
    ledNum = 0;
    b.ledOn(ledNum, 105,0,255);
    startTime = millis(); 
    checkFlag = false;
    subFlag = false;
}//initializing function for variables

void checkButton(){
    
    if(b.buttonOn(3) || b.buttonOn(2)){
        checkFlag = !checkFlag;
        delay(50);
        while(b.buttonOn(3));
        delay(50);
    }//end of checkFlag toggle
    
}//checkButton() is for Flag Checking

Credits

472f305109b02fad6ef0f273664fdce8
Vrajesh Patel
1 project • 0 followers
__hypernova_render_token[6d7dca8e91beb929c1917ad10737e421]__Contact
68fa032cd8f3830e53769ac57340984b
Terrell Britton
1 project • 0 followers
__hypernova_render_token[a8136ad24f0d4da73f57c076a01a73ac]__Contact

Comments