I designed a circuit board to toggle my LED ceiling lights, using Arduino Nano & transistor array IC. My hardware circuitry works fine. I just want to toggle output of these pins, should be a simple project. I planned to use pins A0 - A6. So I took this opportunity to play with direct port manipulation, and can't figure out what my malfunction is.
I can toggle A0 - A5! A6? That pin will not toggle. All I need now is that 6th pin for my 6th light - and I can go on with my project, but NO - I'm presented with a nice scavenger hunt for information instead...
A6 does not want to cooperate with my whole "PORTC" manipulation. Here's some sample code (the whole program is cluttered and I do not want to confuse anyone)
void setup()
{
//port maniupulation
DDRC = B11111111; // set all pins on portc as output
}
void loop()
{
for (int iTemp = 0; iTemp < 16;iTemp++)
{
PORTC = 0b11111111;
delay(128);
PORTC = 0b00000000;
delay(128);
}
I tried to read up on this on my own and got confused, and the answer might be obvious - I probably need just a push to help me understand whats going on.
Are pins A6 and A7 ONLY INPUT ? yes / no? Are A6 & A7 in PORTC? If those last two bits on PORTC are not assigned to A6 & A7, what pins are they assigned to ?
On the Uno portB has 6 pins, port C has 6 pins, only port D has 8 pins and 2 of those are hardware
serial. If you want to drive 7 or 8 pins from one port you will have an issue...
The way the Nano was laid out I just ran 7 wires from a0-a5 to the transistor array was easy. No, I do not specifically need to use those pins only - but I've already had everything designed in Eagle so, it's a big mess if I have to run 7 wires from the other side of the board.
But according to what I read here now, I can't get 7 output wires on ANY port. Actually, I only have 6 actual LEDs in the ceiling lights and 1 output was a spare I'm not using.
I can see from the layout, that PORTB is has pins 9 and 10, which I use for AltSoftSerial. lol. This figures, no matter what I choose I'm going to have to sacrifice something that completely defies the design of what I planned out.
My idea was to make an array of numbers, so that I can animate the 6 lights to spin around in a circle and do fun disco stuff. I just store 8-bit int's into an array, and easily assign PORTC=ledArray[iTemp] - and be done with it.
Actually, to be precise I should point out that port B does have 8 pins, but only if you configure
internal RC clock and thus have the two Xtal pins available for general use...
Are using port expanders out of the question? A '595 on SPI or PCF8574 on I2C will give you a full 8 bit port. Since you are toggling LEDs port speed shouldn't be an issue.
Or upgrade your project to a Mega, which has several 8 bit ports available.
This is intended to be a small light device that is simple. Thank you for the complex suggestions, the information is useful.
I actually have enough pins, I just counted 6, again. I have 6 led lights I want to use. The 7th is just a spare channel on transister array. I have attached esp8266, and that is all the complexity i want to get into.
After this lesson, I learned is better for me to have 1 or more spare pins / channels instead of using up everything with no room for me to change my mind or upgrade.