variable voltage using pot to 7 seg display

Hey guys first time posting. I am trying to build an led testing circuit and need help with the coding. first off using arduino micro and 2 individual 7 segment displays from radioshack. I have used 2 existing written code to test the individual components. the variable voltage to serial using a pot that comes with the software (ReadAnalogVoltage), works great. For the 7 segment I downloaded a counting one see below.
int pin1 = 2;
int pin2 = 3; // --6--
int pin3 = 4; // 5 | | 7
int pin4 = 5; // |--4--|
int pin5 = 6; // 1 | | 3
int pin6 = 7; // --2--
int pin7 = 8;
int gnd1 = 11; // gnd1 is display 1's gnd
int gnd2 = 9; // gnd2 is display 2's gnd
int timer = 50; // A timer, to run the for loop 10 times, which turns out as 1 second.
int value; // The value, part of the FADING display

void setup(){
pinMode(pin1, OUTPUT);
pinMode(pin2, OUTPUT);
pinMode(pin3, OUTPUT);
pinMode(pin4, OUTPUT); //The following sets up all of the pins for use.
pinMode(pin5, OUTPUT);
pinMode(pin6, OUTPUT);
pinMode(pin7, OUTPUT);
pinMode(gnd1, OUTPUT);
pinMode(gnd2, OUTPUT);

This works I just want to combine the 2 kinda so that the voltage writes to the display instead of serial.

!!! pin 9 and 11
each led 10mA ? (if serial 220R each segment)
Dont push the 40mA limit (also read datasheet on total current - all pins)

U write the two digita alternating to segments. (switching 9 11 )
do this 100x/sec.
Light intesity will degrade - Reduse R (a little) - or add registers with latch. (many choices available)

Couple things:
Set up your segments in the standard way:
a
f b
g
e c
d DP

and have the fonts defined to turn on the digits
byte fontArray = {
0b00111111, // 0, turns on segments f-e-d-c-b-a
0b00000110, // 1, c-b are on
0b01011011, // 2, g-e-d-b-a are on
0b01001111, // 3, g-d-c-b-a
// etc. up thryu 9

Also, have a segment mask array, this will determine which segment gets turned on
byte segmentMask = {
0b00000001, // a
0b00000010, // b
0b00000100, // c
0b00001000, // d
0b00010000, // e
0b00100000, // f
0b01000000, // g
0b10000000, }; // DP

Then have a byte for each segment:
byte digit0;
byte digit1;

and put the pins used for the segment into an array
byte pinArray = {9,8,7,6,5,4,3,2,}; // the segment IO pins you listed, from DP-g-f-e-d-c-b-a
(this order may need adjusting) for the anodes of the display

Next write a multiplexing loop that enables 1 GND and 1 Segment, leave a segment on for 1mS, then move on to the next one. That way all segments are refreshed every 14mS for 70+Hz refresh rate, will be bright & flicker free as up to 20mA can sourced into each segment. Use blink without delay style programming.

void loop(){
// first 4 lines here are the heart of blink without delay
currentMillis = millis(); // all time elements are type unsigned long
elapsedMillis = currentMillis - previousMillis;
if (elapsedMillis >= 1mS){
previousMillis = previousMillis + 1mS;

// ok, 1 mS has passed turn off the prior segment and turn on the next one.
// written as a loop within a loop - outer loop is the digit select, inner loop is the segment select
// but - loop counters are seperately tracked (vs using a for loop) so the count can be mixed with the time tracking:

// turn off prior segment (whether it was on or off)

digitalWrite (pinArray[segmentCount], LOW);
digitalWrite (gnd1, HIGH); // whatever you called those
digitalWrite (gnd2, HIGH);

// update the segment to be updated 
segmentCount = segmentCount +1; 
if (segmentCount == 8){ // or 7 if not using Decimal Point
segmentCount = 0; // reset to initial segment - the "inner loop"
digitCount = digitCount + 1;
if (digitCount == 2){
digitCount = 0; // reset to initial digit - the "outer loop"
  }
}
// now, the segment to light up in a digit has been selected.
// look up the font for the byte to be displayed,
// mask off the value of a particular segment, and turn it on if it's a 1:
if (digitCount == 0){ // first digit
if ( (segmentMask[segmentCount] & fontArray[byte0]) >0){ 
// so if segmentCount == 3, segmentMask[3] will be 0b00001000
// and if byte0 = 3, then fontArray[3] = 0b01001111, the & will result on 0b00001000, 
// which is >0, (just looking for 0 or not 0; and >0 is same as not 0) so turn on segment D
digitalWrite (pinArray[segmentCount], HIGH);
// and turn the Gnd back on
digitalWrite (gnd1, LOW);
  }
 }
// if not the first digit, must be the 2nd
else{ // digitCount ==1
if ( (segmentMask[segmentCount] & fontArray[byte1]) >0){ 
// so if segmentCount == 3, segmentMask[3] will be 0b00001000
// and if byte0 = 3, then fontArray[3] = 0b01001111, the & will result on 0b00001000, 
// so turn on segment D
digitalWrite (pinArray[segmentCount], HIGH);
// and turn the Gnd back on
digitalWrite (gnd1, LOW);
  }
 }
}
// now do whatever else you're doing for remainder of 1mS until the next update time
} // end loop

I think that covers it all - got blink without delay, got an array to look up fonts, got an array to look up the segment to turn on.
Take out all the comments, makes a nice little loop.

Duplicate post deleted - Don’t post the same thing numerous times!

mind blown first off thank you. I'm trying to wrap my brain around this. I keep getting these errors
led_testing:55: error: expected unqualified-id before '{' token
led_testing:61: error: expected constructor, destructor, or type conversion before '=' token
led_testing:62: error: expected unqualified-id before 'if'

this is what i got

[quote]
#define G  5
#define F  6
#define A  7
#define B  8
#define E  2
#define D  3
#define C  4
#define DP  10
#define gnd_1  11                           
#define gnd_2  9   

[color=#CC6600]int[/color] currentMillis = 1;
[color=#CC6600]int[/color] elapsedMillis = 1;
[color=#CC6600]int[/color] previousMillis = 1;

[color=#CC6600]byte[/color] fontArray[] = {
0b00111111, [color=#7E7E7E]// 0, turns on segments f-e-d-c-b-a[/color]
0b00000110, [color=#7E7E7E]// 1, c-b are on[/color]
0b01011011, [color=#7E7E7E]// 2, g-e-d-b-a are on[/color]
0b01001111, [color=#7E7E7E]// 3, g-d-c-b-a[/color]
0b01100110, [color=#7E7E7E]// 4[/color]
0b01101101, [color=#7E7E7E]// 5[/color]
0b01111100, [color=#7E7E7E]// 6[/color]
0b00100111, [color=#7E7E7E]// 7[/color]
0b01111111, [color=#7E7E7E]// 8[/color]
0b01100111,};[color=#7E7E7E]// 9[/color]

[color=#CC6600]byte[/color] segmentMask[] = { 
0b00000001, [color=#7E7E7E]// a[/color]
0b00000010, [color=#7E7E7E]// b[/color]
0b00000100, [color=#7E7E7E]// c[/color]
0b00001000, [color=#7E7E7E]// d[/color]
0b00010000, [color=#7E7E7E]// e[/color]
0b00100000,  [color=#7E7E7E]// f[/color]
0b01000000,  [color=#7E7E7E]// g[/color]
0b10000000,}; [color=#7E7E7E]// DP[/color]

[color=#CC6600]byte[/color] digit0;
[color=#CC6600]byte[/color] digit1; 

[color=#CC6600]byte[/color] pinArray[] = {10/5/6/2/3/4/8/7}
;
[color=#CC6600]void[/color] [color=#CC6600][b]loop[/b][/color](){
[color=#7E7E7E]// first 4 lines here are the heart of blink without delay[/color]
currentMillis = [color=#CC6600]millis[/color](); [color=#7E7E7E]// all time elements are type unsigned long[/color]
elapsedMillis = currentMillis - previousMillis;
[color=#CC6600]if[/color] (elapsedMillis >= 1)
previousMillis = previousMillis + 1;}

[color=#7E7E7E]// ok, 1 mS has passed turn off the prior segment and turn on the next one.[/color]
[color=#7E7E7E]// written as a loop within a loop - outer loop is the digit select, inner loop is the segment select[/color]
[color=#7E7E7E]// but - loop counters are seperately tracked (vs using a for loop) so the count can be mixed with the time tracking:[/color]

[color=#7E7E7E]// turn off prior segment (whether it was on or off)[/color]

[color=#CC6600]digitalWrite[/color] (pinArray[8], [color=#006699]LOW[/color]);
[color=#CC6600]digitalWrite[/color] (gnd_1, [color=#006699]HIGH[/color]); [color=#7E7E7E]// whatever you called those[/color]
[color=#CC6600]digitalWrite[/color] (gnd_2, [color=#006699]HIGH[/color]);
}
 
segmentCount = segmentCount +1; 
[color=#CC6600]if[/color] (segmentCount == 8){ [color=#7E7E7E]// or 7 if not using Decimal Point[/color]
segmentCount = 0; [color=#7E7E7E]// reset to initial segment - the "inner loop"[/color]
digitCount = digitCount + 1;
[color=#CC6600]if[/color] (digitCount == 2){
digitCount = 0; [color=#7E7E7E]// reset to initial digit - the "outer loop"[/color]
  }
}
[color=#7E7E7E]// now, the segment to light up in a digit has been selected.[/color]
[color=#7E7E7E]// look up the font for the byte to be displayed,[/color]
[color=#7E7E7E]// mask off the value of a particular segment, and turn it on if it's a 1:[/color]
[color=#CC6600]if[/color] (digitCount == 0){ [color=#7E7E7E]// first digit[/color]
[color=#CC6600]if[/color] ( (segmentMask[segmentCount] & fontArray[byte0]) >0){ 
[color=#7E7E7E]// so if segmentCount == 3, segmentMask[3] will be 0b00001000[/color]
[color=#7E7E7E]// and if byte0 = 3, then fontArray[3] = 0b01001111, the & will result on 0b00001000, [/color]
[color=#7E7E7E]// which is >0, (just looking for 0 or not 0; and >0 is same as not 0) so turn on segment D[/color]
[color=#CC6600]digitalWrite[/color] (pinArray[segmentCount], [color=#006699]HIGH[/color]);
[color=#7E7E7E]// and turn the Gnd back on[/color]
[color=#CC6600]digitalWrite[/color] (gnd_1, [color=#006699]LOW[/color]);
  }
 }
[color=#7E7E7E]// if not the first digit, must be the 2nd[/color]
[color=#CC6600]else[/color]{ [color=#7E7E7E]// digitCount ==1[/color]
[color=#CC6600]if[/color] ( (segmentMask[segmentCount] & fontArray[byte1]) >0){ 
[color=#7E7E7E]// so if segmentCount == 3, segmentMask[3] will be 0b00001000[/color]
[color=#7E7E7E]// and if byte0 = 3, then fontArray[3] = 0b01001111, the & will result on 0b00001000, [/color]
[color=#7E7E7E]// so turn on segment D[/color]
[color=#CC6600]digitalWrite[/color] (pinArray[segmentCount], [color=#006699]HIGH[/color]);
[color=#7E7E7E]// and turn the Gnd back on[/color]
[color=#CC6600]digitalWrite[/color] (gnd_1, [color=#006699]LOW[/color]);
  }
 }
}
[color=#7E7E7E]// now do whatever else you're doing for remainder of 1mS until the next update time[/color]
} [color=#7E7E7E]// end loop[/color]

[/quote]

I there a certain number i use in the [segmentCount] sections like 8 or does it change on the if statements like "if ( (segmentMask[segmentCount] & fontArray[byte1]) >0){ "

I appreciate the help

Modify your post please. Delete the code, and re-post it using straight copy & paste
(CTRL-A to highlight, CTRL-C to copy it, CTRL-V to paste it) using the # button (code tags).
The "copy for forum" is not reviewable, too much just inserted. I wish they'd delete it from the forum.

The stuff I wrote is not the complete code, it needs to be fleshed out fully to work. Might need to have things like { } and and ( ) cleaned up. Needs variable types declared, etc.

segmentCount will cycle thru from 0 to 7 and then reset to 0.

#define G 5
#define F 6
#define A 7
#define B 8
#define E 2
#define D 3
#define C 4
#define DP 10
#define gnd_1 11
#define gnd_2 9

int currentMillis = 1;
int elapsedMillis = 1;
int previousMillis = 1;

byte fontArray = {
0b00111111, // 0, turns on segments f-e-d-c-b-a
0b00000110, // 1, c-b are on
0b01011011, // 2, g-e-d-b-a are on
0b01001111, // 3, g-d-c-b-a
0b01100110, // 4
0b01101101, // 5
0b01111100, // 6
0b00100111, // 7
0b01111111, // 8
0b01100111,};// 9

byte segmentMask = {
0b00000001, // a
0b00000010, // b
0b00000100, // c
0b00001000, // d
0b00010000, // e
0b00100000, // f
0b01000000, // g
0b10000000,}; // DP

byte digit0;
byte digit1;

byte pinArray = {10/5/6/2/3/4/8/7}
;
void loop(){
// first 4 lines here are the heart of blink without delay
currentMillis = millis(); // all time elements are type unsigned long
elapsedMillis = currentMillis - previousMillis;
if (elapsedMillis >= 1)
previousMillis = previousMillis + 1;}

// ok, 1 mS has passed turn off the prior segment and turn on the next one.
// written as a loop within a loop - outer loop is the digit select, inner loop is the segment select
// but - loop counters are seperately tracked (vs using a for loop) so the count can be mixed with the time tracking:

// turn off prior segment (whether it was on or off)

digitalWrite (pinArray[8], LOW);
digitalWrite (gnd_1, HIGH); // whatever you called those
digitalWrite (gnd_2, HIGH);
}

segmentCount = segmentCount +1;
if (segmentCount == 8){ // or 7 if not using Decimal Point
segmentCount = 0; // reset to initial segment - the "inner loop"
digitCount = digitCount + 1;
if (digitCount == 2){
digitCount = 0; // reset to initial digit - the "outer loop"
}
}
// now, the segment to light up in a digit has been selected.
// look up the font for the byte to be displayed,
// mask off the value of a particular segment, and turn it on if it's a 1:
if (digitCount == 0){ // first digit
if ( (segmentMask[segmentCount] & fontArray[byte0]) >0){
// so if segmentCount == 3, segmentMask[3] will be 0b00001000
// and if byte0 = 3, then fontArray[3] = 0b01001111, the & will result on 0b00001000,
// which is >0, (just looking for 0 or not 0; and >0 is same as not 0) so turn on segment D
digitalWrite (pinArray[segmentCount], HIGH);
// and turn the Gnd back on
digitalWrite (gnd_1, LOW);
}
}
// if not the first digit, must be the 2nd
else{ // digitCount ==1
if ( (segmentMask[segmentCount] & fontArray[byte1]) >0){
// so if segmentCount == 3, segmentMask[3] will be 0b00001000
// and if byte0 = 3, then fontArray[3] = 0b01001111, the & will result on 0b00001000,
// so turn on segment D
digitalWrite (pinArray[segmentCount], HIGH);
// and turn the Gnd back on
digitalWrite (gnd_1, LOW);
}
}
}
// now do whatever else you're doing for remainder of 1mS until the next update time
} // end loop