hello, im making an automatic cat feeder to dispense dry food every 6 hrs. Initially when writing the program it made the sound the started the servo for 3 sec. when i tried to refine it by making it go for say 10 seconds, when it was plugged into the usb so i could use the serial output to make sure it worked. then after taking out the usb an ran from the power source the beeping just looped over and over, and i cant figure out why. is there a simple reason?
// Include the library
#include <Servo.h>
#include <Noiasca_timer.h>
// Create the servo object
Servo myservo;
const int buzzer = 7; //buzzer to arduino pin 9
LittleTimer littleTimer {3600000};
unsigned long count = 0;
// Setup section to run once
void setup() {
Serial.begin(9600);
Serial.println("\nStart");
littleTimer.start();
myservo.attach(8); // attach the servo to our servo object
pinMode(buzzer, OUTPUT); // Set buzzer - pin 9 as an output
//buzz();
servomove();
}
// Loop to keep the motor turning!
void loop() {
if (littleTimer.hasTriggered()) // if the defined time is over, the timer will execude the followin lines
{
Serial.println("timer has triggered");
(count++);
}
Serial.println(count);
if (count >= 7) {
count = 0;
}
if (count == 6) {
Serial.println( "here comes the food");
buzz();
servomove();
}
}
void servomove() {
myservo.write(40); // rotate the motor counterclockwise
delay(5000); // keep rotating for 5 seconds (5000 milliseconds) time it takes to fill a bowl
myservo.write(90); // stop the motor
}
void buzz() {
tone(buzzer, 4800); // Send 1KHz sound signal...
delay(800); // ...for 1 sec
noTone(buzzer); // Stop sound...
delay(100); // ...for 1sec
tone(buzzer, 4500);
delay(800); // ...for 1 sec
noTone(buzzer);
delay(100);
tone(buzzer, 4000); // Send 1KHz sound signal...
delay(800); // ...for 1 sec
noTone(buzzer);
}