#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <IRremote.h>
#include <IRremoteInt.h>
#include <Servo.h>
LiquidCrystal_I2C myDisplay(0x27,16,2);
Servo myservo; // create servo object to control a servo
int pos = 0; // variable to store the servo position
long FISHFEEDER = 15000; // 12 hours between feeding
long endtime;
long now;
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
int IRCode = 0;
decode_results results;
void setup()
{
Serial.begin(9600);
// Serial.begin(0);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
irrecv.enableIRIn();
myDisplay.init(); //initialize the lcd - this sets the character canvas to 5x8 pixels and some other hardware specifics
myservo.write(0);
delay(15);
myDisplay.backlight();//this turns the backlight on
//Print a message to the LCD.
myDisplay.print(" Fish Feeder");
myDisplay.setCursor(1,8);
myDisplay.print("Every 12 Hours");
}
// Dumps out the decode_results structure.
// Call this after IRrecv::decode()
void dump(decode_results *results) {
int count = results->rawlen;
results->decode_type;
IRCode = results->value;
}
// Test send or receive.
// If mode is SENDER, send a code of the specified type, value, and bits
// If mode is RECEIVER, receive a code and verify that it is of the
// specified type, value, and bits. For success, the LED is flashed;
// for failure, the mode is set to ERROR.
// The motivation behind this method is that the sender and the receiver
// can do the same test calls, and the mode variable indicates whether
// to send or receive.
void test( int type, unsigned long value, int bits) {
irrecv.resume(); // Receive the next value
unsigned long max_time = millis() + 1000;
// Wait for decode or timeout
while (!irrecv.decode(&results)) {
if (millis() > max_time) {
IRCode = 0;
return;
}
}
dump(&results);
}
void loop()
{
{
now = millis();
endtime = now + FISHFEEDER;
while(now < endtime) {
myservo.write(0);
delay(10000);
now = millis();
}
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
// The test suite.
Serial.println(IRCode);
switch(IRCode){
break;
case 16753245: //button 1
FISHFEEDER = 14400000;
myDisplay.setCursor(1,8);
myDisplay.print("Every 4 Hours ");
break;
case -24481: //button 2
FISHFEEDER = 21600000;
myDisplay.setCursor(1,8);
myDisplay.print("Every 6 Hours ");
break;
case 24735: //button 3
FISHFEEDER = 28800000;
myDisplay.setCursor(1,8);
myDisplay.print("Every 8 Hours ");
break;
case 4335: //button 4
FISHFEEDER = 36000000;
myDisplay.setCursor(1,8);
myDisplay.print("Every 10 Hours");
break;
case -28561: //button 5
FISHFEEDER = 43200000;
myDisplay.setCursor(1,8);
myDisplay.print("Every 12 Hours");
break;
case 20655: //button 6
FISHFEEDER = 50400000;
myDisplay.setCursor(1,8);
myDisplay.print("Every 14 Hours");
break;
}}
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
servo1:GND
servo1:V+
servo1:PWM
ir1:GND
ir1:VCC
ir1:DAT
lcd1:VSS
lcd1:VDD
lcd1:V0
lcd1:RS
lcd1:RW
lcd1:E
lcd1:D0
lcd1:D1
lcd1:D2
lcd1:D3
lcd1:D4
lcd1:D5
lcd1:D6
lcd1:D7
lcd1:A
lcd1:K
r1:1
r1:2