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.
Dependencies: mbed
main.cpp@1:24717a795dc0, 2017-12-23 (annotated)
- Committer:
- osmith2
- Date:
- Sat Dec 23 15:57:31 2017 +0000
- Revision:
- 1:24717a795dc0
- Parent:
- 0:7c0bfc9d2e16
testing http://www.cplusplus.com/reference/cstdio/sprintf/; different variations of the code
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| osmith2 | 0:7c0bfc9d2e16 | 1 | #include "mbed.h" |
| osmith2 | 0:7c0bfc9d2e16 | 2 | |
| osmith2 | 0:7c0bfc9d2e16 | 3 | |
| osmith2 | 0:7c0bfc9d2e16 | 4 | |
| osmith2 | 0:7c0bfc9d2e16 | 5 | |
| osmith2 | 0:7c0bfc9d2e16 | 6 | |
| osmith2 | 0:7c0bfc9d2e16 | 7 | Serial pc(USBTX, USBRX); |
| osmith2 | 0:7c0bfc9d2e16 | 8 | |
| osmith2 | 0:7c0bfc9d2e16 | 9 | |
| osmith2 | 0:7c0bfc9d2e16 | 10 | |
| osmith2 | 0:7c0bfc9d2e16 | 11 | int year = 2017; |
| osmith2 | 0:7c0bfc9d2e16 | 12 | char month = 12; |
| osmith2 | 0:7c0bfc9d2e16 | 13 | char day = 25; |
| osmith2 | 0:7c0bfc9d2e16 | 14 | char hour = 23; |
| osmith2 | 0:7c0bfc9d2e16 | 15 | char minute = 28; |
| osmith2 | 0:7c0bfc9d2e16 | 16 | |
| osmith2 | 0:7c0bfc9d2e16 | 17 | DigitalOut myled(LED1); |
| osmith2 | 0:7c0bfc9d2e16 | 18 | |
| osmith2 | 0:7c0bfc9d2e16 | 19 | int main() { |
| osmith2 | 0:7c0bfc9d2e16 | 20 | while(1) { |
| osmith2 | 0:7c0bfc9d2e16 | 21 | myled = 1; // LED is ON |
| osmith2 | 0:7c0bfc9d2e16 | 22 | wait(0.2); // 200 ms |
| osmith2 | 0:7c0bfc9d2e16 | 23 | myled = 0; // LED is OFF |
| osmith2 | 0:7c0bfc9d2e16 | 24 | wait(1.0); // 1 sec |
| osmith2 | 0:7c0bfc9d2e16 | 25 | |
| osmith2 | 0:7c0bfc9d2e16 | 26 | //date |
| osmith2 | 0:7c0bfc9d2e16 | 27 | pc.printf("Year: %d\n", year); |
| osmith2 | 0:7c0bfc9d2e16 | 28 | pc.printf("Month: %d\n", month); |
| osmith2 | 0:7c0bfc9d2e16 | 29 | pc.printf("Day: %d\n", day); |
| osmith2 | 0:7c0bfc9d2e16 | 30 | //time |
| osmith2 | 0:7c0bfc9d2e16 | 31 | pc.printf("Hour: %d\n", hour); |
| osmith2 | 0:7c0bfc9d2e16 | 32 | pc.printf("Minute: %d\n", minute); |
| osmith2 | 0:7c0bfc9d2e16 | 33 | |
| osmith2 | 0:7c0bfc9d2e16 | 34 | |
| osmith2 | 0:7c0bfc9d2e16 | 35 | // SOOooooo, am I retarded or can we not just do this? |
| osmith2 | 0:7c0bfc9d2e16 | 36 | pc.printf("Date and time: %d.%d.%d.%d.%d \n", year, month, day, hour, minute); |
| osmith2 | 1:24717a795dc0 | 37 | pc.printf("Merry christmas!\n"); |
| osmith2 | 1:24717a795dc0 | 38 | |
| osmith2 | 1:24717a795dc0 | 39 | |
| osmith2 | 1:24717a795dc0 | 40 | |
| osmith2 | 1:24717a795dc0 | 41 | char buffer [50]; |
| osmith2 | 1:24717a795dc0 | 42 | int n; |
| osmith2 | 1:24717a795dc0 | 43 | //a=5, b=3; |
| osmith2 | 1:24717a795dc0 | 44 | n=sprintf (buffer, "%d.%d.%d¦%d:%d", year, month, day, hour, minute); |
| osmith2 | 1:24717a795dc0 | 45 | pc.printf ("[%s] is a string %d chars long\n",buffer,n); |
| osmith2 | 1:24717a795dc0 | 46 | return 0; |
| osmith2 | 1:24717a795dc0 | 47 | |
| osmith2 | 1:24717a795dc0 | 48 | |
| osmith2 | 1:24717a795dc0 | 49 | /* |
| osmith2 | 1:24717a795dc0 | 50 | char rtard [50]; |
| osmith2 | 1:24717a795dc0 | 51 | int m, c=5, d=3; |
| osmith2 | 1:24717a795dc0 | 52 | m=sprintf (rtard, "Duo %d plus %d is %d", c, d, c+d); |
| osmith2 | 1:24717a795dc0 | 53 | pc.printf ("[%s] is a string %d chars long\n",rtard,n); |
| osmith2 | 1:24717a795dc0 | 54 | return 0; |
| osmith2 | 1:24717a795dc0 | 55 | */ |
| osmith2 | 1:24717a795dc0 | 56 | |
| osmith2 | 1:24717a795dc0 | 57 | /* |
| osmith2 | 1:24717a795dc0 | 58 | char datboi [100]; |
| osmith2 | 1:24717a795dc0 | 59 | int o; |
| osmith2 | 1:24717a795dc0 | 60 | o = sprintf (datboi, "Date and Time: %d.%d \n", year, month); |
| osmith2 | 1:24717a795dc0 | 61 | pc.printf ("[%s] is a string chars long\n",datboi, n); |
| osmith2 | 1:24717a795dc0 | 62 | return 0; |
| osmith2 | 1:24717a795dc0 | 63 | */ |
| osmith2 | 1:24717a795dc0 | 64 | |
| osmith2 | 0:7c0bfc9d2e16 | 65 | } |
| osmith2 | 0:7c0bfc9d2e16 | 66 | } |