-
-
Save c010/90d61f970580bb5f6fc1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void bpm() | |
{ | |
permin = max_count*6;//to calculate your breaths per min | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float x = 0;//the starting value | |
int stats = 0; | |
void inOrout() | |
{ | |
float reading; | |
reading = analogRead(THERMISTORPIN); | |
// convert the value to resistance | |
reading = (1023 / reading) - 1; | |
reading = SERIESRESISTOR / reading;// the numbers that the rubber is getting | |
if ( reading > x)//inhaling | |
// if the current restistence is greater then previos resistence | |
{ | |
x = reading;// constantly store the conductive rubber reading in x | |
if (stats == 0)// has yet to exhale | |
{ | |
max_count++;// increase the number of breaths by 1 | |
stats = 1; | |
} | |
} | |
else if (reading < x)//exhaling | |
{ | |
x = reading; | |
if (stats == 1) //while reading is getting smaller the state is 0 | |
//therefore when reading gets bigger again it will know | |
//that you are inhaling agian adding to the counter | |
{ | |
stats = 0; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int max_count = 0; | |
int permin; | |
#define THERMISTORPIN A5 | |
#define SERIESRESISTOR 10000 | |
//int lightValue = 0; | |
String inString = ""; | |
void setup() | |
{ | |
// put your setup code here, to run once: | |
Serial.begin(9600); | |
pinMode(THERMISTORPIN, INPUT); | |
} | |
void loop() | |
{ | |
timer(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsigned long interval = 10000; | |
unsigned long previousMillis = 0; | |
void timer() | |
{ | |
unsigned long currentMillis = millis(); | |
inOrout(); | |
// if time is greater than 10 secconds do this if statment | |
if ((unsigned long)(currentMillis - previousMillis) >= interval) | |
{ | |
previousMillis = currentMillis; | |
bpm(); | |
Serial.print("Breaths per minute: ");Serial.println(permin); | |
max_count= 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment