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:
- 2:bdd8b01141d1
- Parent:
- 1:81b129bec569
- Child:
- 3:aac8dcbe6e18
--- a/main.cpp Wed Jan 06 12:24:45 2016 +0000
+++ b/main.cpp Wed Dec 20 11:40:20 2017 +0000
@@ -2,7 +2,7 @@
2645_FSM_Counter
-Sample code from ELEC2645 Week 16 Lab
+Sample code from ELEC2645
Demonstrates how to implement a simple FSM counter
@@ -20,16 +20,13 @@
InterruptIn sw2(SW2);
InterruptIn sw3(SW3);
-// LEDs to display counter output
-// connect up external LEDs to these pins with appropriate current-limiting resistor
-BusOut output(PTB2,PTB3,PTB10,PTB11);
+// LEDs on Gamepad (1 to 4) - active-low 0 = on and 1 = off
+BusOut output(PTA1,PTA2,PTC2,PTC3);
// array of states in the FSM, each element is the output of the counter
-int fsm[4] = {1,2,4,8};
+// set the output in binary to make it easier, 0 is LED on, 1 is LED off
+int fsm[4] = {0b0111,0b1011,0b1101,0b1110};
-// function prototypes
-// error function hangs flashing an LED
-void error();
// set-up the on-board LEDs and switches
void init_K64F();
@@ -38,7 +35,7 @@
init_K64F();
// set inital state
int state = 0;
-
+
while(1) { // loop forever
output = fsm[state]; // output current state
@@ -58,12 +55,12 @@
state = 0;
break;
default:
- error(); //invalid state - call error routine
+ error("Invalid state"); //invalid state - call error routine
// or could jump to starting state i.e. state = 0
break;
}
- wait(0.2); // small delay
+ wait(0.5); // small delay
}
}
@@ -80,14 +77,4 @@
sw2.mode(PullNone);
sw3.mode(PullNone);
-}
-
-void error()
-{
- while(1) { // if error, hang while flashing error message
- r_led = 0;
- wait(0.2);
- r_led = 1;
- wait(0.2);
- }
}
\ No newline at end of file