/* This code : Counts the number of Pull ups,
Plays Music during workout,Post on facebook when U reach a milestone ,
auto Pause Music and Auto reset the counter
Created By: Khatab Salah
if you need help or have any notices Contact me
at: Khatab163@gmail.com*/
#define CUSTOM_SETTINGS
#define INCLUDE_MUSIC_PLAYER_SHIELD
#define INCLUDE_TERMINAL_SHIELD
#define INCLUDE_TEXT_TO_SPEECH_SHIELD
#define INCLUDE_FACEBOOK_SHIELD
/* Include 1Sheeld library. */
#include <OneSheeld.h>
/* UltraSonic library. */
#include "Ultrasonic.h"
Ultrasonic ultrasonic(11, 10); //(Trig,Echo)
boolean flag, speechFlag;
int i,n;
void setup()
{
/*Start communication*/
OneSheeld.begin();
}
void loop() {
/* detect motion within 70cm*/
if(ultrasonic.Ranging(CM)<70)
{
/* check brevious State of the sensor */
if(flag==0)
{
/* Display the number on the terminal*/
Terminal.println(n);
/* Set the volume. */
MusicPlayer.setVolume(5);
/* Turn on the music. */
MusicPlayer.play();
/*change the state of the sensor*/
flag=1;
/* reset timer*/
i=0;
speechFlag = 0;
/* increase counter by 1 */
n++;
/*Tells the current number using text-to-speech */
String s = "";
s.concat(n);
TextToSpeech.say(s);
}
}
else if(ultrasonic.Ranging(CM)>=70)
{
/* reset sensor state */
flag=0;
/*wait half second Every Iteration */
delay(500);
i++;
}
/* Facebook Post when you achieve a milestone */
if (n=10)
{
Facebook.post(" yeaaah , a new milestone Achieved :D ");
}
/* Pause music After 20 Iteration Away from sensor (10 Seconds) */
if(i>=20)
{
MusicPlayer.pause();
}
/* Reset Progress after 60 Iteration Away from sensor (30 Seconds*/
if(i>=60 && speechFlag == 0)
{
TextToSpeech.say("You got away for too long, progress reset");
/* Reset Counter */
n=0;
speechFlag = 1;
}
}
Comments