Mee_n_Mac:
So far as I can tell these are equivalent and use the same amount of flash memory:
#define switchpin 9
const int switchpin = 9;
I assume you’re doing the below to enable the internal pull-up ?
digitalWrite (switchpin , HIGH);
You should do that in the setup() function prior to running your messaging code. You can also try this command when setting the pinmode:
pinMode(switchpin , INPUT_PULLUP);
http://arduino.cc/en/Reference/PinMode
But be aware that the pin will now be a HIGH unless it’s pulled LOW. So if you want to send a message, you should base the message on the pin being pulled LOW. If you need it to be based on when the pin is pulled HIGH by some external device, the don’t enable the internal pull-up (just declare the pin as an input) and use an external resistor (5k - 20k) connected from the pin to ground (aka an external pull-down resistor).
Thank you sir.
I think its not necessary to use pinMode (switchPin, HIGH), as you said, because I’m using it to control an external device (GSM module)
And, I had another doubt.
Is it better to use if (digitalRead(9) == 1) to check the status of the pin, or
define an const int variable like switchPin and initialize it to number 9 (pin number) , and then use the statement if (switchPin==HIGH) ??
Actually, I’m using a pin from another arduino to activate this switchPin by using the statement
digitalWrite(red, HIGH), where red is initialized as an output pin , by using
int red = 8 and
pinMode (red,OUTPUT)
on the other arduino.
Pls reply back!!