The present code executes a counter that checks current state and determines the next state.

Dependencies:   mbed

Fork of 2645_FSM_Counter by Craig Evans

Revision:
2:324696ae91a9
Parent:
1:81b129bec569
--- a/main.cpp	Wed Jan 06 12:24:45 2016 +0000
+++ b/main.cpp	Mon May 09 11:45:19 2016 +0000
@@ -1,21 +1,23 @@
 /* 
 
-2645_FSM_Counter
+Task1_FSM_Counter
 
 Sample code from ELEC2645 Week 16 Lab
 
 Demonstrates how to implement a simple FSM counter
 
-(c) Craig A. Evans, University of Leeds, Jan 2016
+(c) Bonny Ngangu, University of Leeds, Jan 2016
 
 */ 
 
 #include "mbed.h"
 
-// K64F on-board LEDs 
+// K64F on-board 4 LEDs 
 DigitalOut r_led(LED_RED);
 DigitalOut g_led(LED_GREEN);
 DigitalOut b_led(LED_BLUE);
+DigitalOut y_led(LED_BLUE);
+
 // K64F on-board switches
 InterruptIn sw2(SW2);
 InterruptIn sw3(SW3);
@@ -25,7 +27,7 @@
 BusOut output(PTB2,PTB3,PTB10,PTB11);
 
 // array of states in the FSM, each element is the output of the counter
-int fsm[4] = {1,2,4,8};
+int fsm[4] = {8,4,2,1}; //reversed order counter going down
 
 // function prototypes
 // error function hangs flashing an LED
@@ -45,17 +47,17 @@
 
         // check which state we are in and see which the next state should be
         switch(state) {
-            case 0:
-                state = 1;
+            case 0://0
+                state = 1;//1
                 break;
-            case 1:
-                state = 2;
+            case 1://1
+                state = 2;//2
                 break;
-            case 2:
-                state = 3;
+            case 2://2
+                state = 3;//3
                 break;
-            case 3:
-                state = 0;
+            case 3://3
+                state = 0;//0
                 break;
             default:
                 error();  //invalid state - call error routine
@@ -73,7 +75,8 @@
     // on-board LEDs are active-low, so set pin high to turn them off.
     r_led = 1;
     g_led = 1;
-    b_led = 1;   
+    b_led = 1;
+    y_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