Skip to main content
2 of 4
added 98 characters in body
Roger Rowland
  • 2k
  • 4
  • 21
  • 36

You need to remember the state of each input, and only output to the UART if it changes.

Something like this, just for one input so you get the idea :

// NB - put this line outside your loop
uint8_t uInput1 = 0;               

while (1)
{
    // ...

    // NB - put this code inside your loop
    if (PORTAbits.RA6 != uInput1)
    {
        // save current state
        uInput1 = uInput1 ? 0 : 1;

        // output change
        if (uInput1)
            putsUART2("Input: 1 ON\n");
        else
            putsUART2("Input: 1 OFF\n");
    }

    // ... do the same for other inputs
}
Roger Rowland
  • 2k
  • 4
  • 21
  • 36