]> Pileus Git - ~andy/csm213a-hw/blob - hw2/tester.cpp
Import testing code and update makefiles
[~andy/csm213a-hw] / hw2 / tester.cpp
1 /* main.cpp
2  * mbed project: Simple_Square_Wave
3  * mbed board: FRDM-KL46Z
4  * Generate square waves using DigitalOut.
5  */
6
7 #include "mbed.h"
8
9 DigitalOut Square_Wave(PTD3); // Used PWM output is PTD3
10 InterruptIn Control_Testing(PTC12);  // SW3
11
12 void Control_T(void);
13
14 int START_STOP_FLAG = 0;
15 float period_s = 0.0001;
16
17 extern serial_t stdio_uart;
18
19 int main(int arc, char **argv)
20 {
21         serial_init(&stdio_uart, USBTX, USBRX);
22         serial_baud(&stdio_uart, 115200);
23         printf("starting\r\n");
24
25         Control_Testing.rise(&Control_T);    // Enable getMode interrupt handler
26         __enable_irq();
27
28         while(1)
29         {
30                 if(START_STOP_FLAG == 1)
31                 {
32                         Square_Wave.write(0);
33                         wait(period_s/2);
34                         Square_Wave.write(1);
35                         wait(period_s/2);
36                 }
37                 else
38                         Square_Wave.write(0);
39         }
40 }
41
42 void Control_T(void)
43 {
44         if(START_STOP_FLAG == 0)
45         {
46                 period_s = 1;
47                 START_STOP_FLAG = 1;
48         }
49         else
50         {
51                 START_STOP_FLAG = 0;
52                 Square_Wave.write(0);
53         }
54 }