Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 3:aac8dcbe6e18
- Parent:
- 2:bdd8b01141d1
- Child:
- 4:c6d3c2dea4b0
--- a/main.cpp Wed Dec 20 11:40:20 2017 +0000 +++ b/main.cpp Fri Jan 24 13:18:25 2020 +0000 @@ -7,32 +7,30 @@ Demonstrates how to implement a simple FSM counter (c) Craig A. Evans, University of Leeds, Jan 2016 +Updated January 2020 */ #include "mbed.h" // K64F on-board LEDs -DigitalOut r_led(LED_RED); -DigitalOut g_led(LED_GREEN); -DigitalOut b_led(LED_BLUE); -// K64F on-board switches -InterruptIn sw2(SW2); -InterruptIn sw3(SW3); - -// LEDs on Gamepad (1 to 4) - active-low 0 = on and 1 = off -BusOut output(PTA1,PTA2,PTC2,PTC3); +BusOut k64f_leds(LED_RED, LED_GREEN, LED_BLUE); +// Gamepad switches +InterruptIn buttonA(PTC7); +InterruptIn buttonB(PTC9); +// LEDs on Gamepad (1 to 3) - active-low 0 = on and 1 = off +// BusOut arguments are LSB first +BusOut output(PTA2,PTC2,PTC3); // array of states in the FSM, each element is the output of the counter // set the output in binary to make it easier, 0 is LED on, 1 is LED off -int fsm[4] = {0b0111,0b1011,0b1101,0b1110}; +int fsm[3] = {0b011,0b101,0b110}; -// set-up the on-board LEDs and switches -void init_K64F(); int main() { - init_K64F(); + k64f_leds = 0b111; // turn off K64F LEDs + // set inital state int state = 0; @@ -49,13 +47,10 @@ state = 2; break; case 2: - state = 3; - break; - case 3: state = 0; break; default: - error("Invalid state"); //invalid state - call error routine + error("Invalid state"); //invalid state - call Mbed error routine // or could jump to starting state i.e. state = 0 break; } @@ -63,18 +58,4 @@ wait(0.5); // small delay } -} - -void init_K64F() -{ - // on-board LEDs are active-low, so set pin high to turn them off. - r_led = 1; - g_led = 1; - b_led = 1; - - // since the on-board switches have external pull-ups, we should disable the internal pull-down - // resistors that are enabled by default using InterruptIn - sw2.mode(PullNone); - sw3.mode(PullNone); - } \ No newline at end of file