John Reilly

Arduino 4-Digit 7-Segment Display

by jreilly on Apr.13, 2010, under Arduino, Electronics

Source code:

long n = 0;
int x = 100;
int del = 1;
 
void setup(){
//  clearLEDs();
//  testLEDs();
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(1, OUTPUT);
 
}
 
void loop(){
 
  clearLEDs();
  pickDigit(1);
  pickNumber((n/x/1000)%10);
  delayMicroseconds(del);
  clearLEDs();
  pickDigit(2);
  pickNumber((n/x/100)%10);
  delayMicroseconds(del);
  clearLEDs();
  pickDigit(3);
  pickNumber((n/x/10)%10);
  delayMicroseconds(del);
  clearLEDs();  
  pickDigit(4);
  pickNumber(n/x % 10);  
  delayMicroseconds(del);
  if(n/x > 9999){ 
    n = 0;
    delay(5000);
  }
  else n++;
}
 
void pickDigit(int x){
  digitalWrite(13, LOW); // dig 1
  digitalWrite(12, LOW); // dig 2
  digitalWrite( 9, LOW); // dig 3
  digitalWrite( 8, LOW); // dig 4
 
  switch(x){
    case 1: digitalWrite(13, HIGH); break;
    case 2: digitalWrite(12, HIGH); break;
    case 3: digitalWrite(9, HIGH); break;
    case 4: digitalWrite(8, HIGH); break;    
  }
}
 
void pickNumber(int x){
   switch(x){
     case 1: one(); break;
     case 2: two(); break;
     case 3: three(); break;
     case 4: four(); break;
     case 5: five(); break;
     case 6: six(); break;
     case 7: seven(); break;
     case 8: eight(); break;
     case 9: nine(); break;
     default: zero(); break;
   } 
}
 
void clearLEDs(){  
  //digitalWrite(13, HIGH);
 // digitalWrite(12, HIGH);
  //digitalWrite(9, HIGH);
//  digitalWrite(8, HIGH);  
  digitalWrite( 5, HIGH); // A
  digitalWrite( 7, HIGH); // B
  digitalWrite( 4, HIGH); // C
  digitalWrite(11, HIGH); // D
  digitalWrite(10, HIGH); // E
  digitalWrite( 3, HIGH); // F
  digitalWrite( 6, HIGH); // G 
}
 
void one(){
  digitalWrite( 5, HIGH); // A
  digitalWrite( 7, LOW); // B
  digitalWrite( 4, LOW); // C
  digitalWrite(11, HIGH); // D
  digitalWrite(10, HIGH); // E
  digitalWrite( 3, HIGH); // F
  digitalWrite( 6, HIGH); // G 
}
 
void two(){
  digitalWrite( 5, LOW); // A
  digitalWrite( 7, LOW); // B
  digitalWrite( 4, HIGH); // C
  digitalWrite(11, LOW); // D
  digitalWrite(10, LOW); // E
  digitalWrite( 3, HIGH); // F
  digitalWrite( 6, LOW); // G 
}
 
void three(){
  digitalWrite( 5, LOW); // A
  digitalWrite( 7, LOW); // B
  digitalWrite( 4, LOW); // C
  digitalWrite(11, LOW); // D
  digitalWrite(10, HIGH); // E
  digitalWrite( 3, HIGH); // F
  digitalWrite( 6, LOW); // G 
}
 
void four(){
  digitalWrite( 5, HIGH); // A
  digitalWrite( 7, LOW); // B
  digitalWrite( 4, LOW); // C
  digitalWrite(11, HIGH); // D
  digitalWrite(10, HIGH); // E
  digitalWrite( 3, LOW); // F
  digitalWrite( 6, LOW); // G 
}
 
void five(){
  digitalWrite( 5, LOW); // A
  digitalWrite( 7, HIGH); // B
  digitalWrite( 4, LOW); // C
  digitalWrite(11, LOW); // D
  digitalWrite(10, HIGH); // E
  digitalWrite( 3, LOW); // F
  digitalWrite( 6, LOW); // G 
}
 
void six(){
  digitalWrite( 5, LOW); // A
  digitalWrite( 7, HIGH); // B
  digitalWrite( 4, LOW); // C
  digitalWrite(11, LOW); // D
  digitalWrite(10, LOW); // E
  digitalWrite( 3, LOW); // F
  digitalWrite( 6, LOW); // G 
}
 
void seven(){
  digitalWrite( 5, LOW); // A
  digitalWrite( 7, LOW); // B
  digitalWrite( 4, LOW); // C
  digitalWrite(11, HIGH); // D
  digitalWrite(10, HIGH); // E
  digitalWrite( 3, HIGH); // F
  digitalWrite( 6, HIGH); // G 
}
 
void eight(){
  digitalWrite( 5, LOW); // A
  digitalWrite( 7, LOW); // B
  digitalWrite( 4, LOW); // C
  digitalWrite(11, LOW); // D
  digitalWrite(10, LOW); // E
  digitalWrite( 3, LOW); // F
  digitalWrite( 6, LOW); // G 
}
 
void nine(){
  digitalWrite( 5, LOW); // A
  digitalWrite( 7, LOW); // B
  digitalWrite( 4, LOW); // C
  digitalWrite(11, LOW); // D
  digitalWrite(10, HIGH); // E
  digitalWrite( 3, LOW); // F
  digitalWrite( 6, LOW); // G 
}
 
void zero(){
  digitalWrite( 5, LOW); // A
  digitalWrite( 7, LOW); // B
  digitalWrite( 4, LOW); // C
  digitalWrite(11, LOW); // D
  digitalWrite(10, LOW); // E
  digitalWrite( 3, LOW); // F
  digitalWrite( 6, HIGH); // G 
}
Comments Off more...

You probably don’t understand Unicode

by jreilly on Dec.09, 2009, under Programming

Comments Off more...

Die Hard 2 in HD is hilarious

by jreilly on Dec.07, 2009, under Movies

Not only does HD make new movies and shows better, it makes older movies from the pre-HD era even more awesome. Case in point, one of my favorites: Die Hard 2. Director Renny Harlin probably never expected that this scene would be seen in such clarity. These images are from a 30 second sequence where a terrorist on top of some scaffolding falls and is crushed by said scaffold. A tense and brutal scene when viewed in standard definition turns into something else when viewed in HD: (continue reading…)

Comments Off more...

SQL “Contains All” Query

by admin on Dec.01, 2009, under SQL

Problem: You want to return a set of employees that have all of the necessary skills to perform a particular task. A generalization of this would be something like, “return the objects in set A which contain all of the properties of a chosen item of set B”.

You have a table of Employees and a table of Tasks. Both make use of a common Skills table. The Employee table is linked to the Skills table by the table EmployeeHasSkill. The Task table is linked to the Skills table by TaskRequiresSkill. (continue reading…)

Comments Off more...

Blog!

by admin on Jul.04, 2009, under Uncategorized

Hooray!

Comments Off more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Archives

All entries, chronologically...