led display controll

Help!

I'm relatively new to this world, learning languages in bits and pieces to make projects happen. I need assistance converting code for the basic stamp 2 to control a four segment led display to the arduino environment. So far, I can turn all the segments on, but without any control over the individual led's. Can anyone help? The source code I'm chopping up is viewable at http://user.pa.net/~bean/hc4led/HC4LED.BS2.

Matthew

Hi

what do you have so far in terms of code? Post it and we can have a look

D

I have a few code samples that are similar to what I've pasted below. What I want to know is how to control the led to write text or specific numbers, etc. It seems like the answer is in the shiftOut, dataOut, functions, but I just don't have a handle on it yet.

#define CLOCKPIN 12 //change this to the pin where the clock is going in to
#define DATA_PIN 13 // change to the pin where the data wire is plugged in to
int time = 2400;
int digits[10] = { 126, 24, 109, 61, 27, 55, 119, 28, 127, 31 }; // define numerals (0-9)
int digitC = 60;
int digitF = 71;
int digitE = 103;
int flashDelay = 1400;
int minDelay = 500;
char* numStr = " ";
void setup()
{
Serial.begin(9600);
pinMode(DATA_PIN, OUTPUT);
pinMode(CLOCKPIN, OUTPUT);
}
void numOut(int num){
int g;

char* *numStrPtr;
//char *numDigitPtr;

numStrPtr = &numStr;
//numDigitPtr = &numDigit;

itoa(num, *numStrPtr, 10);

for (g=3; g >= 0; g--) {

if (g == 0) {
digitOut(digits[numStr[g]-48], flashDelay);
} else {
digitOut(digits[numStr[g]-48], minDelay);
}

}

}
void digitOut(byte dataOut, int curDelay) {
// This shifts bits out MSB first, on the rising edge of the clock:
int i; // bit counter
if (curDelay < minDelay) { curDelay = minDelay; } // delay
for (i=7; i>=0; i--) {

if ( dataOut & (1<<i) ) {
digitalWrite(DATA_PIN, HIGH);
}

// if this bit of the dataOut variable is a 0,
// then set the data pin low to shift out a 0:
else {
digitalWrite(DATA_PIN, LOW);
}

digitalWrite(CLOCKPIN, HIGH);
// pulse the clock:
if (i == 0) {
delayMicroseconds(curDelay);
} else {
delayMicroseconds(minDelay);
}
digitalWrite(CLOCKPIN, LOW);

}

}
void loop()
{

time = time - 1;

numOut(time); //use this function to display what you want to display
//Serial.println(time);
delay(1000);
}

Here is a fairly straightforward conversion of the BS2 program. I haven't had a chance to compile this so there might be a few syntax errors.

/*

  • HC4LED.BS2 converted from PBASIC 2.5 to Arduino Wiring/Processing by wandrson@yahoo.com
  • This program demonstrates the use of the HC4LED display module
  • HC4LED Pinout:
  • Pin1 = +5VDC (White wire)
  • Pin2 = Gnd
  • Pin3 = Blank (Must connect to Gnd to enable display)
  • Pin4 = No Connection
  • Pin5 = Clock (Connect to pin 1 for this demo program)
  • Pin6 = Data (Connect to pin 0 for this demo program)
  • To display values:
  • Set the "zeros" variable to 0=No leading zeros; or 1=Show leading zeros
  • Set the variable "value" to 0 to 9999
  • Then use "GOSUB DisplayValue" to show the value on the display
  • Each segment of the display is addressable, so you can create letters
  • and symbols.
  • To display custom symbols:
  • Set the variables "segments(0)" thru "segments(3)" (segments(0) is on the left)
  • simply add the segment values that you want on
  • Then use "GOSUB DisplaySegments" to show the segments on the display
  • ---4---
  • | |
  • 2 8
  • | |
  • |---1---|
  • | |
  • 64 16
  • | |
  • --32---
  • For example "F" would be 4+2+1+64 = 71

*/

int Clock=13;
int Dat = 11;

int vWord; // Holds value to display
byte cnt; // Used by display routines
byte segment[4]; // Used by display routines & customer chars
int digits[] = {126, 24, 109, 61, 27, 55, 119, 28, 127, 31 }; // define numbers 0-9

void setup()
{
pinMode(Dat, OUTPUT);
pinMode(Clock, OUTPUT);
}

/*

  • Call with:
  • segments(0) thru segments(3) set to custom character values
  • segments(0) is on the left; segments(3) is on the right
    */
    void DisplaySegments()
    {
    shiftOut(Dat, Clock, MSBFIRST, segment[3]);
    shiftOut(Dat, Clock, MSBFIRST, segment[2]);
    shiftOut(Dat, Clock, MSBFIRST, segment[1]);
    shiftOut(Dat, Clock, MSBFIRST, segment[0]);
    digitalWrite(Dat, (segment[0] & 1));
    digitalWrite(Clock, HIGH);
    // Clock MUST remain high for at LEAST 1 millisecond for the
    // new data to be latched onto the display.
    delay(1);
    }

/*

  • Call with:
  • parm = (value to display)
    */
    void DisplayValue(int parm)
    {
    int dig3;
    int dig2;
    int dig1;
    int dig0;

if (parm < 10000) {
dig3 = parm / 1000;
dig2 = (parm - (dig3 * 1000))/100;
dig1 = (parm - (dig3 * 1000) - (dig2 * 100))/10;
dig0 = (parm - (dig3 * 1000) - (dig2 * 100) - (dig1 * 10));
segment[0] = digits[dig0];
segment[1] = digits[dig1];
segment[2] = digits[dig2];
segment[3] = digits[dig3];
}
}

void loop()
{
int value;

while(1) // Repeat forever
{
for (value = 0; value <=1000; value++) // Count from 0 to 1000
{
DisplayValue(value); // Count from 0 to 1000
delay(1000); // Display count on HC4LED module
}
delay(10000); // Wait 1 second
segment[0] = 28; // Setup to display "72°F"
segment[1] = 109; // 2
segment[2] = 15; // °
segment[3] = 71; // F
DisplaySegments(); // Display custom characters
delay(20000); // Wait 2 seconds
} // Repeat forever
}

Thanks! I'll give it a shot!