# I'm a noob.. storing a font in arduino

I actually can't believe I got this far so fast...

I got a few of these cheap displays... and using the theory based at this link, I was able to control it.. (on my first freaking try even)

So now my issue, the top 7 items are 14 segment displays. By hand I calculated A and googled it to find:
http://www.ee.ualberta.ca/~elliott/ee552/studentAppNotes/2001_w/interfacing/alphanumeric_LED/

That has all the characters I need. So my question is, how do I store this in arduino code? I've searched around trying to find some code that saves the font on the chip.. but haven't found much...

I'm more of a perl/php/ruby guy.. how does one make a proper hash in C?

Many thanks...

here is a fragment that I hope will get you started. Its off the top of my head and needs work but I trust it will get you going in the right direction

#define NBR_SEGMENTS 14 // each array element has a bit indicating the state of the 14 segments

unsigned int letters[] = {0b11101100100010,0b00111100000000,... }; // fonts from 'a' to 'z'
unsigned int numbers[] = {0b11111100010001,... }; //numbers from 0 to 9

void ShowLetters(char character){

int index = toupper(character) - 'A'; // convert to upper case and get offset from start of array
for( int i=0, unsigned int bit = 1; i < NBR_SEGMENTS; i ++, bit <<= 1) //shift through all 14 bits
if( letters[index] & bit ) // light the segement if this bit in the array is 1
// code to turn on the segment
}

Thanks mem, that should be enough to get me going.

One question, what does the 0b for at the start of each segment? I take it that its some sort of binary formatter? Is that what makes the <<= work properly ?

You are right, the 0b is simply an indication that the number following is to be interpretated as a binary value.

that code is perhaps a little obscure, I should explain:

the for loop manipulates two variables:
a counter 'i' that is used to ensure there are 14 iterations (one for each segment)
'bit' which is shifted left on each iteration and tested to see if the corresponding bit is set in the font.
bit <<= 1 is terse C code which does the shifting (it is equivalent to: bit = bit << 1)

the font data is represented in binary format because that's how it was indicated in the data sheet. But of you have the hex or decimal value that would work equally well.

Reversing the bits?

unsigned int bit = 1;
for( int i=0; i < NBR_SEGMENTS; i++) { //shift through all 14 bits
bit<<=1

This reverses the order of the binary format. I need it in the “rightmost shift”? but if i try bit>>=1 all I get are zeros…

Otherwise I think I’m on the right track…

It looks like my binary format font definitions should be reversed? Correct… read from right to left?

bit = (1<<(NBR_SEGMENTS - 1 - i));

Seems to work.. but not sure if its the correct way.. so please let me know if its not..

Yep, I think you have got it.

(for posterity) Here is what a night of playing got me… a scrolling from left ot right “Hello World”

``````//1) 1 start + 14 alpha + 2 colon + 1 ignore + 8 icon + 2 colon + 2 ignore + 5 transistor + 1 zero = 36
//2) 1 start + 14 alpha + 7 numeric + 7 numeric + 1 ignore + 5 transistor + 1 zero = 36
//3) 1 start + 14 alpha + 7 numeric + 7 numeric + 1 ignore + 5 transistor + 1 zero = 36
//4) 1 start + 14 alpha + 14 alpha + 1 ignore + 5 transistor + 1 zero = 36
//5) 1 start + 14 alpha + 14 alpha + 1 ignore + 5 transistor + 1 zero = 36

#define NBR_SEGMENTS 14    // each array element has a bit indicating the state of the 14 segments
#define NBR_DIGITS 7
#define ClockPin 12
#define DataPin 13
#define ResetPin 7

//                          A                B                C                D                E                F                G                H                I                J
unsigned int letters[] = {0b11101100100010,0b11110010101000,0b10011100000000,0b11110010001000,0b10011100100010,0b10001100100010,0b10111100100000,0b01101100100010,0b10010010001000,0b01110000000000,0b00001101010010,0b00011100000000,0b01101101000001,0b01101100010001,0b11111100000000,0b11001100100010,0b11111100010000,0b11001100110010,0b10110100100010,0b10000010001000,0b01111100000000,0b00001101000100,0b01101100010100,0b00000001010101,0b00000001001001,0b10010001000100,0b00000000000000 };

char disp[] = "HELLO WORLD";
int s = 0 - NBR_DIGITS;
int loopCnt = 0;
int dispLgth = sizeof(disp);

void setup()
{
pinMode(ClockPin, OUTPUT);
pinMode(DataPin, OUTPUT);
pinMode(ResetPin, OUTPUT);
Serial.begin(9600);

// RESET the display
digitalWrite(ResetPin,HIGH);
delay(1000);
digitalWrite(ResetPin,LOW);

}

void loop()
{

loopCnt++;

if (loopCnt == 20) { // increase for slower scrolling
loopCnt = 0;
if (s > dispLgth) { s = 0 - NBR_DIGITS; } // scrolling complete... reset
else { s++; } // slide digits one spot
}

int x;
for (x = 0; x < 5; x++) {

int i;
for (i = 0; i < 36; i++) {

digitalWrite(ClockPin, LOW); // clock starts low

if (i == 0) { digitalWrite(DataPin, HIGH); WiggleClock(); } // first bit always HIGH
else if (i == 1) { ShowLetter(x + s); } // Start letter
else if (i < 15) { } // portion of letter
else if ((x >= 3) && (i == 15)) { ShowLetter(x + s +2); } // 2nd letter on row 3,4
else if ((x >= 3) && (i < 29)) { } // portion of letter
else if (i == (30 + x)) { digitalWrite(DataPin, HIGH); WiggleClock(); } // resistor/line
else { digitalWrite(DataPin, LOW); WiggleClock(); } // everything else low

}
}
}

void ShowLetter(int position){

// bit hacky but it works...
int index = 26;
if ((position < 0) || (position >= dispLgth)) { index = 26; } // char 26 is blank
else { index = disp[position] - 'A'; } // get offset from start of array

if ((index < 0) || (index > 26)) { index = 26; } // double check its blank
unsigned int bit = 1;
for( int i=0; i < NBR_SEGMENTS; i++) {  //shift through all 14 bits
bit = 1<<(NBR_SEGMENTS -1 - i);
if(letters[index] & bit ) {
digitalWrite(DataPin, HIGH);
}
else {
digitalWrite(DataPin, LOW);
}
WiggleClock();
}
}

void WiggleClock(){
delayMicroseconds(3); // pause
digitalWrite(ClockPin, HIGH); // Clock set to high
delayMicroseconds(10);
digitalWrite(DataPin, LOW);
digitalWrite(ClockPin, LOW); // clock ends low
}
``````