# Can I have help in finishing the variables?

**URL:** <https://forum.fritzing.org/t/can-i-have-help-in-finishing-the-variables/3190>\
**Category:** uncategorized\
**Created:** [March 2, 2017, 1:37am UTC](https://forum.fritzing.org/t/can-i-have-help-in-finishing-the-variables/3190 "2017-03-02T01:37:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MashCaup](https://forum.fritzing.org/letter_avatar_proxy/v4/letter/m/eb9ed0/32.png) [@MashCaup](https://forum.fritzing.org/u/MashCaup)\
**Post date:** [March 2, 2017, 1:37am UTC](https://forum.fritzing.org/t/can-i-have-help-in-finishing-the-variables/3190/1 "2017-03-02T01:37:52Z")

</div>

byte fontArray[] = {  
0b00111111, // 0 DP-g-f-e-d-c-b-a, 1 = segment on  
0b00000110, // 1  
0b01011011, // 2  
0b01001111,  
0b01100110,  
0b01101101,  
0b01111101,  
0b00000111,  
0b01111111,  
0b01101111, // 9  
};  
unsigned long currentMillis=millis();  
unsigned long previousMillis=0;  
unsigned long elapsedMillis=currentMillis-previousMillis;  
long onDuration=3000;  
unsigned char digitDrive[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67};  
int digitPin=13;

void setup(){

}

void loop(){  
currentMillis = millis(); // all time elements are type unsigned long, declare before setup()  
elapsedMillis = currentMillis - previousMillis;  
if (elapsedMillis \>= onDuration){ // onDuration set for 2, 3 whatever you use, up to about 8 for 30Hz refresh  
previousMillis = previousMillis + onDuration; // set up for next interval  
// turn off current digit drive transistor, assume using pins 15-14-13-12, set up in an array:  
digitalWrite (digitPin[digitDrive], LOW);  
digitDrive = digitDrive[10] + 1; // point to next digit  
if (digitDrive == 4){ digitDrive = 0;} // reset to initial digit  
// assume you’re using 4 bits of PORTD and 4 bits of PORTB: 7-6-5-4, and 11-10-9-8, for DP-g-f-e, d-c-b-a  
// and data is stored in an array  
// clear lower 4 bits of PORTB  
PORTB = PORTB & 0b11110000;  
// look up the font (segment mapping), mask off lower 4 bits of data, OR into output register  
PORTB = PORTB | (fontArray[dataArray[digitDrive]] & 0b00001111);  
// clear upper 4 bits of PORTD,  
// look up the font (segment mapping), mask off upper 4 bits of data, OR into output register  
PORTD = PORTD & 0b00001111;  
PORTD = PORTD | (fontArray[dataArray[digitDrive]] & 0b11110000);  
// turn on the transistor for the current data  
digitalWrite (digitPin[digitDrive], HIGH);  
}  
// do whatever you do to update dataArray[0], dataArray[1], dataArray[2], dataArray[3] with data while the 2-8mS is passing by to turn on the next digit  
}

---

<div class="post-metadata">

**Author:** ![vanepp](https://forum.fritzing.org/user_avatar/forum.fritzing.org/vanepp/32/4426_2.png) [@vanepp](https://forum.fritzing.org/u/vanepp)\
**Post date:** [March 2, 2017, 2:52am UTC](https://forum.fritzing.org/t/can-i-have-help-in-finishing-the-variables/3190/2 "2017-03-02T02:52:47Z")

</div>

This code appears to be wrong. A Fritzing schematic of the hardware would be necessary to make a stab at correcting it I expect as various parts of the code will depend on what pins are in use for what such as what pins are doing the digit driving (which appears to be where some errors are) although the segment drive ports would also be necessary.

---

<div class="post-metadata">

**Author:** ![MashCaup](https://forum.fritzing.org/letter_avatar_proxy/v4/letter/m/eb9ed0/32.png) [@MashCaup](https://forum.fritzing.org/u/MashCaup)\
**Post date:** [March 2, 2017, 3:04am UTC](https://forum.fritzing.org/t/can-i-have-help-in-finishing-the-variables/3190/3 "2017-03-02T03:04:55Z")

</div>

im entirely new with arduino and this is a 4 digit seven segment

---

<div class="post-metadata">

**Author:** ![vanepp](https://forum.fritzing.org/user_avatar/forum.fritzing.org/vanepp/32/4426_2.png) [@vanepp](https://forum.fritzing.org/u/vanepp)\
**Post date:** [March 2, 2017, 3:43am UTC](https://forum.fritzing.org/t/can-i-have-help-in-finishing-the-variables/3190/4 "2017-03-02T03:43:11Z")

</div>

I figure it was for a 4 digit seven segment display, We would need to know what pins are connected to what parts of the output drivers to make corrections. The line digitalWrite (digitPin[digitDrive], LOW); is incorrect. Digital write needs a pin number as the first parameter. If your setup is the same as the comments that would be an array containing 15, 14, 13, 12 where those are the pin numbers of the segment drivers. The line above won’t do that (I don’t think it will compile). You then would need to have an index variable that starts at 0 and cycles to 4 (and if (digitDrive == 4){ digitDrive = 0;} // reset to initial digit won’t do that both because digitDrive is an array not an int and nothing is incrementing it to make its value increase if it was an int). Then as the comments suggest you would need to get the values to display in to the array dataArray[0-3] somehow
