Digital pins strange behaviour

I have 5 LEDs connected to 5 digital pins 2 to 6. I want to send via serial port a string of a combination of 5 characters “0” or “1” to turn on a combination of the 5 LEDs for a given time duration. Sending “00001” would turn LED1, “00010” LED2, etc or combinations like “10101” for LED1, LED3, and LED5 for example.

Many strange things happen:

LED5 is never turned on. I had to add LED6 to have LED5 working Pins 2 to 6 are connected but I had to initialize them as 1 to 5. If I initialize them as 2 to 6, LED1 doses not work. After the time delay, I set all 5 pins to LOW, but when sending the next combination string the pious pins a still high for a fraction of second, and this is annoying for my application.

Any help? Thank you

Your finger array has 6 entries, namely 0 through 5. You are accessing index 6, which does not belong to the array (5 is the last element).

char finger[6];
// ...
if (finger[6] == '1')

Scherady: I have 5 LEDs connected to 5 digital pins 2 to 6.

Not according to the code you attached

// Initializing pin numbers
int P1_OUT = 1; // Pin 2
int P2_OUT = 2; // Pin 3
int P3_OUT = 3; // Pin 4
int P4_OUT = 4; // Pin 5
int P5_OUT = 5; // Pin 6
int P6_OUT = 6; // Pin 7

Your comments do not match the actual pin assignments. You are using pins 1 through 6. Pin 1 is used as the TX pin for serial communication so you should not use that pin.

Also, wrong comments are worse than no comments in your code. Always adjust your comments when you change your code.

Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.,148850.0.html . Then look down to item #7 about how to post your code.Hi It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :)

Thank you LightuC, you are right index 6 is out of the range of finger[6] but that was not the problem.

After further investigation, I was able to solve the problem by properly handling and properly parsing the data read from the serial buffer.

Hi, Can you please post your final code, so it will make this thread complete for any other user that could use your information?

Thanks.. Tom... :)