i want to read the status to tell its high or low once only whenever the pin 7 status is changed
so, code is running in loop is there method to reply once and wait until the status changes and then reply again.hope this time made less mistakes
#include <SoftwareSerial.h>
SoftwareSerial BTserial(10, 11);
void setup() {
Serial.begin(9600);
Serial.print("Arduino is ready");
BTserial.begin(9600);
BTserial.print("Bluetooth is ready");
}
void loop() {
int INPIN = 7;
int val = 0;
pinMode(INPIN, INPUT);
val = digitalRead(INPIN);
switch (val) {
case 0:
BTserial.println("off");
break;
case 1:
BTserial.println("on");
break;
}
delay(1000);
}
i want to read the status to tell its high or low once only whenever the pin 7 status is changed
How are you going to tell that it has changed status, if you only read it once? You must read the pin over and over. You can WRITE only once when the state changes.
Why are you setting the mode of the pin in loop()?
No, but there IS a need for a pullup or pulldown resistor if you do not want a floating pin problem, like you have now. Fortunately, the Arduino has internal pullup resistors on all pins, activated using INPUT_PULLUP as the mode.
floating problem is solved,thanks.
last one thing why its not showing status when code is uploaded first time,when the wire is removed then connected it works why so?