I am interfacing PIC32 MCU with 24 inputs and UART. When any inputs comes, this data is transferred to PC via uart. I am using multiple if condition like
if(input1==high)
{
putsUART("input 1 ON\n");
}
if(input2==high)
{
putsUART("input 2 ON\n");
}
What this if condition is doing is whenever an input comes, it keep on printing the data like
input 1 ON
input 1 ON
input 1 ON
and it goes on. I want it to be displayed once only. For example, if I applied input1, input 1 ON
should be printed once and if remove the input input 1 OFF
should be displayed once.
I don't know how can I run this if condition only once. Please help. Thanks.!
CODE(just for 3 inputs):
int main()
{
TRISAbits.TRISA6 = 1;
TRISAbits.TRISA7 = 1;
TRISGbits.TRISG13 = 1;
while(1)
{
if(PORTAbits.RA6 == 0) //INPUT 1
{
putsUART2("Input: 1 ON\n");
Delayms(1000);
}
if(PORTAbits.RA7 == 0) //INPUT 2
{
putsUART2("Input: 2 ON\n");
Delayms(1000);
}
if(PORTAbits.RG13 == 0) //INPUT 3
{
putsUART2("Input: 3 ON\n");
Delayms(1000);
}
}
}