0
Offline
Newbie
Karma: 0
Posts: 19
Arduino rocks
|
 |
« on: April 06, 2009, 01:09:18 pm » |
Is it possible to set the arduino time clock? If yes, how can you allow the user to enter the time so it can be set? Pls help!!!
|
|
|
|
|
Logged
|
|
|
|
|
London
Offline
Faraday Member
Karma: 6
Posts: 6226
Have fun!
|
 |
« Reply #1 on: April 06, 2009, 01:41:06 pm » |
There is a library here that provides time functions on Arduino: http://www.arduino.cc/playground/Code/DateTime Also included is a Processing sketch to set the time from a PC or Mac. What is it you want to do?
|
|
|
|
« Last Edit: April 06, 2009, 01:49:59 pm by mem »
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 19
Arduino rocks
|
 |
« Reply #2 on: April 06, 2009, 01:50:27 pm » |
I wanna design a GUI that allows the user to set a time when an LED should light up without changing the actual time (think of it as an alarm clock). For example, say at 4:00 pm. How would you do that?
|
|
|
|
« Last Edit: April 06, 2009, 01:51:52 pm by bugzy4real »
|
Logged
|
|
|
|
|
London
Offline
Faraday Member
Karma: 6
Posts: 6226
Have fun!
|
 |
« Reply #3 on: April 06, 2009, 02:10:32 pm » |
You need to say more about what you would like to do.
What kind of gui would you like to have?
Would you like the gui on a display device connected to Arduino or running on application running on a computer connected to the serial port? (or whichever is easer to impliment?)
|
|
|
|
« Last Edit: April 06, 2009, 02:12:28 pm by mem »
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 19
Arduino rocks
|
 |
« Reply #4 on: April 07, 2009, 11:11:46 am » |
I'd like to use processing to develop the GUI. The GUI should take input maybe as a text field that allows the user to enter time in integer form and that input should be used to determine when the LED should light up
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Sr. Member
Karma: 0
Posts: 354
Arduino rocks
|
 |
« Reply #5 on: April 07, 2009, 11:31:39 am » |
Is you arduino going to always be connected to the computer? Or are you just using the computer to program the Arduino, and then unplugging the Arduino and leaving it running as a stand alone, through a wallwart or battery?
If you are going to leave it connected to the computer, this is fairly easy. Your computer can do the counting and when the alarm is hit it can send a message over serial to the arduino, the arduino can then parse this message and set the LED accordingly.
If you are going to be unpluggin the arduino it gets a little complicated. I would use an external timing IC and battery back it up. I would use one that has some sort of memory like the DS1307
|
|
|
|
|
Logged
|
|
|
|
|
London
Offline
Faraday Member
Karma: 6
Posts: 6226
Have fun!
|
 |
« Reply #6 on: April 07, 2009, 11:54:12 am » |
If you are going to be unpluggin the arduino it gets a little complicated. not if the Arduino is battery operated or remains powered when disconnected from the seial port. I'd like to use processing to develop the GUI. The GUI should take input maybe as a text field that allows the user to enter time in integer form and that input should be used to determine when the LED should light up There is a processing application supplied with the download that sets the clock. You can add functionality to that Processing sketch to get an alarm time. The DateTime library has a function to return the number of seconds that have elapsed since that start of the day. So to light an led at 8:30 in the morning for one hour you would do something like this: time_t alarmOnTime = (8 * SECS_PER_HOUR) + (30 * SECS_PER_MIN); time_t alarmOffTime = alarmOnTime + (60 * SECS_PER_MIN); time_t nextAlarm;
nextAlarm = previousMidnight(DateTime.now())+ alarmOnTime;
if( DateTime.now() >= nextAlarm && DateTime.now() < nextAlarm + alarmOffTime ) digitalWrite(ledPin), HIGH); else digitalWrite(ledPin), LOW);
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 19
Arduino rocks
|
 |
« Reply #7 on: April 07, 2009, 01:37:03 pm » |
mem: Thanks a lot! your code worked to perfection! darudude: thanks for your suggestion too!
But guys, how can i create a text box or anything at all to allow the user input the time the LED should light up
|
|
|
|
« Last Edit: April 07, 2009, 02:01:29 pm by bugzy4real »
|
Logged
|
|
|
|
|
Norway@Oslo
Offline
Edison Member
Karma: 11
Posts: 2033
loveArduino(true);
|
 |
« Reply #8 on: April 07, 2009, 02:08:17 pm » |
Buy a LCD, or a led display. You could write a program that runs on your computer, querying the user, and sending the data over serial. Interfacing With Software
|
|
|
|
|
Logged
|
|
|
|
|
London
Offline
Faraday Member
Karma: 6
Posts: 6226
Have fun!
|
 |
« Reply #9 on: April 07, 2009, 02:09:13 pm » |
But guys, how can i create a text box or anything at all to allow the user input the time the LED should light up can you clarify your question? are you asking how to add it to the setArduinoClock Processing sketch? can you say more about your level of programming skill?
|
|
|
|
« Last Edit: April 07, 2009, 02:12:41 pm by mem »
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 19
Arduino rocks
|
 |
« Reply #10 on: April 08, 2009, 05:36:22 pm » |
All i'm saying is i wanna create a GUI or something interactive where the user can actually enter the time he wants the LED to light up. So that, the user would be able to determine the values (8,30) in the example you gave me below:
time_t alarmOnTime = (8 * SECS_PER_HOUR) + (30 * SECS_PER_MIN); time_t alarmOffTime = alarmOnTime + (60 * SECS_PER_MIN);
P.S: I'm new to Arduino. i could have done this GUI easily in C#
|
|
|
|
« Last Edit: April 08, 2009, 05:37:15 pm by bugzy4real »
|
Logged
|
|
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 19
Arduino rocks
|
 |
« Reply #12 on: April 09, 2009, 09:49:06 am » |
Interfacing with C# is good but i'd rather not mix C# with arduino+processing except i have no other choice
|
|
|
|
|
Logged
|
|
|
|
|
London
Offline
Faraday Member
Karma: 6
Posts: 6226
Have fun!
|
 |
« Reply #13 on: April 09, 2009, 10:14:56 am » |
If you are more comfortable with C# than Processing, there is no reason not to use it.
It should be quite easy to replace the Processing code to set the time with a C# app. it just gets the current time, converts that into the number if seconds since jan 1 1970, and sends that as as string of digits preceeded by some unique header (255 in the published version).
Write whatever gui you want in whatever language your prefer. you just need to send your alarm time as a string with some identifying header byte followed by a string of digits indicating the time_t for the alarm you want. Have a look at the Arduino example source to see how it handles this string and add you code that identifies and uses the alarm on and off times.
I hope that helps
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 175
---
|
 |
« Reply #14 on: April 09, 2009, 08:23:53 pm » |
Interfacing with C# is good but i'd rather not mix C# with arduino+processing except i have no other choice Why not? Let the micro controller do what it does best, and let it interface with your pc for everything else. This usually results in an efficient implementation.
|
|
|
|
|
Logged
|
|
|
|
|
|