Pump Timer

I uploaded a pump controller code by Nick Gammon, but this doesn’t work for me. I suspect I don’t have the library as I have searched and looked up libraries/ and can only see Bounce in there.
Do I need to upload “avr/sleep.h” and put that in "Arduino/libraries?
Also I changed the last command (if that’s what you call it) from “pumpTime *= 60000UL; // convert minutes to milliseconds” to “pumpTime *= 5000UL;” which I think is going to allow the timer to run for 5 seconds for testing.
Are pins 3 to 11 held HIGH or LOW or allowed to float, when not selected?
Any help greatly appreciated.

// Pump timer
// Author: Nick Gammon
// Date: 7th January 2012
// Released into the public domain.

#include <avr/sleep.h>

const int pumpPin = 13; // output pin for the pump and solenoid (goes to the relay)
const int buttonPin = 2; // input pin (for a pushbutton switch)
const int firstSwitch = 3; // first switch pin for time rotary button
const int lastSwitch = 11; // last switch pin
const int debounceTime = 20; // debounce in milliseconds
const unsigned long delayTime = { 2, 5, 10, 15, 20, 30, 45, 46, 120}; // Pump run times in minutes
unsigned long startPumpTime = 0; // when pump started
unsigned long pumpTime; // how long to run pump
volatile boolean buttonPressed; // set when button pressed

// interrupt service routine in sleep mode
void wake ()
{
sleep_disable (); // first thing after waking from sleep:
} // end of wake

// interrupt service routine when awake and button pressed
void buttonDown ()
{
buttonPressed = true;
} // end of buttonDown

void sleepNow ()
{
set_sleep_mode (SLEEP_MODE_PWR_DOWN);
sleep_enable (); // enables the sleep bit in the mcucr register
attachInterrupt (0, wake, LOW);
sleep_mode (); // here the device is actually put to sleep!!
detachInterrupt (0); // stop LOW interrupt
} // end of sleepNow

void deBounce ()
{
unsigned long now = millis ();
do
{
// on bounce, reset time-out
if (digitalRead (buttonPin) == LOW)
now = millis ();
}
while (digitalRead (buttonPin) == LOW ||
(millis () - now) <= debounceTime);

} // end of deBounce

void setup()
{
pinMode(pumpPin, OUTPUT);
digitalWrite (buttonPin, HIGH); // pull-up on button
for (int i = firstSwitch; i <= lastSwitch; i++)
digitalWrite (i, HIGH); // pull-up on switch
} // end of setup

void loop ()
{

// if pump is running, see if time to turn it off
if (digitalRead (pumpPin) == HIGH)
{
if ((millis () - startPumpTime) >= pumpTime || buttonPressed)
{
digitalWrite (pumpPin, LOW);
deBounce ();
buttonPressed = false;
}
return; // not time to sleep yet
} // end of pump running

// ------ here if pump not running -----

// pump not running? sleep then
sleepNow ();

// pump is not running and we woke up, work out how long to run it

deBounce ();
pumpTime = 0;

EIFR = 1; // cancel any existing falling interrupt (interrupt 0)
attachInterrupt (0, buttonDown, FALLING); // ready for button press

for (int i = firstSwitch; i <= lastSwitch; i++)
if (digitalRead (i) == LOW)
pumpTime = delayTime [i - firstSwitch];

if (pumpTime == 0)
return; // no time selected

// start pump
startPumpTime = millis ();
digitalWrite (pumpPin, HIGH);

pumpTime *= 6000UL; // convert minutes to milliseconds

// pumpTime = 5000; // FOR TESTING - 5 seconds

} // end of loop

You need to put the code inside code tags. The post edit window # button above the smileys makes code tags.

Nick uses this deBounce function?
Do I read this right or does it not block execution until the button is pressed?

void deBounce ()
{
  unsigned long now = millis ();
  do
  {
    // on bounce, reset time-out
    if (digitalRead (buttonPin) == LOW)
      now = millis ();
  }
  while (digitalRead (buttonPin) == LOW ||
    (millis () - now) <= debounceTime);

}  // end of deBounce

Thanks I couldn't figure out how to add the code as everyone else does.

If the pump is supposed to fill something then why not have a fill sensor trigger a relay to run the pump?

I was just trying to get it working so I could learn how Nick had the different setting working. Pumps are often used for swimming pool filters or pool solar heaters, so they don't fill as such, they circulate.

sleep.h is one of the standard AVR GCC libraries that you already have.
http://www.nongnu.org/avr-libc/user-manual/modules.html

I just don't understand how debounce is supposed to act there if the button is not pushed.
It looks like it will stay and wait for a push which looks to me like it blocks the sleep until pushed.

Anyone? Do I have that wrong? This is Nick's code and I expect it's been thoroughly checked.

GoForSmoke:
Anyone? Do I have that wrong? This is Nick's code and I expect it's been thoroughly checked.

I think the idea is that the button triggers an interrupt which wakes the processor, so when this function is called we know the button is pressed or has been pressed recently. What it does is wait for the button to be released and have remained released for the debounce duration.

Oh, I see! The button pin is a pullup input!
DOH!