First Last
/
Minor_Assignment3_4
Assignment 3 and 4. Both in commits.
Revision 0:86aaef96170e, committed 2015-09-02
- Comitter:
- vsluiter
- Date:
- Wed Sep 02 12:33:55 2015 +0000
- Child:
- 1:958fbf7ad850
- Commit message:
- Assignment 3
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MODSERIAL.lib Wed Sep 02 12:33:55 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/Sissors/code/MODSERIAL/#8ef4f91813fd
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Sep 02 12:33:55 2015 +0000 @@ -0,0 +1,55 @@ +#include "mbed.h" +#include "MODSERIAL.h" + +DigitalOut led(LED_GREEN); +DigitalIn button(PTA4); +MODSERIAL pc(USBTX, USBRX); + +const int baudrate = 115200; +const int ms_wait = 100; + +const float period_led = 0.1; +const float t_on = 0.1; +const float t_off = period_led - t_on; + +const int led_on = 0; +const int led_off = 1; + +const int button_pressed = 0; + + +void blink(int number_of_blinks) +{ + for(int i = 0; i < 5 ; i++) { + led.write(led_on); //turn led on + wait(t_on); + led.write(led_off); // toggle led + wait(t_off); + } +} + +int main() +{ + int waittime = 0; + led.write(led_off); + pc.baud(baudrate); + pc.printf("Hello World!\n"); + + while (true) { + wait_ms(ms_wait); //const value + if(button.read() == button_pressed) //button pressed + { + waittime++; + pc.printf("Pressed for %d ms\n", waittime * ms_wait); //const used again -> updating it at the top gives consistent results!! + } + else //button released + { + waittime = 0; + } + if(pc.readable()) //if character available. If expresseion is non-zero, it's true + { + pc.rxBufferFlush(); //flush the buffer. Otherwise pc.readable() will stay larger than zero + blink(1); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Sep 02 12:33:55 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/8ed44a420e5c \ No newline at end of file