hey there
i got small project here, for feeding pets. its working all fine, except serial commands - it giving me bad command and numbers (not sure where numbers come from)
15:26:09.632 -> bad command
15:26:09.632 -> Command: 102
15:26:10.147 -> bad command
15:26:10.147 -> Command: 101
15:26:10.658 -> bad command
15:26:10.658 -> Command: 101
15:26:11.171 -> bad command
15:26:11.171 -> Command: 110
15:26:11.685 -> bad command
15:26:11.685 -> Command: 10
here is my code. thanks.
#include <Servo.h>
#include <string.h>
#include <Wire.h>
#include <iarduino_RTC.h>
iarduino_RTC time(RTC_DS1307);
String hrs;
String mins;
String timenow;
int Data;
int angle = 112;
Servo myservo; // create servo object to control a servo
const int servoPWcontrol = 5; // the number of serwo porwe control
void setup()
{
delay(300);
Serial.begin(9600);
time.begin();
myservo.attach(9);
myservo.write(angle);
pinMode(servoPWcontrol, OUTPUT);
digitalWrite(servoPWcontrol, LOW); // Turn powersource od servo OFF
Serial.println("Type Command (feednow, gettime, RTC.setTime(yy:mm:dd:dow:hh:mm:ss)");
}
void loop()
{
timenow=time.gettime("H:i:s");
delay(500);
digitalWrite(servoPWcontrol, LOW);
if(timenow=="10:00:00")
{
digitalWrite(servoPWcontrol, HIGH);
delay(1000);
myservo.write(70);
delay(1500);
myservo.write(112);
delay(1000);
digitalWrite(servoPWcontrol, LOW);
Serial.println("They always hungry...");
}
if(Serial.available()){
Data = Serial.read();
if (Data == "feednow") {
digitalWrite(servoPWcontrol, HIGH);
delay(1000);
myservo.write(70);
delay(1500);
myservo.write(112);
delay(1000);
digitalWrite(servoPWcontrol, LOW);
Serial.println("They always hungry...");
}
else if (Data == "gettime") {
Serial.println(time.gettime("H:i:s"));
}
else {
Serial.println("bad command");
}
Serial.print("Command: ");
Serial.println(Data);
}
}