Go Down

Topic: Why does "for" not work (Read 1 time) previous topic - next topic

KenH

#5
Feb 17, 2010, 05:29 am Last Edit: Feb 17, 2010, 05:32 am by KenH Reason: 1
@BrettW - THANK YOU!!  That did the trick.  I did not realize what I had to do that - put the clear statement just before. I will try to remember that.  I have been having to fudge things for the last while to make the analog inputs read correctly for the last couple of projects I have done.  Thank you.

@Coding Badly: Thank you for making the clear statement clear with your example.  
Also of great interest is your comment on "pin 5" is something I've been wondering about for a long time (weeks) - how does the Arduino IDE know if a pin assignment is "pin 5 - Analog (m168 pin 28)" or pin 5 - digital (m168 pin 11)"?

I work with the m168 pins and have to refer to a the Arduino pin mapping to help keep pins straight. Most of my projects use a home etched PCB with the m168 installed.

Can you - or anyone - shed light on how the IDE keeps those pins straight?

AND a BIG THANK YOU to all the folks who make this a GREAT group.

Ken H>

Coding Badly

Quote
how does the Arduino IDE know if a pin assignment is "pin 5 - Analog (m168 pin 28)" or pin 5

It's the set of functions you use.  pinMode, digitalRead, and digitalWrite refer to digital pins.  analogRead refers to analog pins.  

The two spaces overlap.  There's a digital pin 5 and an analog pin 5 but they're not the same physical pin.

Quote
Can you - or anyone - shed light on how the IDE keeps those pins straight?

For digital pins, there's a pair of mapping functions / tables in the library.  One map is used to determine the port.  The other map determines the bit on the port.

I have no idea how analog pins are mapped to physical pins.

trialex

You don't need to do a pinMode for the analog in pins.

By using the analogRead() command that is enough for it to know that you want to use the analog pins.


KenH

Thanks to both of ya'll for helping me understand.  I'll go back and remove all those pinModes from my code for analog inputs.  Darn, there is so much to this stuff.  Just when I think I'm starting to learn some....  

Ya'll all help a LOT!!!

Ken H>

KenH

I think I understand the problem even better now - I had set voltraw to zero, but it was in teh first section (declarations?) of the sketch where I have the "int voltraw = 0;" and this ran only one time at start of sketch.

The "voltraw = 0" has to be declared in the loop section so it gets reset to zero EACH time thru the loop.  There is no real need to use the "int voltraw = 0;" in the first section, just in the loop section of code.

Should I have just used "int voltraw = 0;" in the first section of the "for" statement and not put at all in the declaration section at the beginning?  OR is it better declare the "int voltraw = 0;" in the declaration section to run one time, then in the "for" statement in the loop section put the "voltraw = 0:" so it clears each time the program loops?

Thanks again for all the help.

ken H.

Go Up