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:818317dbe8a5
- Parent:
- 2:299c10699314
- Child:
- 4:b6e9d473ce0e
--- a/main.cpp Thu Jan 19 19:39:28 2017 +0000
+++ b/main.cpp Wed Dec 20 13:06:03 2017 +0000
@@ -2,7 +2,7 @@
2645_FSM_Puffin
-Sample code from ELEC2645 Week 16 Lab
+Sample code from ELEC2645
Demonstrates how to implement a puffin crossing using a FSM
@@ -18,13 +18,15 @@
DigitalOut b_led(LED_BLUE);
// LEDs to display traffic light output
-// connect up external LEDs to these pins with appropriate current-limiting resistor
+// May need to change pins depending on which order you soldered the LEDs
// LSB MSB
// car - green,amber, red pedestrian - green, red
-BusOut output(PTB2,PTB3,PTB10,PTB11,PTC11);
+BusOut output(PTC2,PTA2,PTA1,PTD3,PTC3); // LED order suggested in notes
+
// BusIn to read inputs simutaneously
-// camera , pedestrian
-BusIn input(SW3,SW2);
+// camera (button A) , pedestrian button (button B)
+// LSB, MSB
+BusIn input(PTB9,PTD0);
// struct for state
struct State {
@@ -32,10 +34,9 @@
float time; // time in state
int nextState[4]; // array of next states
};
-//typedef const struct State STyp;
State fsm[4] = {
- {0x0C,5.0,{...,...,...,...}}, // 0 - cars stop, pedestrian walk 5 seconds
+ {0x13,5.0,{...,...,...,...}}, // 0 - cars stop, pedestrian walk 5 seconds
{...,2.0,{2,2,2,2}}, // 1 - cars get ready to go, pedestrian stop 2 seconds
{...,10.0,{...,...,...,...}}, // 2 - cars go, pedestrian stop 10 seconds
{...,2.0,{0,0,0,0}} // 3 - cars get ready to stop, pedestrian stop 2 seconds
@@ -48,8 +49,8 @@
g_led = 1;
b_led = 1;
- // on-board switches have external pull-ups, so turn off default internal pull-downs
- input.mode(PullNone);
+ // turn on internal pull-downs for buttons A and B
+ input.mode(PullDown);
int state = 2; // start with cars green