Single Digit Seven Segment Display Code Question COMMON ANODE

I made a previous post, but I now have things thought out a little more. I know pins 1 and 6 are the anodes and 2,3,4,5,7,8,9,10 Cathodes. Since it is common Anode 7 segment display I used digitalWrite sketching <lol Sketching. I wrote this code:

//All pins on Segment directly convert over to Arduino pins i.e 1=1
int LEDpin1= 1;
int LEDpin2= 2;
int LEDpin3= 3;
int LEDpin4= 4;
int LEDpin5= 5;
int LEDpin6= 6;
int LEDpin7= 7;
int LEDpin8= 8;
int LEDpin9= 9;
int LEDpin10= 10;

void setup ()
{
pinMode(LEDpin1,OUTPUT);//Green Anode
pinMode(LEDpin2,OUTPUT);
pinMode(LEDpin3,OUTPUT);
pinMode(LEDpin4,OUTPUT);
pinMode(LEDpin5,OUTPUT);
pinMode(LEDpin6,OUTPUT);//Red Anode
pinMode(LEDpin7,OUTPUT);
pinMode(LEDpin8,OUTPUT);
pinMode(LEDpin9,OUTPUT);
pinMode(LEDpin10,OUTPUT);
}
void loop ()
{
//DISPLAY #1
digitalWrite(LEDpin8,LOW); //Display #1
digitalWrite(LEDpin9,LOW); //Cathodes LOW for GND ON
digitalWrite(LEDpin1,HIGH); //Anode HIGH for 5V   ON
delay(1000);// Delay 1 sec 
//#1 OFF                                                                                    
digitalWrite(LEDpin8,HIGH);//Cathode HIGH for OFF or 5V
digitalWrite(LEDpin9,HIGH);
digitalWrite(LEDpin1,LOW);// Anode LOW for OFF or GND
delay(1000);//Delay 1 sec
//DISPLAY #2
digitalWrite(LEDpin3,LOW);//Display #2                             
digitalWrite(LEDpin4,LOW);//pins 3-10 cathodes
digitalWrite(LEDpin5,LOW);
digitalWrite(LEDpin9,LOW);
digitalWrite(LEDpin10,LOW);
digitalWrite(LEDpin1,HIGH);// pin 1 Anode
delay(1000);
//#2 OFF
digitalWrite(LEDpin3,HIGH);// #2 OFF again
digitalWrite(LEDpin4,HIGH);
digitalWrite(LEDpin5,HIGH);
digitalWrite(LEDpin9,HIGH);
digitalWrite(LEDpin10,HIGH);
digitalWrite(LEDpin1,LOW);
delay(1000);

//DISPLAY #3
digitalWrite(LEDpin3,LOW);
digitalWrite(LEDpin5,LOW);
digitalWrite(LEDpin8,LOW);
digitalWrite(LEDpin9,LOW);
digitalWrite(LEDpin10,LOW);
digitalWrite(LEDpin1,HIGH);
delay(1000);

//#3 OFF
digitalWrite(LEDpin3,HIGH);
digitalWrite(LEDpin5,HIGH);
digitalWrite(LEDpin8,HIGH);
digitalWrite(LEDpin9,HIGH);
digitalWrite(LEDpin10,HIGH);
digitalWrite(LEDpin1,LOW);
delay(1000);

//DISPLAY #4
digitalWrite(LEDpin2,LOW);
digitalWrite(LEDpin3,LOW);
digitalWrite(LEDpin8,LOW);
digitalWrite(LEDpin9,LOW);
digitalWrite(LEDpin1,HIGH);
delay(1000);

//#4 OFF
digitalWrite(LEDpin2,HIGH);
digitalWrite(LEDpin3,HIGH);
digitalWrite(LEDpin8,HIGH);
digitalWrite(LEDpin9,HIGH);
digitalWrite(LEDpin1,LOW);
delay(1000);

}

I spent some time thinking this over.SO I believe this sketch is the best way(I know) to achieve my goal of displaying various characters. Though i’m sure it’s very inefficient, I also believe this is the only way to do this, RIGHT???Because Common Anode type 7 Seg’s aren’t as common. MY FEAR IS IT WILL SHORT, After it displays #1 and moves on through the loop, the cathodes that are not being GND’d to light up, will short! BUT IT IS A DIODE ALSO RIGHT?? SO it shouldn’t short in theory right???Making this an effective way to do this RIGHT?? I am NO expert and have only been into Electronics for 9 months or less. ANYONE who is an Expert/ Engineer or just plain smarter in the field then I am at the moment, Please HELP I MUCH APPRECIATE IT!!!

Anyone Got an IDEA????? I am desperate to try my salvaged 7 SEG. Yet scared I dont want to fry my NANO

A little basic electronics for you.

Common anode goes to the +Ve supply and your sketch should take the cathodes to earth via a current limiting resistor of around 100ohms. This will limit the current into the arduino to a safe level. As each output pin is taken low, the segment will be turned on.

To turn it off the pin is taken high. If you have one pin high and another pin low, there is no danger of short as the high segment is a reverse biased diode so no current can flow.

I have not commented on the code just the display.

Weedpharma

Did you even read my answer to your previous question?

Did you even read my answer to your previous question?

Sorry it wasn't YOUR question :blush:

@weedpharma I am NO noob! You are trying to speak like I am a noob, but its more like a mirror situation. If have no Idea how to answer my question, please dont! I am well aware Normally an anode would go to Vcc or 5V, BUT i have two anodes 1 for green 1 for red so I want to control them seperatly, which is why it has to be done this way. And as far as this ken fool he has been trolling all my posts, but never is helpful.

BUT i have two anodes 1 for green 1 for red so I want to control them seperatly, which is why it has to be done this way.

You can not do it this way because the arduino will not be able to supply enough current to the anode pin to power all the segments. You need a transistor to power the anode, normally a PNP one.

Also code without a schematic is useless we need to see how you have wired things up. That code is very poor. Learn to use functions. Write a function to turn all segments off and call it when you are done with a display.

I am NO noob!

Sorry but yes you are, if you are asking this sort of question. It is nothing to be ashamed about we all have to learn.

Willyboielectro:
@weedpharma I am NO noob! You are trying to speak like I am a noob, but its more like a mirror situation. If have no Idea how to answer my question, please dont! I am well aware Normally an anode would go to Vcc or 5V, BUT i have two anodes 1 for green 1 for red so I want to control them seperatly, which is why it has to be done this way. And as far as this ken fool he has been trolling all my posts, but never is helpful.

Willyboielectro:
I made a previous post, but I now have things thought out a little more. I know pins 1 and 6 are the anodes and 2,3,4,5,7,8,9,10 Cathodes. Since it is common Anode 7 segment display I used digitalWrite sketching <lol Sketching. I wrote this code:

//All pins on Segment directly convert over to Arduino pins i.e 1=1

int LEDpin1= 1;
int LEDpin2= 2;
int LEDpin3= 3;
int LEDpin4= 4;
int LEDpin5= 5;
int LEDpin6= 6;
int LEDpin7= 7;
int LEDpin8= 8;
int LEDpin9= 9;
int LEDpin10= 10;

void setup ()
{
pinMode(LEDpin1,OUTPUT);//Green Anode
pinMode(LEDpin2,OUTPUT);
pinMode(LEDpin3,OUTPUT);
pinMode(LEDpin4,OUTPUT);
pinMode(LEDpin5,OUTPUT);
pinMode(LEDpin6,OUTPUT);//Red Anode
pinMode(LEDpin7,OUTPUT);
pinMode(LEDpin8,OUTPUT);
pinMode(LEDpin9,OUTPUT);
pinMode(LEDpin10,OUTPUT);
}
void loop ()
{
//DISPLAY #1
digitalWrite(LEDpin8,LOW); //Display #1
digitalWrite(LEDpin9,LOW); //Cathodes LOW for GND ON
digitalWrite(LEDpin1,HIGH); //Anode HIGH for 5V   ON
delay(1000);// Delay 1 sec
//#1 OFF                                                                                    
digitalWrite(LEDpin8,HIGH);//Cathode HIGH for OFF or 5V
digitalWrite(LEDpin9,HIGH);
digitalWrite(LEDpin1,LOW);// Anode LOW for OFF or GND
delay(1000);//Delay 1 sec
//DISPLAY #2
digitalWrite(LEDpin3,LOW);//Display #2                            
digitalWrite(LEDpin4,LOW);//pins 3-10 cathodes
digitalWrite(LEDpin5,LOW);
digitalWrite(LEDpin9,LOW);
digitalWrite(LEDpin10,LOW);
digitalWrite(LEDpin1,HIGH);// pin 1 Anode
delay(1000);
//#2 OFF
digitalWrite(LEDpin3,HIGH);// #2 OFF again
digitalWrite(LEDpin4,HIGH);
digitalWrite(LEDpin5,HIGH);
digitalWrite(LEDpin9,HIGH);
digitalWrite(LEDpin10,HIGH);
digitalWrite(LEDpin1,LOW);
delay(1000);

//DISPLAY #3
digitalWrite(LEDpin3,LOW);
digitalWrite(LEDpin5,LOW);
digitalWrite(LEDpin8,LOW);
digitalWrite(LEDpin9,LOW);
digitalWrite(LEDpin10,LOW);
digitalWrite(LEDpin1,HIGH);
delay(1000);

//#3 OFF
digitalWrite(LEDpin3,HIGH);
digitalWrite(LEDpin5,HIGH);
digitalWrite(LEDpin8,HIGH);
digitalWrite(LEDpin9,HIGH);
digitalWrite(LEDpin10,HIGH);
digitalWrite(LEDpin1,LOW);
delay(1000);

//DISPLAY #4
digitalWrite(LEDpin2,LOW);
digitalWrite(LEDpin3,LOW);
digitalWrite(LEDpin8,LOW);
digitalWrite(LEDpin9,LOW);
digitalWrite(LEDpin1,HIGH);
delay(1000);

//#4 OFF
digitalWrite(LEDpin2,HIGH);
digitalWrite(LEDpin3,HIGH);
digitalWrite(LEDpin8,HIGH);
digitalWrite(LEDpin9,HIGH);
digitalWrite(LEDpin1,LOW);
delay(1000);

}


I spent some time thinking this over.SO I believe this sketch is the best way(I know) to achieve my goal of displaying various characters. Though i'm sure it's very inefficient, I also believe this is the only way to do this, RIGHT???Because Common Anode type 7 Seg's aren't as common. MY FEAR IS IT WILL SHORT, After it displays #1 and moves on through the loop, the cathodes that are not being GND'd to light up, will short! BUT IT IS A DIODE ALSO RIGHT?? SO it shouldn't short in theory right????Making this an effective way to do this RIGHT?? I am NO expert and have only been into Electronics for 9 months or less. ANYONE who is an Expert/ Engineer or just plain smarter in the field then I am at the moment, Please HELP I MUCH APPRECIATE IT!!!!!

What part of “I am NO expert…” Tells me you are an expert???
Am I also supposed to troll through all your other threads to find out your display is two colours and not simply two pins connected togerher??

You ask for assistance then flame anyone that offers this assistance!!

Next time give all the information in one post then accept graciously any help offered.

Weedpharma