Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
6 years, 3 months ago.
Clock timer
Hello guys,
I will make My outdoor lights Switch automatic at a spezific time.
I Need for this a Hello world Code.
My idea:
Its 8 o‘clock pm— — Pin 13 high —— It‘s 11 o‘clock pm —— Pin 13 low
Had anyone an idea for me as a beginner?
Thanks for your help
1 Answer
6 years, 3 months ago.
hi Sasha, and welcome...
Some things that come to mind - (and what to search for to get details and examples). I've quoted apis of which many are standardized, so you could search for these on the mbed site.
- Set the time
- search for "set_time"
- "ntp client" - if you have an Ethernet interface connected.
- there are similar client's if you have a WiFi interface.
- Read the time
- "localtime", "gmtime"- gets the current time into a data structure, one member of which is "tm_hour"
- Check the time of day for 8pm and 11pm
- compare the "tm_hour", and optionally the "tm_min" values to your target times.
- look at the other members of the "tm" structure, which may give you other ideas for enhanced features.
- consider what happens if your device reboots at 9pm. Should it turn on, or do nothing?
- Control the output pin
- Search for "DigitalOut"
I've wrapped up a few of these components together into a "TimeInterface" library. I've only tested it on the LPC1768., but it may help you on your way. [I have not run these on OS5, so I don't know if they will build in that environment.]
-
As a totally different way to answer your question - I have some WiFi controlled switches, and the mbed is on the same network. It can read the WiFi switch to see if it is on or off and it can send commands to the switches to set them on/off.