Go Down

Topic: Arduino programmed ATiny84 controlling a 7 segment display! (Read 1 time) previous topic - next topic

mixania

Sep 09, 2012, 12:16 am Last Edit: Sep 09, 2012, 12:33 am by mixania Reason: 1
Hey guys, I've just got my Arduino Uno R3 a few days ago and began playing with it. javascript:void(0);
One of my first projects I've created was a 7 segment display (from RadioShack) with two buttons: one that increases the digit by one and the other decreases it by one.

I then found a turtorial on programming an Attiny micro microcontroller which really got my attention. I then ordered two Attiny85's and one Attiny84 for just 3.04$ from http://www.newark.com !!  :smiley-eek:

So I started messing around with these little fellows and then decided to implement one of the chips (particulary the Attiny84 because it has 10 functional pins compared to 5 pins in Attiny85 ) in my segment display project! 8)

What I used:
- Arduino Uno
- ATTiny84 (8KB Flash, 1KB RAM, 14Pins (10 Functional)) 2.13 $
http://www.newark.com/atmel/attiny84-20pu/ic-8bit-mcu-avr-tiny-20mhz-14-pdip/dp/68T3783?in_merch=Popular%20Products
- Bread Board
- Some Pull-up wires
- 220 - 270 Ohm resistor
- Momentary button
- LED (optional)

Due to some unexplainable dificulties I just left only the button that increases the digit but I was still exited seeing my project not connected to my Arduino anymore! :%

Code: [Select]



int aPin = 7; // a segment
int bPin = 6; // b segment
int cPin = 2; // c segment
int dPin = 3; // and so on....
int ePin = 4;
int fPin = 5;
int gPin = 8;

int upPin = 9; // button connection.

int ledPin = 10; // led connection. this is really optional, i just added it for debuging

int count = 0;
int d = 250; // delay, experiment with it so you'll see what it is.

void setup ()
{
 pinMode(aPin, OUTPUT);
 pinMode(bPin, OUTPUT);
 pinMode(cPin, OUTPUT);
 pinMode(dPin, OUTPUT);
 pinMode(ePin, OUTPUT);
 pinMode(fPin, OUTPUT);
 pinMode(gPin, OUTPUT);
 
 pinMode(upPin, INPUT);
 
 zero ();
 
}

void loop ()
{
 int up  = digitalRead(upPin);
 
 if ( up == 0)
 {
   digitalWrite (ledPin, HIGH);
   off();
   count ++;
   
    if (count == 1)
   {
     off();
     one ();
   }    
    if (count  == 2)
   {
     off();
     two ();
   }  
    if (count == 3)
   {
     off();
     three ();
   }
    if (count == 4)
   {
     off();
     four ();
   }    
    if (count == 5)
   {
     off();
     five ();
   }    
    if (count == 6)
   {
     off();
     six ();
   }    
    if (count == 7)
   {
     off();
     seven ();
   }  
    if (count == 8)
   {
     off();
     eight ();
   }  
    if (count == 9)
   {
     off();
     nine ();
   }    
    if (count == 0)
   {
     off();
     zero ();
   }    
    if (count > 9)
   {
     count = 0;
     zero ();
   }    
   delay (d);  
  digitalWrite (ledPin, LOW);
 }
 
}

void off ()
{
 digitalWrite(aPin, LOW);
 digitalWrite(bPin, LOW);
 digitalWrite(cPin, LOW);
 digitalWrite(dPin, LOW);
 digitalWrite(ePin, LOW);
 digitalWrite(fPin, LOW);
 digitalWrite(gPin, LOW);
}

void one ()
{
 digitalWrite(bPin, HIGH);
 digitalWrite(cPin, HIGH);
}

void two ()
{
 digitalWrite(aPin, HIGH);
 digitalWrite(bPin, HIGH);
 digitalWrite(gPin, HIGH);
 digitalWrite(dPin, HIGH);
 digitalWrite(ePin, HIGH);
}

void three ()
{
 digitalWrite(aPin, HIGH);
 digitalWrite(bPin, HIGH);
 digitalWrite(cPin, HIGH);
 digitalWrite(dPin, HIGH);
 digitalWrite(gPin, HIGH);
}

void four ()
{
 digitalWrite(bPin, HIGH);
 digitalWrite(cPin, HIGH);
 digitalWrite(gPin, HIGH);
 digitalWrite(fPin, HIGH);
}

void five ()
{
 digitalWrite(aPin, HIGH);
 digitalWrite(fPin, HIGH);
 digitalWrite(gPin, HIGH);
 digitalWrite(cPin, HIGH);
 digitalWrite(dPin, HIGH);
}

void six ()
{
 digitalWrite(aPin, HIGH);
 digitalWrite(fPin, HIGH);
 digitalWrite(cPin, HIGH);
 digitalWrite(dPin, HIGH);
 digitalWrite(ePin, HIGH);
 digitalWrite(gPin, HIGH);
}

void seven ()
{
 digitalWrite(aPin, HIGH);
 digitalWrite(bPin, HIGH);
 digitalWrite(cPin, HIGH);
}

void eight ()
{
 digitalWrite(aPin, HIGH);
 digitalWrite(bPin, HIGH);
 digitalWrite(cPin, HIGH);
 digitalWrite(dPin, HIGH);
 digitalWrite(ePin, HIGH);
 digitalWrite(fPin, HIGH);
 digitalWrite(gPin, HIGH);
}

void nine ()
{ digitalWrite(aPin, HIGH);
 digitalWrite(bPin, HIGH);
 digitalWrite(cPin, HIGH);
 digitalWrite(fPin, HIGH);
 digitalWrite(gPin, HIGH);
}

void zero ()
{
 digitalWrite(aPin, HIGH);
 digitalWrite(bPin, HIGH);
 digitalWrite(cPin, HIGH);
 digitalWrite(dPin, HIGH);
 digitalWrite(ePin, HIGH);
 digitalWrite(fPin, HIGH);
}




HELPFUL SOURCE!!
http://hlt.media.mit.edu/?p=1695


Here are the sources you'll find helpful:
http://www.youtube.com/watch?v=30rPt802n1k




THANK YOU FOR VIEWING!! PLEASE COMMENT!!
Arduino Uno R3
Mac OSX Lion

Nick Gammon

Quote
if (count == 8)


Please edit your post, select the code, and put it between [code] ... [/code] tags.

You can do that by hitting the # button above the posting area.


(You may need to grab the actual source code, don't use "copy for forum".)

Also please remove the sideways scrolling text, it's rather distracting.

mixania

Arduino Uno R3
Mac OSX Lion

Nick Gammon

Thank you very much!

If you are having trouble with the buttons you could post a query in the Programming section, someone may be able to help you.

mixania

Arduino Uno R3
Mac OSX Lion

Lakes


Go Up