HC4LED Scoreboard

hello I am still very new to the arduino language. I would like to eventually make a two player scoreboard using the HC4LED display. I want the scoreboard to have a plus and a minus for each player. I was wondering if someone could point me into some direction as how to code for a device as such. I have no written code and would like some help with this. If anyone would like to help me it would be greatly appreciated. Thanks
ed

Take a look at the playground page I just posted for a basic starting place.

http://www.arduino.cc/playground/ComponentLib/hc4led

hi

there have been several threads on this.. I think the code has actually already been written. Maybe you can put it all together on that playground page!

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1157807338/
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1154868522

D

thanks daniel and bdmatic
these links helped out a whole lot
i think i can get the coding done now
but i do have one question about this code

#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 upPin = 7;   // pushbutton for counting up
int dnPin = 5;   // pushbutton for counting down
int val = 0;     // variable for reading the pin status
int time = 0;  // the number to display
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);    
  pinMode(upPin, INPUT);    // declare pushbutton as input
  pinMode(dnPin, INPUT);    // declare pushbutton as input
}

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()
{
  val = digitalRead(upPin);  // read input value
  if (val == HIGH) {         // check if the input is HIGH (button pressed)
    time = time + 1;  // increment the number
    numOut(time);  //use this function to display what you want to display
    Serial.println(time);
    delay(1000);
    }
  val = digitalRead(dnPin);  // read input value
  if (val == HIGH) {         // check if the input is HIGH (button pressed)
    time = time - 1;  // decrement the number
    numOut(time);  //use this function to display what you want to display
    Serial.println(time);
    delay(1000);
  }
  delay(10);
}

ok so

  1. I don not understand for (g=3; g >= 0; g--) or for (i=7; i>=0; i--)
    what are the g and the i for?
  2. what does this do? char* numStr = " ";
    and i think this is related char* *numStrPtr;
  3. what does the minDelay, Flashdelay, and Curdelay do? and why is there no Curdelay variable set?
  4. what are the DigitC, DigitE, and DigitF things for?
  5. what is itoa? i read about it in the other links but still dont understand

thanks for all your help

Look at the code I posted- it's a simplified version of your's.

how is it a simplified version it doesnt even work???

can someone explain how i can make the HC4LEDa score board for 2 players, 2 digits per person?
essentially i want 2 of the buttons to count up and down by ones and 2 other buttons to count up and down by hundreds

here is my code so far which is for one player only

#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 upPin = 7;   // pushbutton for counting up
int dnPin = 5;   // pushbutton for counting down
int val = 0;     // variable for reading the pin status
int time = 0;  // the number to display
int dn_pin_val = 0;
int up_pin_val = 0;
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);    
  pinMode(upPin, INPUT);    // declare pushbutton as input
  pinMode(dnPin, INPUT);    // declare pushbutton as input
}

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()
{
  dn_pin_val = digitalRead(dnPin);
  up_pin_val = digitalRead(upPin);  // read input value
  if (up_pin_val == LOW)        // check if the input is HIGH (button pressed)
    {
    time++;  // increment the number
    }
   else if (dn_pin_val == LOW)         // check if the input is HIGH (button pressed)
    {
    time--;  // decrement the number
    }
    numOut(time);  //use this function to display what you want to display
    delay(1000);
}

one more thing, when i use this code above, i have to hold the up and down buttons for at least 1 second, is there a way to minimize this delay?

anyone? :frowning:

I'll upload it tonight since I have one of these and see what I can do. I haven't looked at the HC4LED in about 6 months so it might take me a bit to get back up to speed.

when i use this code above, i have to hold the up and down buttons for at least 1 second, is there a way to minimize this delay?

Well, down towards the end you have delay(1000); - that's your one second delay. Another "feature" of this method is that it'll repeat once a second if you continue to hold it.

You are using a method called polling - you poll your inputs once a second to see if they have changed. You can cut down this interval to reduce the delay.

To avoid multiple counts with a single button press, you will need use timers to see how long it's been since you have acted on a button press, or use flags to see if you are dealing with the situation where the button was just pressed and you need to act on it, or the button is still pressed and you have already acted on it.

Here's a quick example of handling a single button using flags to make sure we only count once per button press:

void loop()
{
  static byte player_one_up_pressed = 0;

  if (digital_read(player_one_up_pin))
  {
     if (!player_one_up_pressed)
     {
         player_one_up_pressed = 1;
         player_one_score++;
     }
  }
  else // player_one_up_pin is 0
  {
    player_one_up_pressed = 0;
  }

  display_score();
  delay(200);  // debounce delay
}

The only magic here is the static directive, which tells the compiler to keep the value of this variable between function calls. Normally variables are automatic, which means they are allocated and initialized when the function starts, then go away when the function returns.

Another way is to use interrupts instead of polling, but the ATmega8/168 only has two interrupts (which leaves you short since you want to count up and down for each player for a total of 4 inputs).

There's another issue known as debounce, so some sort of delay is desirable so that you don't get multiple hits as the signal "settles" to a steady state (usually happens when the signal goes positive).

-j

thanks j that helps a bunch
Im gonna test out your advise right now