Pages: [1] 2   Go Down
Author Topic: pinMode(ledpin17, LOW); is wrong? but no errors  (Read 1526 times)
0 Members and 1 Guest are viewing this topic.
Turku
Offline Offline
Full Member
***
Karma: 0
Posts: 201
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Cape Town, South Africa
Offline Offline
Full Member
***
Karma: 0
Posts: 177
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Edison Member
*
Karma: 7
Posts: 1221
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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..

Logged


0
Offline Offline
Newbie
*
Karma: 0
Posts: 31
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

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

#define HIGH 0x1
#define LOW  0x0

#define INPUT 0x0
#define OUTPUT 0x1

so
Code:
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
Logged

0
Offline Offline
Edison Member
*
Karma: 7
Posts: 1221
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged


UK
Offline Offline
Faraday Member
**
Karma: 16
Posts: 2883
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


does NOT work??  I

There are no internal pull-downs.
Logged

Per Arduino ad Astra

0
Offline Offline
Newbie
*
Karma: 0
Posts: 31
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Edison Member
*
Karma: 7
Posts: 1221
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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...

Logged


Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24442
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

0
Offline Offline
Edison Member
*
Karma: 7
Posts: 1221
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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-grin

thanks..

« Last Edit: July 10, 2010, 10:08:57 am by xl97 » Logged


0
Offline Offline
Edison Member
*
Karma: 7
Posts: 1221
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

bump..
Logged


Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24442
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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?

Quote
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.
« Last Edit: July 16, 2010, 08:06:17 am by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

0
Offline Offline
Edison Member
*
Karma: 7
Posts: 1221
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks for the reply..

to recap/clarify:


Quote
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
Logged


Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24442
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
.. 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.
« Last Edit: July 16, 2010, 09:58:02 am by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

0
Offline Offline
Edison Member
*
Karma: 7
Posts: 1221
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged


Pages: [1] 2   Go Up
Jump to: