@@ -124,9 +124,9 @@ void printButtonPressed(int pressedButton) {
124124
125125void button_led_control (void )
126126{
127- uint8_t ioexInputs = 0 ;
128- uint8_t defaultInputs = 0 ;
129- uint8_t activeLEDs = 0 ;
127+ uint8_t mcp23008_1_activeLEDs = 0 ;
128+ uint8_t mcp23008_2_previousInputs = 0 ;
129+ uint8_t mcp23008_2_currentInputs = 0 ;
130130
131131 (uint8_t ) MCP23008_Write (MCP23008_1_I2C_ADDRESS , MCP23008_IODIR , 0x00 );
132132 (uint8_t ) MCP23008_Write (MCP23008_1_I2C_ADDRESS , MCP23008_GPIO , 0x00 ); // After this line of code, the LEDs should be on.
@@ -136,25 +136,25 @@ void button_led_control(void)
136136 (uint8_t ) MCP23008_Write (MCP23008_2_I2C_ADDRESS , MCP23008_IOCON , 0x20 ); // Set SEQOP bit to 1 for Byte mode
137137
138138 // Read the default state of the inputs
139- (uint8_t ) MCP23008_Read (MCP23008_2_I2C_ADDRESS , MCP23008_GPIO , & defaultInputs );
140- (int ) printf ("Default inputs: 0x%02X\n" , defaultInputs );
139+ (uint8_t ) MCP23008_Read (MCP23008_2_I2C_ADDRESS , MCP23008_GPIO , & mcp23008_2_previousInputs );
140+ (int ) printf ("Default inputs: 0x%02X\n" , mcp23008_2_previousInputs );
141141
142- while (IO_Reset_GetValue () && !resetFlag ) // Run until Reset SW is pressed
142+ while (( IO_Reset_GetValue () != 0 ) && !resetFlag ) // Run until Reset SW is pressed
143143 {
144- (uint8_t ) MCP23008_Read (MCP23008_2_I2C_ADDRESS , MCP23008_GPIO , & ioexInputs ); // Read GPIO register to get the state of the inputs
144+ (uint8_t ) MCP23008_Read (MCP23008_2_I2C_ADDRESS , MCP23008_GPIO , & mcp23008_2_currentInputs ); // Read GPIO register to get the state of the inputs
145145
146- uint8_t changed_inputs = defaultInputs ^ ioexInputs ; // XOR to find changed bits
146+ uint8_t changed_inputs = mcp23008_2_previousInputs ^ mcp23008_2_currentInputs ; // XOR to find changed bits
147147 if (!(changed_inputs == 0U )) // Check if there is any change from the default state
148148 {
149149 for (uint8_t i = 0U ; i < 8U ; i ++ ) // Check each bit to see if a button is pressed
150150 {
151151 if (!(changed_inputs == 0U )) // Check if there is any change from the default state
152152 {
153- if ((ioexInputs & (1U << i )) == 0U ) // Button pressed (active low)
153+ if ((mcp23008_2_currentInputs & (1U << i )) == 0U ) // Button pressed (active low)
154154 {
155155 uint8_t pressedButton = i ;
156- activeLEDs = (activeLEDs | (1U << pressedButton ));
157- (uint8_t ) MCP23008_Write (MCP23008_1_I2C_ADDRESS , MCP23008_GPIO , activeLEDs ); // Set IO-expander 1 pins low
156+ mcp23008_1_activeLEDs = (mcp23008_1_activeLEDs | (1U << pressedButton ));
157+ (uint8_t ) MCP23008_Write (MCP23008_1_I2C_ADDRESS , MCP23008_GPIO , mcp23008_1_activeLEDs ); // Set IO-expander 1 pins low
158158 printButtonPressed (pressedButton );
159159 }
160160 }
0 commit comments