pinMode(ledpin17, LOW); is wrong? but no errors

I was probably sleeping with my eyes open and copy pasted this kind of rubbish into my code. Compiler did not give any errors.

LOW, just like INPUT and OUTPUT is just plain integer constants, hence the compiler will not complain.

I guess your could make it a lot more type-safe (given it is compiled with g++ rather than gcc), but that will add unnecessary overhead.

it might be rubbish..

but for noobs like myself.. and learning/grasping he concept of internal pullup resistors.. a pulldown resistor seems logical as well..

I don't think the atmega has pulldowns.
If it has them using the same syntax as for pullUps would make more sense:

pinMode(pin, INPUT);
digitalWrite(pin, HIGH); // activate pull up

As it is the wiring.h defines the constants HIGH,LOW,INPUT and OUTPUT:

#define HIGH 0x1
#define LOW  0x0

#define INPUT 0x0
#define OUTPUT 0x1

so

pinMode(ledpin17,LOW);
pinMode(ledpin17,0);
pinMode(ledpin17,INPUT);

all have the same effect, and actually result all in the same code on the arduino.

I actually often write digitalWrite(pin, 0); instead of digitalWrite(pin, LOW); just because of habit.

bye,
NsN

hmm..

being a noob.. I really have no clue..

but I thought I read ONLY the internal PULL UP resistor works/is available? But using

pinMode(pin, INPUT);
digitalWrite(pin, LOW); // activate pull down

does NOT work?? I had just read that a few days in a post here (somewhere)

so youre saying you 'can' in fact use it the same way to initiate an INTERNAL PULL 'DOWN' resistor on a pin?

Thanks

digitalWrite(pin, LOW); // activate pull down

does NOT work?? I

There are no internal pull-downs.

No what i meant was that if there were internal pulldowns, it would make sense to use digitalWrite(pin,LOW) to activate them.

However, since there are no pulldowns, digitalWrite(pin,LOW) will just deactivate the pulldowns, and the pin will behave like it is not connected.

ok..

so (again) there are NO (none) internal resistors to use like the internal PULL UPS..

which is what I was relating..and how to a NOOB,...

the PULL DOWN thing (which does not exist)..can be confusing since you learn a trick to do PULL UP resistors that way...

the PULL DOWN thing (which does not exist)..can be confusing since you learn a trick to do PULL UP resistors that way

Any clues what the intuitive method of disabling pull-ups AND (imaginary) pull-downs would be in a binary system?

huh?

I guess I dont even understand the question.. so I'll just answer: 'no'..

Im not picking any fights with anyone..

Im saying..for a noob like myself..

its confusing to see/learn how the internal pull UP resistor trick works.. (and one would think there is the same for a pull DOWN)

I understand this is the same thing:

pinMode(somePin,HIGH);
pinMode(somePin,1);

and 'if' there was a internal Pull Down..

I would/could use this:

pinMode(somePin,LOW);
pinMode(somePin,0);

but since there isnt an internal pull DOWN resistor..
that wont work..

on a side note.

whats the difference between using a:

define# statement

vs.

int ledPin 13;

for example??

and I have never seen

'states' (HIGH/LOW) used in a define before?

#define HIGH 0x1
#define LOW 0x0

#define INPUT 0x0
#define OUTPUT 0x1

any help on explanation on this?

Thanks in advance. :smiley:

thanks..

bump..

its confusing to see/learn how the internal pull UP resistor trick works.. (and one would think there is the same for a pull DOWN)

I don't see what's confusing; the mechanism is adequately documented.
If you were expecting a HIGH to enable pull-ups, and a LOW to enable pull-downs, which third binary state were you going to use for neither?

and I have never seen

'states' (HIGH/LOW) used in a define before?

Not sure what you're saying here, but you can view all the Arduino source headers in the distribution directories.

Re: "const int" vs. "#define".
Some say that "#define" and the C preprocessor is Old School, and that C++ programmers should use the "const" method.
Personally, I use whichever feels the more natural for the particular usage.

thanks for the reply..

to recap/clarify:

I don't see what's confusing; the mechanism is adequately documented.
If you were expecting a HIGH to enable pull-ups, and a LOW to enable pull-downs, which third binary state were you going to use for neither?

I guess Im a bit confused now..

I was under the impression form reading posts HERE.

that you can ONLY use an INTERNAL PULL UP resistor..like so:

pinMode(pin, INPUT);
digitalWrite(pin, HIGH); // activate pull up

however.. THERE IS NO PULLDOWN INTERNAL RESISTOR.. correct?
this:

pinMode(pin, INPUT);
digitalWrite(pin, LOW); // activate pull down

first questo clarify.. IS THIS CORRECT? simple yes or no?

everywhere I have read stated internal PULL UP = YES.

internal PULL DOWN = NO..

is this information False then?

let just get clear on that.. if this is NOT true...and you can in fact use INTERNAL PULL DOWN RESISTORS...

then my statement of 'thats confusing' to noobies is irrelevant.

Your question of what 3rd binary state I would use.. I have no clue.. is there even one? 1 or 0..what 3rd state? (confused as to what your even asking really)..

Im not even trying to 'label' any 3rd state.. more about the confirmation of Is there or is there not a INTERNAL PULL DOWN resistor.. (pretty simple & straightforward I think)

second point: (which has NOTHING and shouldnt even be grouped in the same question(s) as above)

I dont know anything about Source headers...or distribution directories (or why they would even be brought up to be honest)

my question was/is...

(which you partially answered already for me)

1.) difference between using a #define statement...vs. const int ledPin 13 for example. (whatever fits your project..no real difference in usage or compiling?)

and then to further that.. I stated I have never seen this before:

#define HIGH 0x1
#define LOW 0x0

#define INPUT 0x0
#define OUTPUT 0x1

never seen HIGH or LOW defined?? nor INPUT or OUTPUT #defined anywhere..

and am asking: what is this for? how/why is it used like this?

just delcaring a 'variable more or less? and those are the values for that var?

hopefully this make my questions a bit more clear.. just trying to get used to, and understand some of the code I see and WHY its used in that fashion..

and to clear up some of the statements I have read regarding the INTERNAL PULL DOWN resistor..

thanks

.. THERE IS NO PULLDOWN INTERNAL RESISTOR.. correct?

There are categorically, without doubt, no form of user-modifiable built-in pull-down resistor on the AVR processor.
Why do you keep asking the question?
I really don't see where your confusion comes from.

because I cant seem to get a straight YES or NO...

and I ask this..because I read here.. (I'll have to go search for the thread now).. and was TOLD (direct post even?)

that while you CAN do/use an internal PULL UP resistor (not hardware related).. but this DOES NOT WORK when trying to do the same thing for an internal PULL DOWN resistor

then I saw all that #DEFINE HIGH/LOW and #DEFINE INPUT/OUTPUT stuff you guys posted..

so I am confused.. that is why I am asking..

here:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1243235304/0

posts# 5 & 6

so whos right?? who am I to follow and believe for correct coding practices???

Im not trying to cause trouble.. Im trying to understand.. and just ask simple basic questions so I can get a foundation to work from.

I guess Im not the only who doesnt find then 'intuitive'...or 'confusing' (thinking if there is a normal pull up...why not a pull down?)

some say there isnt..you say there is?

thanks

some say there isnt..you say there is?

No, there is no internal software enabled pull-down for a Atmel AVR processor chip. I don't think anyone directly stated that there is one on my reading of your posts or links, however I might have missed what you are referring to. If someone did state as such then they were simply wrong ( I know, imagine that someone of the Internet is wrong :wink: ).

To review:

  1. At reset or power up cycle all digital pins are defaulted to be digital input pins with no internal pull-ups on, and they rely totally on the external circuit wired to the pin to provide a valid logic voltage, high or low. If nothing is wired to the pin in this condition then one can not perform a digitalRead statement and expect to get a valid reading, the pin is said to be 'floating' and will return incorrect data.

  2. To enable the internal pull-up for a digital input pin one does:

pinMode(pin, INPUT);
digitalWrite(pin, HIGH); // activate pull up

  1. To disable the internal pull-up (if it was enabled prior) one does:

pinMode(pin, INPUT);
digitalWrite(pin, LOW); // disable internal pull up.

So to repeat an input pin can either be in a floating condition (relying on external components to define the voltage input) or have a active HIGH being applied to the pin by the internal pull-up resistor. There are no other 'states' for a digital input pin.

That help?
Lefty

lol.

Im totally NOT trying to place blame.. just trying to 'cut the mustard' and get some facts... hard enough being new to Arduino/C programming..LOL

mix that with hardware that Im really bad at... (oh boy!) lol

(I wish everything was written in ActionScript) :stuck_out_tongue:

anyways-

everypost I read from AWOL makes it seem (because I couldnt get a yes or no).. just that: "there are categorically, without doubt any form of user-modifiable built-in pull-down resistor on the AVR processor."

which again seems to say YES there is an internal pull DOWN resistor? am I reading all his posts wrong?

and if the answer was just NO.. (why not just say you are correct..ther is none)..

but posting all that #HIGH

#LOW..stuff made me (again) think he was saying yes there is..and here is a way..etc.. (which I asked for clarification on)

seems to get skipped..??

anyways...thanks at least I have that part of the question(s) answered.. :slight_smile:

"there are categorically, without doubt any form of user-modifiable built-in pull-down resistor on the AVR processor."

That is rather a poorly written statement, and I took it as a typo with "any" really meaning no.

PS: I added some more to my prior posting.

Lefty

WINNER WINNER.. CHICKEN DINNER!

thanks man.

that was perfect and crystal clear.

To review:

  1. At reset or power up cycle all digital pins are defaulted to be digital input pins with no internal pull-ups on, and they rely totally on the external circuit wired to the pin to provide a valid logic voltage, high or low. If nothing is wired to the pin in this condition then one can not perform a digitalRead statement and expect to get a valid reading, the pin is said to be 'floating' and will return incorrect data.

  2. To enable the internal pull-up for a digital input pin one does:

pinMode(pin, INPUT);
digitalWrite(pin, HIGH); // activate pull up

  1. To disable the internal pull-up (if it was enabled prior) one does:

pinMode(pin, INPUT);
digitalWrite(pin, LOW); // disable internal pull up.

just awesome..and clears up all confusion.

this here:
pinMode(pin, INPUT);
digitalWrite(pin, LOW); // disable internal pull up.

was a missing piece that is great to know setting a pin LOW disable internal PULL UP..but is NOT setting an internal PULL DOWN..

another piece in the puzzle is solved. (just about 50 more for my project)..lol

now to go back and learn how to work using this sensor correctly:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1278535345/14#14

from my 'research' its a timed.. 'and' a 'count' thing.. like the bounce/jitter is how others are using it to determine tilt vs swing.. how many int's get triggered in a period of time perhaps form what Ive gathered... so I dont think I was too off base on my initial approach for it.

and see if my "interrupt demo' utilizes a 'decent/acceptable' debounce routine/approach?

int ledPin = 13;
int cPin = 2; 
int cState = LOW;

long cCheck = 0;
long cDelay = 50;
long cDiff = 0;
 
void setup(){
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  pinMode(cPin, INPUT);
  digitalWrite(cPin, HIGH);
  attachInterrupt(0, cInt, CHANGE);
}
void loop(){
  //keep count of time passed
  cDiff = (millis() - cCheck);
  //check to see if 'event' fires
  if(cState == HIGH){
    //if event fires, check to see if not false/bounce detection
    Serial.println("--EVENT TRIGGERED--");
    if(cDiff > cDelay){
      //enough time 'has' pased update timer value (reset counter)
      Serial.println("--LEGIT TRIGGER--");
      cCheck = millis();      
      //tone(8, 350, 50);
      digitalWrite(ledPin, cState);
      delay(20);
      cState = LOW;
      digitalWrite(ledPin, cState);
    }
    else{
      //Serial.println("--BOUNCE TRIGGER--");
    }
  }
  else{
    //Serial.println("--EVENT **NOT** TRIGGERED--");
  }
}

void cInt(){
  Serial.println("**ISR: HIGH**");
  cState = HIGH;
}

(and why my attempt at using a non-interrupt, timer only based approach didnt work at all..)

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1277951164/9#9

not sure the code approach he/they are telling me to utilize.. I gave it ti shot.. (no replies) :wink:

(figure I'll give it a shot though...never say die ....right?) LOL

thanks appreciate the help and replies.