Demonstrates how to implement a simple FSM counter

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
eencae
Date:
Wed Dec 20 11:40:20 2017 +0000
Parent:
1:81b129bec569
Commit message:
Updated pins and output values for Gamepad.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 81b129bec569 -r bdd8b01141d1 main.cpp
--- 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
diff -r 81b129bec569 -r bdd8b01141d1 mbed.bld
--- a/mbed.bld	Wed Jan 06 12:24:45 2016 +0000
+++ b/mbed.bld	Wed Dec 20 11:40:20 2017 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/4336505e4b1c
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/e7ca05fa8600
\ No newline at end of file