Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@0:0d5e0666c53b, 2018-06-24 (annotated)
- Committer:
- acracan
- Date:
- Sun Jun 24 12:11:32 2018 +0000
- Revision:
- 0:0d5e0666c53b
Small demo of the Helios class
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| acracan | 0:0d5e0666c53b | 1 | #include "mbed.h" |
| acracan | 0:0d5e0666c53b | 2 | #include "Helios.h" |
| acracan | 0:0d5e0666c53b | 3 | |
| acracan | 0:0d5e0666c53b | 4 | /*------------------------------------------------------------------------------ |
| acracan | 0:0d5e0666c53b | 5 | Before to use this example, ensure that you an hyperterminal installed on your |
| acracan | 0:0d5e0666c53b | 6 | computer. More info here: https://developer.mbed.org/handbook/Terminals |
| acracan | 0:0d5e0666c53b | 7 | |
| acracan | 0:0d5e0666c53b | 8 | The default serial comm port uses the SERIAL_TX and SERIAL_RX pins (see their |
| acracan | 0:0d5e0666c53b | 9 | definition in the PinNames.h file). |
| acracan | 0:0d5e0666c53b | 10 | |
| acracan | 0:0d5e0666c53b | 11 | The default serial configuration in this case is 9600 bauds, 8-bit data, no parity |
| acracan | 0:0d5e0666c53b | 12 | |
| acracan | 0:0d5e0666c53b | 13 | If you want to change the baudrate for example, you have to redeclare the |
| acracan | 0:0d5e0666c53b | 14 | serial object in your code: |
| acracan | 0:0d5e0666c53b | 15 | |
| acracan | 0:0d5e0666c53b | 16 | Serial pc(SERIAL_TX, SERIAL_RX); |
| acracan | 0:0d5e0666c53b | 17 | |
| acracan | 0:0d5e0666c53b | 18 | Then, you can modify the baudrate and print like this: |
| acracan | 0:0d5e0666c53b | 19 | |
| acracan | 0:0d5e0666c53b | 20 | pc.baud(115200); |
| acracan | 0:0d5e0666c53b | 21 | pc.printf("Hello World !\n"); |
| acracan | 0:0d5e0666c53b | 22 | ------------------------------------------------------------------------------*/ |
| acracan | 0:0d5e0666c53b | 23 | |
| acracan | 0:0d5e0666c53b | 24 | DigitalOut led(LED1); |
| acracan | 0:0d5e0666c53b | 25 | Helios sun; |
| acracan | 0:0d5e0666c53b | 26 | |
| acracan | 0:0d5e0666c53b | 27 | int main() |
| acracan | 0:0d5e0666c53b | 28 | { |
| acracan | 0:0d5e0666c53b | 29 | time_t seconds; |
| acracan | 0:0d5e0666c53b | 30 | char buffer[32]; |
| acracan | 0:0d5e0666c53b | 31 | |
| acracan | 0:0d5e0666c53b | 32 | printf("Hello World !\n"); |
| acracan | 0:0d5e0666c53b | 33 | set_time(1529836800); |
| acracan | 0:0d5e0666c53b | 34 | while(1) { |
| acracan | 0:0d5e0666c53b | 35 | wait(1); // 1 second |
| acracan | 0:0d5e0666c53b | 36 | led = !led; // Toggle LED |
| acracan | 0:0d5e0666c53b | 37 | seconds = time(NULL); |
| acracan | 0:0d5e0666c53b | 38 | sun.updatePosition(); |
| acracan | 0:0d5e0666c53b | 39 | strftime(buffer, 32, "%H:%M:%S", localtime(&seconds)); |
| acracan | 0:0d5e0666c53b | 40 | printf("UTC time is: %s\n", buffer); |
| acracan | 0:0d5e0666c53b | 41 | printf("Sun azimuth: %.2f, elevation: %.2f\n", sun.azimuth(), sun.elevation()); |
| acracan | 0:0d5e0666c53b | 42 | } |
| acracan | 0:0d5e0666c53b | 43 | } |