Wiring Forum
http://wiring.org.co/cgi-bin/yabb/YaBB.pl
Programming Questions & Help >> Syntax >> question about different pins
http://wiring.org.co/cgi-bin/yabb/YaBB.pl?num=1193477118

Message started by Titus on 10/27/07 at 09:25:17

Title: question about different pins
Post by Titus on 10/27/07 at 09:25:17
Since the digital I/O pins have a pin 0 and the analog in have a pin 0 and the PWM have a pin 0

if you create an int, like so:
int ledpin = 0;

The led would be on pin 0.

Which pin 0 is it:
Is this correct:



if you use a "analogWrite" command, it is a PWM pin
If you use a "analogRead" command it is a Analog in pin(analog in pins can't be used for analog out, can they, because that's the PWM)

As for the Digital pin:
If you want to use a digital pin, you will need to put a "pinMode" command in the void setup, like so:

void setup()
{
 pinMode(ledPin, OUTPUT); // sets the digital pin as output
}

The OUTPUT or INPUT changes the sort of Digital pin.

Can you use a "digitalWrite" command without the "pinMode" command in the void setup?

Or a "digitalRead" command without the "pinMode" command in the void setup


Thanks,

Titus

Title: Re: question about different pins
Post by worapoht on 10/27/07 at 17:33:44
As pin assignement, I think it's ok

 int ledpin = 0;
// just assign a variable named "ledpin" keep number 0 only, not direct to I/O until placed on digital I/O function

Wiring/Arduino program formed
void setup()
{
}

void loop()
{
}

actually, Real code of both section look like this

int main(void)
{
 init();
 setup();
 for ( ; ; )
   loop();
 return 0;
}

that's pinMode can be use anywhere in program..
about digitalWrite function shouldn't modified direction because some interface need internal pull-up resistor while operate on input mode..

Wiring Forum » Powered by YaBB 2.5 AE!
YaBB Forum Software © 2000-2010. All Rights Reserved.