Skip to content

Instantly share code, notes, and snippets.

@izzuddin91
Created March 29, 2016 08:06
Show Gist options
  • Select an option

  • Save izzuddin91/33e2a6441cb7b3fd4b01 to your computer and use it in GitHub Desktop.

Select an option

Save izzuddin91/33e2a6441cb7b3fd4b01 to your computer and use it in GitHub Desktop.
#include <Process.h>
#include <Console.h>
#include <Servo.h>
Process date;
int hours, minutes, seconds;
int lastSecond = -1;
Servo myservo;
int pos = 0;
void setup() {
Bridge.begin();
Console.begin();
myservo.attach(9);
while(!Console);
Console.println("Time Check");
if (!date.running()) {
date.begin("date");
date.addParameter("+%T");
date.run();
}
}
void loop() {
if(lastSecond != seconds) { // if a second has passed
if (hours <= 9) Console.print("0"); // adjust for 0-9
Console.print(hours);
Console.print(":");
if (minutes <= 9) Console.print("0"); // adjust for 0-9
Console.print(minutes);
Console.print(":");
if (seconds <= 9) Console.print("0"); // adjust for 0-9
Console.println(seconds);
if (!date.running()) {
date.begin("date");
date.addParameter("+%T");
date.run();
}
}
while (date.available()>0) {
String timeString = date.readString();
int firstColon = timeString.indexOf(":");
int secondColon= timeString.lastIndexOf(":");
String hourString = timeString.substring(0, firstColon);
String minString = timeString.substring(firstColon+1, secondColon);
String secString = timeString.substring(secondColon+1);
hours = hourString.toInt();
minutes = minString.toInt();
lastSecond = seconds;
seconds = secString.toInt();
}
for (pos = 0; pos <= 360; 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 = 360; pos >= 0; 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
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment