]> Pileus Git - ~andy/csm213a-hw/blobdiff - hw2/tester.cpp
Import testing code and update makefiles
[~andy/csm213a-hw] / hw2 / tester.cpp
diff --git a/hw2/tester.cpp b/hw2/tester.cpp
new file mode 100644 (file)
index 0000000..3a55bd8
--- /dev/null
@@ -0,0 +1,54 @@
+/* main.cpp
+ * mbed project: Simple_Square_Wave
+ * mbed board: FRDM-KL46Z
+ * Generate square waves using DigitalOut.
+ */
+
+#include "mbed.h"
+
+DigitalOut Square_Wave(PTD3); // Used PWM output is PTD3
+InterruptIn Control_Testing(PTC12);  // SW3
+
+void Control_T(void);
+
+int START_STOP_FLAG = 0;
+float period_s = 0.0001;
+
+extern serial_t stdio_uart;
+
+int main(int arc, char **argv)
+{
+       serial_init(&stdio_uart, USBTX, USBRX);
+       serial_baud(&stdio_uart, 115200);
+       printf("starting\r\n");
+
+       Control_Testing.rise(&Control_T);    // Enable getMode interrupt handler
+       __enable_irq();
+
+       while(1)
+       {
+               if(START_STOP_FLAG == 1)
+               {
+                       Square_Wave.write(0);
+                       wait(period_s/2);
+                       Square_Wave.write(1);
+                       wait(period_s/2);
+               }
+               else
+                       Square_Wave.write(0);
+       }
+}
+
+void Control_T(void)
+{
+       if(START_STOP_FLAG == 0)
+       {
+               period_s = 1;
+               START_STOP_FLAG = 1;
+       }
+       else
+       {
+               START_STOP_FLAG = 0;
+               Square_Wave.write(0);
+       }
+}