Skip to content

Instantly share code, notes, and snippets.

@sigma
Created August 26, 2013 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sigma/6338909 to your computer and use it in GitHub Desktop.
Save sigma/6338909 to your computer and use it in GitHub Desktop.
teensy 7-segment display
/************************************************************************
* Teensy 3.0: Random Numbers on BCD 7-Segment Display Version: 1.00 *
* Functions : Random Numbers between 00 & 99. TURBO-mode, FREEZE-mode *
* MicroCtrlr: MK20DX128 32 bit ARM Cortex-M4 48 MHz *
* Arduino Shield: Alexan Digital Trainer 2 from Alexan Commercial *
************************************************************************
* Arduino IDE v1.0.5 from http://arduino.cc/en/Main/Software *
* Teensyduino v1.14 from http://www.pjrc.com/teensy/td_download.html *
* Configuration: Teensy 3.0 on /dev/ttyACM0 *
* Operating System: Xubuntu Linux 13.10 Saucy Salamander (32-bit) *
* Created: January 27, 2013 (Arduino Mini) Revised: June 20, 2013 *
************************************************************************
* MirandaSoft! - Pasig City, Metro Manila, Philippines *
* http://www.element14.com/community/blogs/mirandasoft *
************************************************************************
* The Main Ingredients *
* Teensy 3.0 from http://www.pjrc.com/teensy/ *
* CD4511 BCD to 7-Segment Latch/Decoder (element14 Order#: 1106122) *
* Common Cathode 7-Seg Hyper-Red Disp (element14 Order#: 2001769) *
************************************************************************/
int inputs1[4] = { 9, 8, 7, 6}; // A,B,C,D inputs Display 1
int inputs2[4] = { 14, 15, 16, 17}; // A,B,C,D inputs Display 2
int tamad = 1000; // Delay of 1000 miliseconds
int huli, bilang, val; // Randomly Chosen Numbers
int pigilin = 2; // Hold pin
int mabilis = 3; // Turbo pin
// Binary-code Decimal (BCD)
// These are 7-Segment Digits from 0 to 9
byte BCD[16][4] ={{0,0,0,0},{1,0,0,0},{0,1,0,0},{1,1,0,0},
{0,0,1,0},{1,0,1,0},{0,1,1,0},{1,1,1,0},{0,0,0,1},{1,0,0,1}};
void setup() {
randomSeed(analogRead(A9)); //initialize the random number generator
for(int m = 0; m < 4; m++) {
pinMode(inputs2[m], OUTPUT); //set outputs for Display 2
pinMode(inputs1[m], OUTPUT); //set outputs for Display 1
bilang = random(100); // Enhances Randomness!!!
}
pinMode(mabilis, INPUT); // Switch: Turbo-mode
pinMode(pigilin, INPUT); // Switch: Freeze-mode
}
void ipakita(int pamalas) {
if((pamalas > 99) || (pamalas < 0)) pamalas = 00; // Error Handler
for(int pasig = 0; pasig < 4; pasig++){
digitalWrite(inputs1[pasig], BCD[pamalas / 10][pasig]);
digitalWrite(inputs2[pasig], BCD[pamalas % 10][pasig]);
}
}
void loop() {
huli = bilang;
bilang = random(1,99);
// Simple Error Handler to Prevent Duplicate Numbers
if(huli==bilang) {
randomSeed(analogRead(A9));
bilang = random(1,99);
}
val = digitalRead(mabilis); // TURBO mode
if(!val) {
tamad = 5000; // Not Switched: 5 Seconds
}
else {
tamad = 100; // Switched: 0.1 Seconds
}
ipakita(bilang);
delay(tamad);
while(digitalRead(pigilin)); // FREEZE mode
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment