Go Down

### Topic: Programming 7- segment with Arduino (Read 1 time)previous topic - next topic

#### Qtechknow

##### Nov 21, 2011, 08:26 pmLast Edit: Nov 21, 2011, 08:28 pm by qtechknow Reason: 1
Hello everyone!
I have been trying to program a 7 segment display today and have had some luck. I have uploaded this code and the bottom and the DP light up. I have hooked up the segment to the arduino via pins 5-13. The common anode is at pin 13 and is working currently. I have no idea on how I got the decimal to light up, because I just initialized it as an output. All I am trying to do now is light up a number on the 7 segment display. After I make and complete this, I will try to make a dice, and then a library for the Arduino. Any help on just trying to make it display a number?

Thanks, qtechknow
Code: [Select]
`/*  7-Segment Display */const int DP = 5;const int CA = 13; int ledPins[] = { 6, 7, 8, 9, 10, 11, 12 }; int zero[] = { 7, 12, 6, 8, 10, 9 };int one[] = { 6, 10 };int two[] = { 7, 6, 11, 8, 9 };int three[] = { 7, 6, 11, 10, 9 };int four[] = { 12, 11, 6, 10 };int five[] = { 7, 12, 11, 10, 9 };int six[] = { 7, 12, 11, 8, 9, 10 };int seven[] = { 7, 6, 10 };int eight[] = { 7, 6, 12, 11, 10, 9, 8 };int nine[] = { 7, 12, 6, 11, 10 };void setup() {                  // initialize the digital pins as outputs  pinMode(CA, OUTPUT);  pinMode(DP, OUTPUT);  pinMode(ledPins[6, 7, 8, 9, 10, 11, 12], OUTPUT);}void loop() {  digitalWrite(13, HIGH);   // set the Common Anode high  digitalWrite(zero[7, 12, 6, 8, 9, 10], LOW);  // display 0}`

#### Msquare

#1
##### Nov 21, 2011, 09:16 pm
digitaWrite(pin, value) --> the pin number has to be a single number - not an array. You have to write a for() loop.

Actually I haven't got a clue what the construct
Code: [Select]
` digitalWrite(zero[7, 12, 6, 8, 9, 10], LOW);  `
does. It should fail to compile, but as Arduino is C++ there is some fancy stuff beyond me. I do know it does NOT write to a list of oins.

Lastly, do not use the Arduino IO pins as power supplies. You have a nice +5V pin you can use for this experiment as the anode supply. Really there should be a resistor of 220 Ohm in series between each of the 5-12 pins and the LED segement.

#2
##### Nov 21, 2011, 10:33 pmLast Edit: Nov 22, 2011, 01:24 am by CrossRoads Reason: 1
What is your plan to turn off unneeded segments?
Ex.
You write out an 8, all segments on.
Then you write out a 1 - 2 segments on.
What turns off the rest of them?

You can do a for:next loop to go thru the pins in array and one at a time write the pins in the number array.
Or you can do this
Code: [Select]
`numbers[] = {B00111111,  //0B00000110, // 1B01011011, // 2etc where BPgfedcba represents the LED segments   af     b   ge    c   d    Pthen to write a digit:PORTX = numbers[number_to_displau];However, you're not using a part that has 8 bit ports accessible, so need to do something different.Bigger chip! No, wait.Write a for:next loop that will write the value of each bit in numbers[x] to the pins in ledPins:for (x=1; x<0x80; x=x<1){  //digitalWrite (ledPins[x], (numbers[number_to_display] && x));}where numbers[number_to_display] && xshould be True (i.e !=0) if the masking result is not equal to 0result of B00000001 && numbers[number_to_display] for segment AB00000010 && && numbers[number_to_display] for segment B, etc.will mask off`
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

#### Grumpy_Mike

#3
##### Nov 21, 2011, 11:01 pm
I just did a tutorial that uses the 7 segment display as an example of how to code:-
http://www.thebox.myzen.co.uk/Tutorial/Arrays.html

#### fubbi

#4
##### Nov 22, 2011, 10:16 am

I just did a tutorial that uses the 7 segment display as an example of how to code:-
http://www.thebox.myzen.co.uk/Tutorial/Arrays.html

nice!

Go Up

Please enter a valid email to subscribe