Pages: [1]   Go Down
Author Topic: AlphaNumeric Display Library  (Read 897 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 96
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,
I have had a few alphanumeric displays and today I have decided to hook them up to a 74HC595.  There are 2 74HC595's in chain that are controlling each segment of the alphanumeric display.  By the way, the library is named Pasta (I name all of my libraries after all of my favorite foods, the next one is going to be bacon).  I have the .cpp and .h files, but I ran into a problem.  I made all of the alphanumeric characters in bytes, 16 bit bytes.  The Arduino IDE is giving me error messages like "B1011101000011010 was not declared in this scope."  How would I go about fixing this?

.cpp file
Code:
#include "Arduino.h"
#include "Pasta.h"

uint8_t Pasta::registerPins(int SER_Pin, int RCLK_Pin, int SRCLK_Pin, int Number_of_Registers) {
    _SER_Pin = SER_Pin;
    _RCLK_Pin = RCLK_Pin;
    _SRCLK_Pin = SRCLK_Pin;
   
    _Number_of_Registers = Number_of_Registers;

pinMode(_SER_Pin, OUTPUT);
pinMode(_RCLK_Pin, OUTPUT);
pinMode(_SRCLK_Pin, OUTPUT);

clear(); //reset all register pins
update(); 
}

void Pasta::update(){
//Set and display registers
//Only call AFTER all values are set how you would like (slow otherwise)
   
    digitalWrite(_RCLK_Pin, LOW);
   
    //iterate through the registers
    for(int i = _Number_of_Registers - 1; i >=  0; i--){
       
        //iterate through the bits in each registers
        for(int j = 8 - 1; j >=  0; j--){
           
            digitalWrite(_SRCLK_Pin, LOW);   
           
            int val = _shiftRegisters[i] & (1 << j);
           
            digitalWrite(_SER_Pin, val);
            digitalWrite(_SRCLK_Pin, HIGH);
           
        }
       
    }
   
    digitalWrite(_RCLK_Pin, HIGH);
}

void Pasta::setPin(int index, boolean val){
int byteIndex = index/8;
int bitIndex = index % 8;

byte current = _shiftRegisters[byteIndex];

current &= ~(1 << bitIndex); //clear the bit
current |= val << bitIndex; //set the bit

_shiftRegisters[byteIndex] = current; //set the value
    update();
}

void Pasta::setAll(boolean val){
    //set all register pins to LOW 
    for(int i = _Number_of_Registers * 8 - 1; i >=  0; i--){
        setPin(i, val);
    }
}

void Pasta::clear(){
    //set all register pins to LOW 
    for(int i = _Number_of_Registers * 8 - 1; i >=  0; i--){
        setPin(i, _common);
    }
}

uint8_t Pasta::segmentPins(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k, int l, int m, int n, int o, int p, boolean common) {
   
    _a=a;
    _b=b;
    _c=c;
    _d=d;
    _e=e;
    _f=f;
    _g=g;
    _h=h;
    _i=i;
    _j=j;
    _k=k;
    _l=l;
    _m=m;
    _n=n;
    _o=o;
    _p=p;
    _common=common;
   
    segmentpins[0] = _a;
    segmentpins[1] = _b;
    segmentpins[2] = _c;
    segmentpins[3] = _d;
    segmentpins[4] = _e;
    segmentpins[5] = _f;
    segmentpins[6] = _g;
    segmentpins[7] = _h;
    segmentpins[8] = _i;
    segmentpins[9] = _j;
    segmentpins[10] = _k;
    segmentpins[11] = _l;
    segmentpins[12] = _m;
    segmentpins[13] = _n;
    segmentpins[14] = _o;
    segmentpins[15] = _p;
   
    for(int i=0; i < 16; i++) {
       
        pinMode(segmentpins[i], OUTPUT);
    }
   
   
}

void Pasta::flicker() {
   
    write(0);
    delay(50);
    write(4);
    delay(50);
    write(9);
    delay(50);
    write(1);
    delay(50);
    write(6);
    delay(50);
    write(9);
    delay(50);
    write(3);
    delay(50);
    write(4);
    delay(100);
    write(7);
    delay(100);
    write(9);
    delay(100);
    write(3);
    delay(100);
    write(2);
    delay(100);
    write(5);
    delay(100);
    write(6);
    delay(100);
    write(3);
    delay(200);
    write(5);
    delay(300);
}

void Pasta::write(int character) {
    boolean isBitSet;
    //             ABCDEFGHIJKLMNOP
    numeral[0]  = B1110001001000111;  // 0
    numeral[1]  = B0000001000000100;  // 1
    numeral[2]  = B1100001111000011;  // 2
    numeral[3]  = B1100001110000111;  // 3
    numeral[4]  = B0010001110000100;  // 4
    numeral[5]  = B1110000110000111;  // 5
    numeral[6]  = B1110000111000111;  // 6
    numeral[7]  = B1100001000000100;  // 7
    numeral[8]  = B1110001111000111;  // 8
    numeral[9]  = B1110001110000111;  // 9
    numeral[10] = B1110001110000100;  // A
    numeral[11] = B1110010101001011;  // B
    numeral[12] = B1110000001000011;  // C
    numeral[13] = B0011000101100000;  // D
    numeral[14] = B1110000111000011;  // E
    numeral[15] = B1110000111000000;  // F
    numeral[16] = B1110000011000111;  // G
    numeral[17] = B0010001111000100;  // H
    numeral[18] = B1100100000010011;  // I
    numeral[19] = B1100100001010010;  // J
    numeral[20] = B0000110000011000;  // K
    numeral[21] = B0010000001000011;  // L
    numeral[22] = B0011011001000100;  // M
    numeral[23] = B0011001001001100;  // N
    numeral[24] = B1110001001000111;  // O
    numeral[25] = B1110001111000000;  // P
    numeral[26] = B1110001001001111;  // Q!!!!!!!!!
    numeral[27] = B1110001111001000;  // R
    numeral[28] = B1110000110000111;  // S
    numeral[29] = B1100100000010000;  // T
    numeral[30] = B0010001001000111;  // U
    numeral[31] = B0010010001100000;  // V
    numeral[32] = B0010001001101100;  // W
    numeral[33] = B0001010000101000;  // X
    numeral[34] = B0001010000010000;  // Y
    numeral[35] = B1100010000100011;  // Z
    numeral[36] = B0000000101010010;  // a
    numeral[37] = B0010000111000111;  // b
    numeral[38] = B0000000101000010;  // c
    numeral[39] = B0000001111000111;  // d
    numeral[40] = B0010000111000100;  // h
    numeral[41] = B0000001000000100;  // l
    numeral[42] = B0000000111000100;  // m
    numeral[43] = B0000000101010000;  // n
    numeral[44] = B0000000101010010;  // o
    numeral[45] = B0000100110010001;  // t
    numeral[46] = B0000000001000111;  // u
    numeral[47] = B0000000001010111;  // w
    numeral[48] = B0000000110000000;  // -
    numeral[49] = B0000010000100000;  // /
    numeral[50] = B1110001010000000;  // ?
    numeral[51] = B0001000000001000;  // \
    numeral[52] = B0000100000010000;  // |
    numeral[53] = B0000100110010000;  // +
    numeral[54] = B0000000000000011;  // _
    numeral[55] = B1100001000000111;  // ]
    numeral[56] = B1110000001000011;  // [
    numeral[57] = B0000000000100000;  // ,
    numeral[58] = B0001110110111000;  // *
    numeral[59] = B1101010000101011;  // hour glass
   
    if (_common == HIGH) {
       
        for(int segment=1; segment < 17; segment++) {
            if(character < 0 || character > 59) {
                isBitSet = 0;
            }else{
                isBitSet = bitRead(numeral[character], segment);
            }
            isBitSet = ! isBitSet;
            setPin(segmentpins[segment], isBitSet);
            update();
        }
    }else{
        for(int segment=1; segment < 17; segment++) {
            if(character < 0 || character > 59) {
                isBitSet = 0;
            }else{
                isBitSet = bitRead(numeral[character], segment);
            }
            setPin(segmentpins[segment], isBitSet);
            update();
        }
    }
}

.h file
Code:
#ifndef Pasta_h
#define Pasta_h

#include "Arduino.h"

class Pasta
{
public:
    uint8_t registerPins(int SER_Pin, int RCLK_Pin, int SRCLK_Pin, int Number_of_Registers);
    uint8_t segmentPins(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k, int l, int m, int n, int o, int p, boolean common);
    void write(int character);
    void clear();
    void setAll(boolean val);
    void setPin(int index, boolean val);
    void update();
    void flicker();
   
private:
    int _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _character;
    int _SER_Pin, _RCLK_Pin, _SRCLK_Pin, _Number_of_Registers;
    byte numeral[10];
    int segmentpins[8];
    boolean _common;
    byte _shiftRegisters[25];
    boolean _val;
};

#endif

Qtechknow
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The Bnnnnnnnn notation is Arduino specific (a bunch of #defines), and only covers a single byte. Try using 0b1011101000011010 instead.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 96
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks.  It compiled, which is a good +, but did not work.  The alphanumeric just lit up some random segments, without changing.
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
    numeral[59] = B1101010000101011;  // hour glass
doesn't seem to agree with
Code:
    byte numeral[10];
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 96
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I changed that, but it still didn't work on the alphanumeric display.  It changed segments, but it didn't have the correct segments lit at the right time.
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How about this?
Code:
    int segmentpins[8];
Code:
    segmentpins[15] = _p;

Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 96
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the help.  It still doesn't work surprisingly though.  I'm not sure why. Any ideas?
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 96
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Anyone know why my library isn't working????
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 615
Posts: 49414
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Anyone know why my library isn't working????
You've supposedly made several code changes, but not pasted new code. And you want us to guess what is now wrong?

Maybe this library wanted to be called Bacon.
Logged

Pages: [1]   Go Up
Jump to: