So, I've been working on arduino off and on for less than a year, and this is my first attempt to make a custom library, and I am struggling. I've gotten everything written out and it even seems like the code likes the library, except for one error message I keep getting when I try to run a program from the custom class I created. I'm trying to store my exercise routine in an arduino. Basically trying to combine my love of arduino with the motication to get active. Haha. The program without the class compiles just fine, so I know it's not the program, so let me just throw the library out files out there. Header first.
#ifndef Exercise_h
#define Exercise_h
#include <Arduino.h>
//Declare Variables
const long oneSecond = 1000;
const long oneMin = oneSecond * 60;
long startSetMillis = 0, startRepMillis = 0, startSecMillis = 0;
int sets = 0, reps = 0, mins = 0, secs = 0, restset = 5;
int numSet = 0, numRep = 0, numMin = -1, numSec = 0, setSec = 0, spd = 0;
boolean status_on = true;
boolean start_sets = true, start_reps = true, start_secs = true;
boolean exerprep = true;
//Define Exercise class
class exercise
{
public:
int Type; //Frequency or Duration Exercise
char Specify; //Specify exactly which exercise to perform
int Sets; //Sets to perform
int Rest; //Rest time between sets
int Duration; //How long to hold duration exercise
int Reps; //Reps to perform during each set on a frequency exercise
int Speed; //Speed at which to complete each rep on a frequency exercise
void initializeExer();
void countReps();
void countRepSets();
void countSecs();
void countTimeSets();
};
#endif
And the .cpp.
#include <Exercise.h>
void initializeExer() //Initializes all variables to default state
{
sets = 0;
reps = 0;
secs = 0;
numSet = 0;
numRep = 0;
numMin = -1;
numSec = 0;
restset = 5;
status_on = true;
start_sets = true;
start_reps = true;
start_secs = true;
exerprep = true;
}
void countReps()
{
if(start_reps)
{
startRepMillis = millis();
start_reps = false;
}
else {
if(((millis()-startRepMillis) > spd*oneSecond) && (numRep >= 0) && status_on)
{
if(numRep > 0)
{
numRep--;
start_reps = true;
for (int i=0; i<150; i++)
{
digitalWrite(12, HIGH);
delayMicroseconds(750);
digitalWrite(12, LOW);
delayMicroseconds(750);
}
}
else if(numRep == 0) {
numRep = reps;
numSet--;
startSetMillis = millis();
for (int i=0; i<200; i++)
{
digitalWrite(12, HIGH);
delayMicroseconds(1000);
digitalWrite(12, LOW);
delayMicroseconds(1000);
}
}
}
}
}
void countRepSets(exercise repSets)
{
if(exerprep == true)
{
numSet = repSets.Sets;
numRep = repSets.Reps;
exerprep = false;
}
if((numSet == sets) && status_on)
{
countReps();
}
else if((numSet > 0) && (numSet < repSets.Sets) && status_on){
if((millis()-startSetMillis) > (repSets.Rest*oneSecond)){
countReps();
}
}
else if(numSet <= 0){
delay(oneSecond);
for(int a=0; a<5; a++)
{
for (int i=0; i<250; i++)
{
digitalWrite(12, HIGH);
delayMicroseconds(500);
digitalWrite(12, LOW);
delayMicroseconds(500);
}
delay(100);
}
}
}
void countSecs()
{
if(start_secs){
startSecMillis = millis();
start_secs = false;
}
else
{
if(((millis() - startSecMillis) >= oneSecond) && (numSec >= 0) && status_on)
{
if((numSec / 60) != numMin)
{
numMin = numSec / 60;
}
if(numSec > 0){
numSec = numSec - 1;
start_secs = true;
}
else if(numSec == 0)
{
numSec = setSec;
numSet--;
startSetMillis = millis();
for (int i=0; i<250; i++)
{
digitalWrite(12, HIGH);
delayMicroseconds(1000);
digitalWrite(12, LOW);
delayMicroseconds(1000);
}
}
}
}
}
void countTimeSets(exercise timedSets)
{
if (exerprep == true)
{
numSet = timedSets.Sets;
numMin = -1;
setSec = timedSets.Duration;
numSec = setSec;
exerprep = false;
}
if((numSet == timedSets.Sets) && status_on)
{
countSecs();
}
else if((numSet > 0) && (numSet < timedSets.Sets) && status_on){
if((millis() - startSetMillis) > (timedSets.Rest*oneSecond)){
countSecs();
}
}
else if(numSet <= 0){
delay(oneSecond);
for(int a=0; a<5; a++)
{
for (int i=0; i<250; i++)
{
digitalWrite(12, HIGH);
delayMicroseconds(500);
digitalWrite(12, LOW);
delayMicroseconds(500);
}
delay(100);
}
}
}
Any guidance you guys can offer is great! I'm not looking to have the answer handed to me, just looking for the right direction to travel in. I'll also link the error codes that I'm getting when I compile in the next post.