//////////////////////////////////////////////////////////////// // void Five_Lights (char *globalOutput) // // Function: Uses a state machine approach with // 15 states. A switch statement evaluates what // action should be taken for each state. The state // value is kept in a static int variable so that // the value remains upon the next entry into the // function without using global variables. Every // state will then increment to the next state // except for the last state, which will reset to state 0. // Each state is equivalent of 250 ms from the // msleep in the main() function's while(1) loop. // // LED operation: (X means ON) // LEDs 7 6 5 4 3 2 1 0 (Bargraph) // X - 500 ms // X X - 500 ms // X X X - 500 ms // X X X X - 500 ms // X X X X X - 500 ms // - 500 ms // // Parameters: char *globalOutput - variable from main program // passed as a call-by-reference parameter; // current pattern of LEDs, gets changed in this // function and by reference changes the original. // // Returns: NONE // //////////////////////////////////////////////////////////////// void Five_Lights (char *globalOutput) { // static variable for state, value remains even after exit // and for the next entry into function static int nState = 0; // switch statement to evaluate state machine states switch ( nState ) { case 0: // LED #4 ON case 1: // for 500 ms *globalOutput = 0x10; break; case 2: // add LED #3 ON case 3: // for 500 ms *globalOutput = 0x18; break; case 4: // add LED #2 ON case 5: // for 500 ms *globalOutput = 0x1C; break; case 6: // add LED #1 ON case 7: // for 500 ms *globalOutput = 0x1E; break; case 8: // add LED #0 ON case 9: // for 500 ms *globalOutput = 0x1F; break; case 10: // LEDs 4-0 OFF case 11: // for 500 ms *globalOutput = 0x00; break; case 12: // Wait total of 1 second (1000 ms) case 13: // before restarting state cycle case 14: case 15: break; } // if not in last state, then increment to next state if ( nState < 15 ) { nState++; } // if in last state, restart back at state 0 else { nState = 0; } } //////////////////////////////////////////////////////////////// // void Output_LEDs ( char outLED1, char outLED2 ) // // Function: To set LED Bargraphs 1 & 2 from the data in outLED1 and outLED2 // Parameters: char outLED1 - output to send to LED Bargraph 1 in format of 1=ON, 0=OFF // char outLED2 - output to send to LED Bargraph 2 in format of 1=ON, 0=OFF // //Returns: none //////////////////////////////////////////////////////////////// void Output_LEDs ( char outLED1, char outLED2) { *pLEDOut1 = ~outLED1; // invert output to LED Bargraph 1 *pLEDOut2 = ~outLED2; // invert output to LED Bargraph 2 }