programming

TIME-ALARM

#include <Servo.h> // servo lib rary
#include <Time.h> // time library
#include <TimeAlarms.h> // allarm library

int i = 0; // make a vraiable for position of degrees
Servo servomotor, servomotortwo;//Make the two servo motors an object
void setup()
{
Serial.begin(9600); // set the serial monitor
setTime(11,15,60,4,7,11); // the time is set to 11:15:60am Apr 7 2011
Alarm.alarmRepeat(11,16,30, FernandoAlarm); // 11:16:30am alarm
Alarm.alarmRepeat(11,16,32, FernandoAlarmCon); // 11:16:35am alarm
Alarm.alarmRepeat(11,17,0,JoseAlarm); // 11:17:00am alarm
Alarm.alarmRepeat(11,17,02,JoseAlarmCon); // 11:17:05am alarm
servomotor.attach(11); // set the servo motor to pin 11
servomotortwo.attach(12); // set the servo motor to pin 12

}

void FernandoAlarm(){
for (i=0;i<180;i=180){ // move the servo motor from 0 to 180 degrees
servomotor.write(i); // wrtie the degrees to the serv motor
delay(15);// determines the speed of the servo
Serial.println(“Turn Motor ON to the Rigth”);
}}
void FernandoAlarmCon(){
for (i=180;i>0;i=0){ // move the servo motor from 180 to 0 degrees
servomotor.write(i); // wrtie the degrees to the servo motor
delay(15); // determines the speed of the servo
Serial.println(“Turn Motor ON to the left”);
}
}

void JoseAlarm()
{
for (i=0;i<180;i=180){ // move the servo motor from 0 to 180 degrees
servomotortwo.write(i); // wrtie the degrees to the serv motor
delay(15); // determines the speed of the servo
Serial.println(“Turn Motor 2 ON to the rigth”);
}}
void JoseAlarmCon(){
for (i=180;i>0;i=0){ // move the servo motor from 180 to 0 degrees
servomotortwo.write(i); // wrtie the degrees to the serv motor
delay(15); // determines the speed of the servo
Serial.println(“Turn Motor 2 ON to the left”);
}}

void loop()
{
digitalClockDisplay();
Alarm.delay(1000); // wait one second between clock display
}

void digitalClockDisplay()
{
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.println();
}

void printDigits(int digits)
{
// utility function for digital clock display: prints preceding colon and leading 0
Serial.print(":");
if(digits < 10)
Serial.print(‘0’);
Serial.print(digits);
}

Why is this a poll?

Did you have a question? There are plenty of comments in the code.

Please modify your post, select the code and press the # button, code will look better. Furthermore in the IDE you can press CTRL-T to re-indent your code. That makes it look better even more.

Use a consequent style for your comments; I prefer comments before a block of code, as this looks better imho, and must be skipped consiously. Comments after a line of code can be skipped unconsiously so chances of missing them is greater. Keep comments to thepoint and don't explain the obvious like:

x = x + 1;  // increment x by one

as this devaluates the value of the comments ==> people will skip it and will eventuallyt skip important comments.

I am very new in programming and would like some to break down this code for me with comments on the side

OK, go ahead, you have my permission ;)

But what is the question you want to ask?

If you are new to programming, try to make functions first; a function does one thing, and ideally, it does that very well ;)

loop() will mainly consist of calls to your functions. A generic pattern often seen in the loop is the following:

void loop()
{
  // MAKE MEASUREMENTS
  ...
  // MAKE CALCULATIONS
  ...
  // PRESENT THEM
  ...
}

There is a major logical error in your code! In setup() you set the alarms before initializing the servo's. If the alarms go off and address the servo's these are not initialized correctly resulting in strange behavior. That becomes a hard to find bug. So you need to think very well what order of initialization is robust.

Finally consider a higher baudrate for Serial, Serial.begin(115200) uses 12 times less time than 9600. No Error sec , just efficiency.

Succes, Rob