Pages: [1]   Go Down
Author Topic: Arduino programmed ATiny84 controlling a 7 segment display!  (Read 1393 times)
0 Members and 1 Guest are viewing this topic.
Westbrook, CT
Offline Offline
Full Member
***
Karma: 2
Posts: 139
"Why should I bother with made-up games when there are so many real ones going on." (c) Kurt Vonnegut
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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! smiley-cool

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! smiley-draw

Code:


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:





THANK YOU FOR VIEWING!! PLEASE COMMENT!!


* DSC_9573.JPG (438.13 KB, 2000x1339 - viewed 20 times.)

* DSC_9554.JPG (877.92 KB, 2000x2988 - viewed 12 times.)

* DSC_9568.JPG (323.82 KB, 2000x1339 - viewed 12 times.)

* DSC_9567.JPG (351.53 KB, 2000x1339 - viewed 14 times.)
« Last Edit: September 08, 2012, 05:33:43 pm by mixania » Logged

Arduino Uno R3
Mac OSX Lion


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
     if (count == smiley-cool

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

Westbrook, CT
Offline Offline
Full Member
***
Karma: 2
Posts: 139
"Why should I bother with made-up games when there are so many real ones going on." (c) Kurt Vonnegut
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Alright now?
Logged

Arduino Uno R3
Mac OSX Lion


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Westbrook, CT
Offline Offline
Full Member
***
Karma: 2
Posts: 139
"Why should I bother with made-up games when there are so many real ones going on." (c) Kurt Vonnegut
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Oooo. Ok thanks!  smiley-wink
Logged

Arduino Uno R3
Mac OSX Lion


Offline Offline
Sr. Member
****
Karma: 5
Posts: 422
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Very good, you should resize your photo`s though. smiley

Some ATtiny links here
http://www.kobakant.at/DIY/?p=3408
Logged

Pages: [1]   Go Up
Jump to: