Pages: [1]   Go Down
Author Topic: Programming 7- segment with Arduino  (Read 1016 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 96
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
/*
  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
}
« Last Edit: November 21, 2011, 02:28:12 pm by qtechknow » Logged

Copenhagen, Denmark
Offline Offline
Edison Member
*
Karma: 32
Posts: 1204
Have you testrun your INO file today?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.

Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 524
Posts: 26473
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
numbers[] = {
B00111111,  //0
B00000110, // 1
B01011011, // 2
etc where BPgfedcba represents the LED segments
   a
f     b
   g
e    c
   d    P
then 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] && x
should be True (i.e !=0) if the masking result is not equal to 0
result of B00000001 && numbers[number_to_display] for segment A
B00000010 && && numbers[number_to_display] for segment B, etc.

will mask off
« Last Edit: November 21, 2011, 07:24:31 pm by CrossRoads » Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 602
Posts: 33379
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

berlin
Offline Offline
Full Member
***
Karma: 0
Posts: 154
fubbi.com
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Pages: [1]   Go Up
Jump to: