/* 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); } }