2 Sparkfun’s 7-Segment Red 6.5? Display and Arduino
A few weeks ago I posted about connecting Sparkfun’s 7-Segment 6.5″ Display’s to Arduino. In that post I only showed how to hook up 1 digit. In this post I will show how to hook up 2, but it scales to however many you want to add. Much of the same applies from my previous post but here are new diagrams and code.
int dataPin = 11; int clockPin = 12; int latchPin = 8; int len = 10; //holders for infromation you're going to pass to shifting function byte dataRED; byte dataArrayRED[10]; byte off = 0x00; byte decimalpoint = 0x80; void setup() { //set pins to output because they are addressed in the main loop pinMode(latchPin, OUTPUT); //Arduino doesn't seem to have a way to write binary straight into the code //so these values are in HEX. Decimal would have been fine, too. dataArrayRED[0] = 0x3F; //00111111 - 0 dataArrayRED[1] = 0x06; //00000110 - 1 dataArrayRED[2] = 0x5B; //01011011 - 2 dataArrayRED[3] = 0x4F; //01001111 - 3 dataArrayRED[4] = 0x66; //01100110 - 4 dataArrayRED[5] = 0x6D; //01101101 - 5 dataArrayRED[6] = 0x7D; //01111101 - 6 dataArrayRED[7] = 0x07; //00000111 - 7 dataArrayRED[8] = 0x7F; //01111111 - 8 dataArrayRED[9] = 0x67; //01100111 - 9 } void loop() { int count = 100; int val = 10; //this is for how many digits for( int i = 0; i<count; i++ ) { digitalWrite(latchPin, 0); int digit2 = i % val; int digit1 = ( i - digit2 ) / val; shiftOut(dataPin, clockPin, dataArrayRED[ digit2 ]); shiftOut(dataPin, clockPin, dataArrayRED[ digit1 ]); digitalWrite(latchPin, 1); delay(300); delay(1000); } } // the heart of the program void shiftOut(int myDataPin, int myClockPin, byte myDataOut) { // This shifts 8 bits out MSB first, //on the rising edge of the clock, //clock idles low //internal function setup int i=0; int pinState; pinMode(myClockPin, OUTPUT); pinMode(myDataPin, OUTPUT); //clear everything out just in case to //prepare shift register for bit shifting digitalWrite(myDataPin, 0); digitalWrite(myClockPin, 0); //for each bit in the byte myDataOut… //NOTICE THAT WE ARE COUNTING DOWN in our for loop //This means that %00000001 or "1" will go through such //that it will be pin Q0 that lights. for (i=7; i>=0; i--) { digitalWrite(myClockPin, 0); //if the value passed to myDataOut and a bitmask result // true then... so if we are at i=6 and our value is // %11010100 it would the code compares it to %01000000 // and proceeds to set pinState to 1. if( myDataOut & (1<<i) ) { pinState= 1; } else { pinState= 0; } //Sets the pin to HIGH or LOW depending on pinState digitalWrite(myDataPin, pinState); //register shifts bits on upstroke of clock pin digitalWrite(myClockPin, 1); //zero the data pin after shift to prevent bleed through digitalWrite(myDataPin, 0); } //stop shifting digitalWrite(myClockPin, 0); }
I also have a video uploaded on viddler
Now that I have this up and running I just have to do something useful with it. And I have to find a better way to solder the digits, because there are wires everywhere.



