pinMode INPUT can not digitalWrite HIGH?

Hi, I find Arduino code like blow not work for spark? How can I set INPUT mode pin HIGH?

#define REC_BUTTON 7

void setup() {
  Serial.begin(9600);

  pinMode(REC_BUTTON, INPUT);
  digitalWrite(REC_BUTTON, HIGH);
}

An input is used for measuring things, generally speaking. Setting a pin HIGH is output. Why would you want to set an input pin HIGH like that?
If it’s meant to act as a pull-up, simply use the appropriate code: http://docs.particle.io/core/firmware/#setup-pinmode

Also, please define your pin as “D7”, rather than just “7”, since we’ve got both digital and analog with similar numbers.

1 Like

@rhoulay, on the Arduino platforms, writing a HIGH to an input is used for activating a pull-up resistor on that input. On Particle devices, the pinMode() commands is used with an explicit mode to specify PULLUP or PULLDOWN resistors like this for example:

pinMode(REC_BUTTON, INPUT_PULLUP);

Refer to the documentation for more intormation :smile:

2 Likes

The solution @peekay123 has pointed out has even become part of the Arduino standard
Look at
http://www.arduino.cc/en/Reference/PinMode