-
Notifications
You must be signed in to change notification settings - Fork 2
/
feed.ino
55 lines (44 loc) · 1008 Bytes
/
feed.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
void init_servo() {
servo.attach(SERVO_PIN);
servo.write(CLOSED_ANGLE);
}
void feed_fish_auto() {
if(!auto_enabled) return;
feed_fish();
}
void feed_fish() {
play_melody(sound1, 3);
client.loop();
for(int c = 1; c<= CYCLES_PER_FEED; c++) {
for(int i = CLOSED_ANGLE; i <= OPEN_ANGLE; i++) {
servo.write(i);
delay(3);
}
for(int i = OPEN_ANGLE; i >= CLOSED_ANGLE; i--) {
servo.write(i);
delay(3);
}
}
client.loop();
last_feed = millis();
inc_num_feeds();
delay(100);
print_status(true);
send_status(true);
play_melody(sound2, 8);
}
void set_num_feeds(int feeds) {
num_feeds = feeds;
EEPROM.update(0, num_feeds);
if(client.connected()) {
String message = F("feed_completed @ ");
message.concat(millis());
char buffer[50];
message.toCharArray(buffer, message.length()+1);
client.publish("home/feeder_beta/messages", buffer);
client.loop();
}
}
void inc_num_feeds() {
set_num_feeds(num_feeds+1);
}