About functions

Hi programmers! I'm sorry but I'm french so my English won't be that good, thinks for your help.

I'm doing a program with some different kind of sensor, a gyro, a buzzer, a cardio sensor, and a gps ( and a button but it's not really a sensor). I've Just copied the code of each sensors but now I need some structures or functions, call this as you want. I've added my program down there.

After my cardio sensor I'd like to have an if, like " if (gyro =1 and cardio = 1){ ", to activate the buzzer just when the gyro and cardio sensor are in a bad position, if you see what I mean.

Then, after the buzzer I'd like to have while loop. This while loop will use to wait 10 seconds and if the user doesn't push the button gps's informations are send, but if the user push the button in this 10 seconds, all stop.

Thinks for your help, I hope you'll understand what I'd like to mean.

Sys.ino (3.48 KB)

Your English is better than a lot of native English posters here, really! :slight_smile:

I notice that you have two delay() calls, totalling 1.5 seconds in your loop() function. That will destroy your plans of using push buttons, because they will be inactive during those periods. You have to use millis() instead, unless you can tolerate the buttons responding extremely slowly. It would be frustrating for most users.

Haha , think you !
But I need an answer quickly, this work is for a team work in electronic lesson for Tuesday, and it's marked... x)

I think you can just remove the delays, and do something like... put all that sensor checking data into a function, let's call it getSensorData(), and have it update globals storing the state of the sensors, say in HeartRate, GyroX, GyroY, GyroZ instead of printing them out (or in addition to it), probably in int (or float) datatype.

Then do like

if (millis()-sensorTime > 1000) {
getSensorData(); 
sensorTime=millis();
if (heartRate == 0 && GyroX <5000 && GyroY < 5000 && GyroZ >5000) { //those numbers make sense if they've been converted to mm/s^2 (I don't know off the top of my head the units your gyro gives)
Serial.print("Zombie alert: Subject is standing up but has no heart beat!"); 
}
}
//do some checking of the buttons and all that other stuff in loop.

titouman:
this work is for a team work in electronic lesson for Tuesday, and it's marked... x)

oooo.... shouldn't have said that!

Mmmmm. Yeah, it's only Saturday on my calendar... and where's the rest of your team? C'mon.

What do you mean ? We're working on a system for ill people, 2 mates did the experience and the presentation and the other one is with me on the prog.

titouman:
What do you mean ? We're working on a system for ill people, 2 mates did the experience and the presentation and the other one is with me on the prog.

So did you get any results from trying the suggestions in reply #3?