Donavin
Published

Gains Box

Get your weight up !

BeginnerWork in progress38

Things used in this project

Hardware components

Photon 2
Particle Photon 2
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Buzzer
Buzzer
×1
OLED Expansion
Onion Corporation OLED Expansion
×1
Flora RGB Neopixel LEDs- Pack of 4
Adafruit Flora RGB Neopixel LEDs- Pack of 4
×1
Rotary Encoder with Push-Button
Rotary Encoder with Push-Button
×1

Software apps and online services

VS Code
Microsoft VS Code

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Schematics

Fritzing

Code

1104

C/C++
Gains Box ! GET YOUR WEIGHT UP !
/* 
 * Project Gains
 * Author: Donavin Merritt
 * Date: 
 * For comprehensive documentation and examples, please visit:
 * https://docs.particle.io/firmware/best-practices/firmware-template/
 */

// Include Particle Device OS APIs
#include "Particle.h"
#include "Adafruit_SSD1306.h"
#include "Adafruit_GFX.h"
#include "Button.h"
//#include "wemo.h"
#include "neopixel.h"
#include "Colors.h"
#include "Encoder.h"
#include "hue.h"


long duration;
int cm;
int inch;

// Encoder
const int CLK = D16;// white wire 
const int DT = D5; // blue wire  
const int SW = D6; //green wire // also button


//OLED
#define OLED_RESET (D4)
Adafruit_SSD1306 onscreen(OLED_RESET);

//HC_SR04 sonar(TRIG,ECHO,MaxDist);

void testdrawchar(void);

// Ultrasonic Sensor

int trigPin = D10;
int echoPin = A2;

// Buzzer

int buzzer = A5;

//Other 

int pushups;
bool inchDn;
bool inchUp;

// Wemo

// bool wemoOnOff = false;
// bool WEMO_STATE;
// const int WEM01 =1;
// int timer;



// Hue Lamps

int bulbQty[6]; // total number of bulbs in classroom 
int bulbId[] = {0,1,2,3,4,5};
bool onOff;

//Encoder

String ONOFF;
Button ENCODERBUTTON(SW);
Encoder myEnc (CLK,DT);

//Neopixel

int neopixel = D2;
const int PXQTY = 2;



//SYSTEM_MODE(MANUAL);

//SYSTEM_MODE(AUTOMATIC); 

SYSTEM_MODE(MANUAL); 

//Specific to neopixel cntrl

Adafruit_NeoPixel gains(PXQTY,SPI1,WS2812B);

// Show system, cloud connectivity, and application logs over USB
// View logs with CLI using 'particle serial monitor --follow'
//SerialLogHandler logHandler(LOG_LEVEL_INFO);

// setup() runs once, when the device is first turned on

// Ultra Sonic Sensor

void setup() {

  Serial.begin(9600);

  waitFor(Serial.isConnected,10'000);

// Neopixel

//pinMode(neopixel,OUTPUT);
gains.begin();
gains.show();

// Ultrasonic Sensor

  pinMode(trigPin,OUTPUT);    
  pinMode(echoPin,INPUT);    
  pinMode(buzzer,OUTPUT);  

//Encoder

  pinMode(SW,INPUT);

//Wemo

 // onOff = true;
 // WiFi.on();
 // WiFi.setCredentials("IoTNetwork");
 // WiFi.connect();
 // while(WiFi.connecting())
  //  Serial.printf("Connecting\n");
  
  
//OLED

  onscreen.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  onscreen.printf("CM_%d \n IN_%d",cm,inch);
  onscreen.display();
  
}

 
  

// loop() runs over and over again, as quickly as it can execute.
  void loop() {

  testdrawchar();

  // First run the Ultrasonic

  digitalWrite(trigPin,LOW);
  digitalWrite(trigPin,HIGH);
  digitalWrite(trigPin,LOW);

  duration = pulseIn(echoPin, HIGH);

  cm= (duration/2)*0.034;
  inch = (duration/2)*0.0135;

  if(inch <= 3){ // buzzer rings true for optimal dn position
    tone( buzzer, 500,500);
  }

   if( inch >=12 && inch <=15){ //buzzer rings true for opitmal up position
    //delay(500);
    tone(buzzer,400,200);
  }

          
//  once both up and down are true then count pushups, reset the 
// up and down to false to continue count, then use a button to reset pushups counter to zero.
    
    if ( inch <= 3 && inchUp == true){ // this condition has two conditions
      inchDn = true;
    }

    if ( inch >=10 && inch <=13){ // register true for number between 12 and 15 including 12 and 15
      inchUp = true;
    }

    if(inchDn && inchUp){
      pushups ++; // reset T/F statements after count lets see if the count continues!
      inchUp = false;
      inchDn = false;
  }

  if (pushups == 3) {
    for ( int i = 0; i < 6; i++){
      setHue(bulbId[i], true, HueGreen, 255, 55);
    }
  }

  if (ENCODERBUTTON.isClicked()) {
    for ( int pixel = 0; pixel < PXQTY; pixel ++ ){
  
      pushups = 0;  // reset push ups to also cut on wemo fan for 10 seconds      
      gains.setPixelColor(pixel,blue);
      gains.setBrightness(100);
      gains.show();
  }
}

//Wemo

// if (ENCODERBUTTON.isClicked()) {
//   WEMO_STATE == true;
//   timer = millis();
// }

// enter rest mode for 10 seconds

// if (millis() - timer > 10000) {
//     WEMO_STATE == false;
//   }

  // Neopixel

  if (inch <= 3) {

      for ( int pixel = 0; pixel < PXQTY; pixel ++ ) {

      gains.setPixelColor(pixel,red);
      gains.setBrightness(75);
      gains.show(); 
      }
  }

  if (pushups == 10){

    for ( int pixel = 0; pixel < PXQTY; pixel ++ ) {
      
      gains.setPixelColor(pixel,green);
      gains.setBrightness(100);
      gains.show(); 
    }
  }
  }

  // Example: Publish event to cloud every 10 seconds. Uncomment the next 3 lines to try it!
  // Log.info("Sending Hello World to the cloud!");
  // Particle.publish("Hello world!");
  // delay( 10 * 1000 ); // milliseconds and blocking - see docs for more info!

void testdrawchar () {

  onscreen.setTextSize(1);
  onscreen.setTextColor(WHITE);
  onscreen.setCursor(0,0); // Sets the location at which subsequent text written to the LCD will be displayed
  onscreen.clearDisplay();
  onscreen.printf("IN-%d \n UP%i \n DN%i \n PUSHUPS-%d ",inch,inchUp,inchDn,pushups);
  onscreen.display();
  onscreen.clearDisplay();

  Serial.printf("CM-%d \n IN-%d \n PU-%d",cm,inch,pushups);
}

Gains Box

Gains Box is also a limited smart room controller. Nevertheless, was designed with the intent to implement fitness challenges.

Credits

Donavin

Donavin

0 projects • 0 followers

Comments

Add projectSign up / Login