A sunrise alarm clock controlled through serial designed to run on a LPC 1768 and is currently being modified to run on a Nucleo board
main.cpp@0:ea21a4715fed, 2015-08-05 (annotated)
- Committer:
- propellerhead
- Date:
- Wed Aug 05 13:24:21 2015 +0000
- Revision:
- 0:ea21a4715fed
- Child:
- 1:dcd847fa6def
PWM works, output from the RTC
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
propellerhead | 0:ea21a4715fed | 1 | #include "mbed.h" |
propellerhead | 0:ea21a4715fed | 2 | |
propellerhead | 0:ea21a4715fed | 3 | PwmOut reds(p21); |
propellerhead | 0:ea21a4715fed | 4 | PwmOut greens(p22); |
propellerhead | 0:ea21a4715fed | 5 | PwmOut yellows(p23); |
propellerhead | 0:ea21a4715fed | 6 | PwmOut blues(p24); |
propellerhead | 0:ea21a4715fed | 7 | |
propellerhead | 0:ea21a4715fed | 8 | Serial pc(USBTX, USBRX); |
propellerhead | 0:ea21a4715fed | 9 | |
propellerhead | 0:ea21a4715fed | 10 | void Rx_interrupt(void); |
propellerhead | 0:ea21a4715fed | 11 | |
propellerhead | 0:ea21a4715fed | 12 | int main(){ |
propellerhead | 0:ea21a4715fed | 13 | pc.baud(9600); |
propellerhead | 0:ea21a4715fed | 14 | reds.period_ms(1); |
propellerhead | 0:ea21a4715fed | 15 | greens.period_ms(1); |
propellerhead | 0:ea21a4715fed | 16 | yellows.period_ms(1); |
propellerhead | 0:ea21a4715fed | 17 | blues.period_ms(1); |
propellerhead | 0:ea21a4715fed | 18 | |
propellerhead | 0:ea21a4715fed | 19 | reds.pulsewidth_us(500); |
propellerhead | 0:ea21a4715fed | 20 | greens.pulsewidth_us(500); |
propellerhead | 0:ea21a4715fed | 21 | yellows.pulsewidth_us(500); |
propellerhead | 0:ea21a4715fed | 22 | blues.pulsewidth_us(500); |
propellerhead | 0:ea21a4715fed | 23 | |
propellerhead | 0:ea21a4715fed | 24 | pc.attach(&Rx_interrupt, Serial::RxIrq); |
propellerhead | 0:ea21a4715fed | 25 | |
propellerhead | 0:ea21a4715fed | 26 | set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37 |
propellerhead | 0:ea21a4715fed | 27 | |
propellerhead | 0:ea21a4715fed | 28 | while(1) { |
propellerhead | 0:ea21a4715fed | 29 | time_t seconds = time(NULL); |
propellerhead | 0:ea21a4715fed | 30 | seconds. |
propellerhead | 0:ea21a4715fed | 31 | |
propellerhead | 0:ea21a4715fed | 32 | printf("Time as seconds since January 1, 1970 = %d\r\n", seconds); |
propellerhead | 0:ea21a4715fed | 33 | |
propellerhead | 0:ea21a4715fed | 34 | printf("Time as a basic string = %s\r\n", ctime(&seconds)); |
propellerhead | 0:ea21a4715fed | 35 | |
propellerhead | 0:ea21a4715fed | 36 | char buffer[32]; |
propellerhead | 0:ea21a4715fed | 37 | strftime(buffer, 32, "%I:%M %p\r\n", localtime(&seconds)); |
propellerhead | 0:ea21a4715fed | 38 | printf("Time as a custom formatted string = %s\r\n", buffer); |
propellerhead | 0:ea21a4715fed | 39 | |
propellerhead | 0:ea21a4715fed | 40 | wait(1); |
propellerhead | 0:ea21a4715fed | 41 | } |
propellerhead | 0:ea21a4715fed | 42 | |
propellerhead | 0:ea21a4715fed | 43 | return 0; |
propellerhead | 0:ea21a4715fed | 44 | } |
propellerhead | 0:ea21a4715fed | 45 | |
propellerhead | 0:ea21a4715fed | 46 | void Rx_interrupt(){ |
propellerhead | 0:ea21a4715fed | 47 | |
propellerhead | 0:ea21a4715fed | 48 | } |