Timer + on-off

Hello! i am relatively new to Arduino, but i am trying to create a timer for a Breathing program to have a certain time for a loop before it is stopped, and i need some help on trying to get an analog input so that if you turn it on-off less than 5 times in one minute, and keep doing that for three minutes, it will flash a blue led 3 times.

Code:

//this is only gonna run once so this is only a test
  
//Variables
int blueled = 7;
int redled = 8;
float breathing[24];
float Counter1;
int minbreath = 5;
int maxbreath = 10;
float Counter2;
int minutes = 2;
int varcount = 3;
int alertconditional = constrain(alertconditional, 1, 4); // how it was going to do the five times in three minutes (check the asterisks, same with the other constrains) 
int alertconditional1 = constrain(alertconditional1, 11, 28); 
int goodconditional = constrain(goodconditional, 6, 9);
boolean digitaltoanalog; // to check the analoginput
//Variables
     unsigned long Timer; // my original attempt at creating a timer, which will now be known as //T
 
void setup() {
    Serial.begin(9600);
pinMode(blueled, OUTPUT);
pinMode(redled, OUTPUT);
 Timer = millis();//T
}
void loop() {
   // this is to count the number of breaths a dog takes in a minute, and a potentiometer is used to replicate a flex sensor
   float regularvolt = (analogRead(A2)) * 45.0 / 1024.0;
   loop(//where the timer would go){
   delay(6000);
if(millis()-Timer >= 6000UL){
if(regularvolt++){
   ++breathing[2];
  }
  if(regularvolt--){
   ++breathing[2];
  }
 }
}
  
    breathing[2] = Counter1;
    Serial.println(breathing[2]); // placeholder to see if everything is working correctly
    delay(700);
    breathing[2] = 0;

 // this is used as a buffer, because the purpose of the program is to check the breathing rate of a dog and if there is something wrong
 // it will flash a blue led, therefore this is used as a buffer to make so that if the dog's breathing spikes and then slows, it doesn't send
 // an alarm signal
 if(minbreath < Counter1 && Counter1 < maxbreath){
    Counter1 += 0; // this is pretty much just here to setup the else statement
   }
  else {
  Counter2++;
  }
  if(minutes>Counter2++){
    Counter2 = 0;
    }
    // ******so these are all the alarm signals which are as follows: when counter2 >= varcount blink Blueled
    //if the analoginput is turned on-off less than 5 times in one minute and you keep doing that for three minutes, blink blueled
    //if the analoginput is turned on-off more than 10 times in one minute and you keep doing that for three minutes, blink blueled
    //as long as you turn the potentiometer on-off more than 5 but less than  ten times, blink redled(real counterintuitive btw, note to myself)
    //make counter 2 reset if you turn the potentiometer on-off less than 5 or more than ten times for a minute, then goes back to regular range(5times-10times)
  if(Counter2 >= varcount)
    digitalWrite(blueled, HIGH);
    delay(500);
     digitalWrite(blueled, LOW);
    delay(500);   
      digitalWrite(blueled, HIGH);
    delay(500);
    digitalWrite(blueled, LOW);
    delay(500);   
      digitalWrite(blueled, HIGH);
    delay(500);
    digitalWrite(blueled, LOW);
    delay(500);
    }
    if(regularvolt > 0){
      digitaltoanalog = true;
    }
    
if(millis()-Timer >= 6000UL  && alertconditional == digitaltoanalog ){ //T
  if(millis()-Timer >= 18000UL  && alertconditional == digitaltoanalog ){ //T
  digitalWrite(blueled, HIGH);
    delay(500);
     digitalWrite(blueled, LOW);
    delay(500);   
      digitalWrite(blueled, HIGH);
    delay(500);
    digitalWrite(blueled, LOW);
    delay(500);   
 }
  
}
if(millis()-Timer >= 6000UL && alertconditional1 == digitaltoanalog){ //T
  if(millis()-Timer >= 18000UL && alertconditional1 == digitaltoanalog){ //T
 digitalWrite(blueled, HIGH);
    delay(500);
     digitalWrite(blueled, LOW);
    delay(500);   
 }
  
}
if(goodconditional == digitaltoanalog){ 
  digitalWrite(redled, HIGH);
    delay(500);
     digitalWrite(redled, LOW);
    delay(500);   
}
if(millis()-Timer >= 6000UL && alertconditional == digitaltoanalog || alertconditional1 == digitaltoanalog){ //T
if(minbreath < Counter1 && Counter1 < maxbreath){
    Counter2 = 0;
   }
  
  }
 
    
}

(attached if you don’t wanna read through on HTML)

Final_Breath_Actual.ino (2.7 KB)

int alertconditional = constrain(alertconditional, 1, 4);

Can you explain what you think this line does?

Can you explain how you think it is any different from:

int alertconditional = 1;

i originally thought this was a range from 1 to 4

No, go look up constrain. It says that if the variable is less than the second argument then make it equal the second argument and if it is greater than the last argument make it equal that. You can't have a variable that has a range.

There is SOOOOO much wrong with the code you have written. I can't even parse through it and figure out what you intended for it to do. You need to stop writing for a while and go do some tutorials or something and learn at least the basics of the language before you try to take on something this complex.

can you at least tell me how i can improve the code

No because it isn’t clear what you’re trying to do.

Actually I can improve that code. Open up the code in the IDE. Hold down the Control key and while holding down Control press A then X and then S. That would at least be a good start and then we can work from there.

TheReBreather:
timer for a Breathing program

You can try starting to explain what a "Breating program" is suppose to do...

TheReBreather:
(attached if you don't wanna read through on HTML)

No need, the HTML view is quick for obvious errors and otherwise the select link on top of the code box is all we need to get it into the editor of choice :smiley: