Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int motoPin = 1; // motoPin goes to a relay to power a 12v waterpump
- int fivPin = 2;
- int tenPin = 3; // input pins assigned pins and variables
- int fiftnPin = 4;
- int usrInput(); //initilize funtion
- int n = 0; //declare N globally so It doesnt reset at top of the loop
- void setup()
- {
- int j = 0;
- pinMode(motoPin, OUTPUT);
- pinMode(fivPin, INPUT);
- pinMode(tenPin, INPUT);
- pinMode(fiftnPin, INPUT);
- for (j = 0; j < 3; j++) //j is declared and used to iterate loop 3 times to signel boot and operational
- {
- digitalWrite(motoPin, HIGH);
- delay(500);
- digitalWrite(motoPin, LOW);
- delay(500);
- }
- delay(2000);
- }
- void loop()
- {
- long i = 0; //set n defualt value to 0 so it runs until a usrInput() is set
- digitalWrite(motoPin, HIGH);
- 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
- {
- delay(1);
- if (usrInput() > 0)
- {
- n = usrInput();
- }
- }
- digitalWrite(motoPin, LOW);
- for (long i = 0; i < (n*60*1000); i++) //turn off and wait for n minutes before running again THIS IS THE WAIT PORTION
- {
- delay(1);
- if (usrInput() > 0)
- {
- n = usrInput();
- }
- }
- }
- int usrInput() // this accepts user input as grounding out of pins on the IC
- {
- 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
- {
- return 5;
- }
- if (digitalRead(tenPin) == LOW)
- {
- return 10; // return value to the function call
- }
- if (digitalRead(fiftnPin) == LOW)
- {
- return 15;
- }
- else
- {
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement