Simple Hello World program that outputs "Hello World!" every five seconds to the serial debug port, and blinks at the user defined hertz.
Dependencies: mbed-src
main.cpp@0:4882b9e3f2cb, 2015-07-06 (annotated)
- Committer:
- agoel
- Date:
- Mon Jul 06 08:05:37 2015 +0000
- Revision:
- 0:4882b9e3f2cb
First version - Simple Hello World program that outputs "Hello World!" every five seconds to the serial debug port, and blinks at the user defined hertz.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
agoel | 0:4882b9e3f2cb | 1 | #include "mbed.h" |
agoel | 0:4882b9e3f2cb | 2 | |
agoel | 0:4882b9e3f2cb | 3 | /* Simple Hello World program that outputs "Hello World!" every |
agoel | 0:4882b9e3f2cb | 4 | five seconds to the serial debug port, and blinks at the user |
agoel | 0:4882b9e3f2cb | 5 | defined hertz |
agoel | 0:4882b9e3f2cb | 6 | */ |
agoel | 0:4882b9e3f2cb | 7 | |
agoel | 0:4882b9e3f2cb | 8 | // LED blink rate: higher -> faster blinking |
agoel | 0:4882b9e3f2cb | 9 | #define LED_BLINK_RATE 8 //Hertz |
agoel | 0:4882b9e3f2cb | 10 | |
agoel | 0:4882b9e3f2cb | 11 | //Define the LED pin output |
agoel | 0:4882b9e3f2cb | 12 | //DigitalOut data00(D0); |
agoel | 0:4882b9e3f2cb | 13 | DigitalOut data00(PA_3); //Blinds D0 LED |
agoel | 0:4882b9e3f2cb | 14 | //DigitalOut data01(D1); |
agoel | 0:4882b9e3f2cb | 15 | DigitalOut data01(PA_2); //Blinds D1 LED |
agoel | 0:4882b9e3f2cb | 16 | //DigitalOut data02(D2); |
agoel | 0:4882b9e3f2cb | 17 | //DigitalOut data02(PB_15); //Blinds D2 LED |
agoel | 0:4882b9e3f2cb | 18 | //DigitalOut data03(D3); |
agoel | 0:4882b9e3f2cb | 19 | DigitalOut data03(PA_0); //Blinds D3 LED |
agoel | 0:4882b9e3f2cb | 20 | //DigitalOut data04(D4); |
agoel | 0:4882b9e3f2cb | 21 | DigitalOut data04(PA_7); //Blinds D4 LED |
agoel | 0:4882b9e3f2cb | 22 | //DigitalOut data05(D5); |
agoel | 0:4882b9e3f2cb | 23 | DigitalOut data05(PA_9); //Blinds D5 LED |
agoel | 0:4882b9e3f2cb | 24 | //DigitalOut data06(D6); |
agoel | 0:4882b9e3f2cb | 25 | DigitalOut data06(PA_1); //Blinds D6 LED |
agoel | 0:4882b9e3f2cb | 26 | //DigitalOut data07(D7); |
agoel | 0:4882b9e3f2cb | 27 | DigitalOut data07(PA_8); //Blinds D7 LED |
agoel | 0:4882b9e3f2cb | 28 | //DigitalOut data08(D8); |
agoel | 0:4882b9e3f2cb | 29 | DigitalOut data08(PB_1); //Blinds D8 LED |
agoel | 0:4882b9e3f2cb | 30 | int temp; |
agoel | 0:4882b9e3f2cb | 31 | |
agoel | 0:4882b9e3f2cb | 32 | //Define timers |
agoel | 0:4882b9e3f2cb | 33 | Timer print_timer; |
agoel | 0:4882b9e3f2cb | 34 | Timer led_timer; |
agoel | 0:4882b9e3f2cb | 35 | |
agoel | 0:4882b9e3f2cb | 36 | int main() { |
agoel | 0:4882b9e3f2cb | 37 | data00 = 1; //Initialize LED off |
agoel | 0:4882b9e3f2cb | 38 | data01 = 1; //Initialize LED off |
agoel | 0:4882b9e3f2cb | 39 | // data02 = 1; //Initialize LED off |
agoel | 0:4882b9e3f2cb | 40 | data03 = 1; //Initialize LED off |
agoel | 0:4882b9e3f2cb | 41 | data04 = 1; //Initialize LED off |
agoel | 0:4882b9e3f2cb | 42 | data05 = 1; //Initialize LED off |
agoel | 0:4882b9e3f2cb | 43 | data06 = 1; //Initialize LED off |
agoel | 0:4882b9e3f2cb | 44 | data07 = 1; //Initialize LED off |
agoel | 0:4882b9e3f2cb | 45 | data08 = 0; //Initialize LED off |
agoel | 0:4882b9e3f2cb | 46 | print_timer.start(); //Start timers, will count until stopped |
agoel | 0:4882b9e3f2cb | 47 | led_timer.start(); |
agoel | 0:4882b9e3f2cb | 48 | |
agoel | 0:4882b9e3f2cb | 49 | while (1) { |
agoel | 0:4882b9e3f2cb | 50 | if (print_timer.read() >= 5) { //print_timer.read() returns time in seconds |
agoel | 0:4882b9e3f2cb | 51 | printf("Hello World!\n"); |
agoel | 0:4882b9e3f2cb | 52 | print_timer.reset(); //Resets timer count to 0 |
agoel | 0:4882b9e3f2cb | 53 | } |
agoel | 0:4882b9e3f2cb | 54 | |
agoel | 0:4882b9e3f2cb | 55 | //Calculates interval needed for specified frequency |
agoel | 0:4882b9e3f2cb | 56 | if ( led_timer.read_ms() >= (2000.0/(2*LED_BLINK_RATE))) { |
agoel | 0:4882b9e3f2cb | 57 | temp = data01; //Invert LED output |
agoel | 0:4882b9e3f2cb | 58 | data01 = data00; //Invert LED output |
agoel | 0:4882b9e3f2cb | 59 | data00 = data03; //Invert LED output |
agoel | 0:4882b9e3f2cb | 60 | data03 = data06; //Invert LED output |
agoel | 0:4882b9e3f2cb | 61 | data06 = data08; //Invert LED output |
agoel | 0:4882b9e3f2cb | 62 | data08 = data05; //Invert LED output |
agoel | 0:4882b9e3f2cb | 63 | data05 = data04; //Invert LED output |
agoel | 0:4882b9e3f2cb | 64 | data04 = data07; //Invert LED output |
agoel | 0:4882b9e3f2cb | 65 | data07 = temp; //Invert LED output |
agoel | 0:4882b9e3f2cb | 66 | led_timer.reset(); //Resets timer count to 0 |
agoel | 0:4882b9e3f2cb | 67 | } |
agoel | 0:4882b9e3f2cb | 68 | } |
agoel | 0:4882b9e3f2cb | 69 | } |