the message is keep repeating. how to stop the message in serial monitor even the pin is still in continuous active high or low status. it’s just a one time message.
There are many problems with this program. Of course it does not matter what the status of “PinB” is. Take a deep breath and think through what each line does.
First off … which message ? I deduce that since there’s a problem you’re getting the PinA ON message but it’s always helpful to state exactly what’s happening and not happening. We can’t read your mind or see what’s happening on your PC. Only the NSA can do that !
Second you’re getting a message all the time because that’s what your code instructs the Arduino to do. It reads pinB and if it’s HIGH is sends the PINA ON message. If pinB was LOW it then reads pinB again and if it’s LOW (which it must be), it sends the PINA OFF message. PinB is either HIGH or LOW, it can’t be anything else … so you get a message all the time. (ps - you’re missing the Serial.begin(XXXX) statement)
What do you want it to do ? Send the messages only on the transitions from HIGH to LOW and from LOW to HIGH ? I might guess this is what you want but ???
BTW what do you have attached to pinB ? Does it always put pinB into a defined state ? Is pinB ever left floating, not connected to anything ? When floating the pins can switch back and forth between HIGH and LOW and so you should enable the input pull-up resistor.
jremington:
There are many problems with this program. Of course it does not matter what the status of “PinB” is. Take a deep breath and think through what each line does.
I'll guess what we see is a snippet of a larger program. It doesn't compile for me.
The use of the name int() makes me wonder if the OP wasn’t trying to use external interrupts.
I’d guess you are only getting pinA high messages. Check the condition on your if statements for the answer.
jremington:
There are many problems with this program. Of course it does not matter what the status of “PinB” is. Take a deep breath and think through what each line does.
I think he just means that the variable ‘val’ is never used… hence the status of PinB does not matter…
bsagan:
I’d guess you are only getting pinA high messages. Check the condition on your if statements for the answer.
jremington:
There are many problems with this program. Of course it does not matter what the status of “PinB” is. Take a deep breath and think through what each line does.
I think he just means that the variable ‘val’ is never used… hence the status of PinB does not matter…
Ha ! I saw the high level goof and missed the low lever goof(s). :oops: