Buy an Axon, Axon II, or Axon Mote and build a great robot, while helping to support SoR.
0 Members and 1 Guest are viewing this topic.
DDRD|=(1<<PORTD7);
PORTD &= ~(1<<7);
DDRB solely changes whether a pin is output or input, it does not change the state.PORTB solely changes the state of the pin (either HIGH or LOW)So, to turn the LED on, you need to set the pin to output, then change the state of the pin to whatever turns it on (depends on how you wired it).
PIND is the register to read the state of pins, PORTD is the register to output things on pins
DDRD|=(1<<PORTD7); PORTD|=(1<<7);
The cathode on an LED is the + end right? Therefore it's the longer end? I have the longer end connected to pin D7.
But but but... cations (in chemistry) are positive... oooo a cathode is named because cations migrate toward it... wow I feel dumb now...
Quote from: Razor Concepts on April 17, 2010, 02:56:14 PMDDRB solely changes whether a pin is output or input, it does not change the state.PORTB solely changes the state of the pin (either HIGH or LOW)So, to turn the LED on, you need to set the pin to output, then change the state of the pin to whatever turns it on (depends on how you wired it).OOOOOOOOOOOOOOOOOOOOOOOOO... I KNEW there had to be something like that. Hmmm, now what exactly does the second snippet of code do that I have written above? In the SoR-utilities it says it turns the port OFF. Why does that turn the led ON?EDIT: I see, there are three registers for portB or C or D. There is DDRD, PORTD, and PIND. I see what DDRD and PORT do, but what does PIN do? I remember reading this somewhere, but I can't remember exactly. I kind of glazed over it...EDIT: Oh and the reason is wasn't working when I used the photovore program... I had the wiring shifted one row up on the breadboard :oops:
PIND is the register used to read the value of port D.PORTD &= ~(1<<7); sets port D pin 7 to 0. This turns on the LED because it grounds the LED's negative pin (cathode).
I have the longer end connected to pin D7.
Quote from: tim_wang on April 17, 2010, 08:54:24 PMPIND is the register used to read the value of port D.PORTD &= ~(1<<7); sets port D pin 7 to 0. This turns on the LED because it grounds the LED's negative pin (cathode).But the annode was connected to D7?QuoteI have the longer end connected to pin D7. Corrado33, where did you have the other end of the led connected to?
You should NOT connect the anode (longer wire) to port d pin 7 because the microcontroller pins can only source (provide) a tiny amount of current. While this tiny amount of current was able to power 1 LED, it would fail if connected to a bank of LEDs in parallel, or other more power hungry devices.
Quote from: tim_wang on April 18, 2010, 12:23:19 AMYou should NOT connect the anode (longer wire) to port d pin 7 because the microcontroller pins can only source (provide) a tiny amount of current. While this tiny amount of current was able to power 1 LED, it would fail if connected to a bank of LEDs in parallel, or other more power hungry devices.Well, technically these AVRs can both sink and source the same amount of current. It is just recommended to sink instead of source so that the AVR chip doesn't have to provide current.
Well that is true, but I never said the microcontroller I/O pins can sink more current than it can source.
So, buy setting the port LOW, i'm letting current flow from the battery, therefore letting the led light? What happens when it's HIGH? Isn't that basically putting a battery (or at least a voltage source) on both sides of the LED? I can't see that being good?
Perhaps other users may suggest a 'beginners guide to electronics'