Hi all,
I'm new to Arduino and coding but looking forward to the projects this can do.
I'm building an egg turner for an incubator and luckily found this code on the internet as part of a huge sketch for controlling all of the incubator.
I have cut and pasted only the servo part and removed everything i thought that didn't relate to that.
I have fixed some obvious errors i made but the last one is a bit tricky.
So could someone please help me out or point me in the place to find it.
My sketch will not compile and gives an error ......expected declaration before '}' token at the very last curly bracket........looking at the code i noticed just above .... // Pause for 2 seconds
delay(2000); there was another double curly which looked wrong ....so removed one and it compiled!........
Does this sound correct?
secondly the positioning numbers used don't seem to match the comments .....i thought you simply use degrees or is there another system of units???? example ..
...myservo.write(70); //put the servo at intitial position of 16 degrees
Any help would be appreciated
// Servo version of
#include <Servo.h>
#include <Wire.h>
Servo myservo; // create servo object to control a servo
// Servo version of
int pos = 0; // variable to store the servo position
int istate = 0;
int END = 0;
unsigned long previousMillis = 0;
const long interval = 3600000UL; //timer for roll eggs 1HOUR
void setup()
{
Serial.begin(9600);
myservo.attach(9); // servo control is set to pin 9 (usually yellow wire is control, black goes to ground red goes to +5V)
myservo.write(70); //put the servo at intitial position of 16 degrees
myservo.detach();
}
void loop() {
// this section is to roll the eggs
unsigned long currentMillis = millis();
int tleft = ((currentMillis - previousMillis)/ 1000) /60;
if (currentMillis - previousMillis >= interval)
{
previousMillis = currentMillis;
if(istate == 0 && END == 0){
//myservo.attach(9);
for (pos = 80; pos <= 155; pos += 1) { // goes from 16 degrees to 80 degrees in steps of 1 degree
myservo.attach(9);
myservo.write(pos);
istate=1;
delay(50);
}
myservo.detach();
}
else if( istate == 1 && END == 0)
{
// myservo.attach(9);
for (pos = 155 ; pos >=80; pos -= 1) { // goes from 80 degrees to 0 degrees
myservo.attach(9);
myservo.write(pos);
istate = 0;
delay(50); // slow the servo down a bit to turn the eggs
}
myservo.detach();
}
}
// Pause for 2 seconds
delay(2000);
}
}