Advertisement
Guest User

Untitled

a guest
Jun 20th, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int motoPin = 1;    // motoPin goes to a relay to power a 12v waterpump
  2. int fivPin = 2;
  3. int tenPin = 3;        // input pins assigned pins and variables
  4. int fiftnPin = 4;
  5.  
  6. int usrInput(); //initilize funtion
  7. int n = 0;  //declare N globally so It doesnt reset at top of the loop
  8.  
  9. void setup()      
  10. {
  11.   int j = 0;        
  12.   pinMode(motoPin, OUTPUT);
  13.   pinMode(fivPin, INPUT);
  14.   pinMode(tenPin, INPUT);
  15.   pinMode(fiftnPin, INPUT);
  16.   for (j = 0; j < 3; j++)    //j is declared and used to iterate loop 3 times to signel boot and operational
  17.   {
  18.     digitalWrite(motoPin, HIGH);    
  19.     delay(500);
  20.     digitalWrite(motoPin, LOW);
  21.     delay(500);
  22.   }
  23.   delay(2000);
  24. }
  25. void loop()
  26. {
  27.   long i = 0;    //set n defualt value to 0 so it runs until a usrInput() is set
  28.    digitalWrite(motoPin, HIGH);
  29.     for (long i = 0; i < (30*1000); i++)   // for 30 seconds run pump and look for input from usrInput function THIS IS THE RUN PORTION
  30.     {
  31.       delay(1);
  32.       if (usrInput() > 0)
  33.       {
  34.         n = usrInput();
  35.       }
  36.     }
  37.    digitalWrite(motoPin, LOW);
  38.     for (long i = 0; i < (n*60*1000); i++)  //turn off and wait for n minutes before running again THIS IS THE WAIT PORTION
  39.     {
  40.       delay(1);
  41.       if (usrInput() > 0)
  42.       {
  43.         n = usrInput();
  44.       }
  45.     }
  46. }
  47.  
  48. int usrInput()   // this accepts user input as grounding out of pins on the IC
  49. {
  50.  if (digitalRead(fivPin) == LOW)      //if the five minute (or any input pin) delay pin is grounded during this funtion, set the value of t to 5 (or other according value) and iterate the wait loop for that long in minutes
  51.   {
  52.     return 5;
  53.   }
  54.   if (digitalRead(tenPin) == LOW)
  55.   {
  56.     return 10;    // return value to the function call
  57.   }
  58.   if (digitalRead(fiftnPin) == LOW)
  59.   {
  60.     return 15;
  61.   }
  62.   else
  63.   {
  64.     return 0;
  65.   }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement