8 Digit Display Module Help

Hi there, I am currently in the process of making a project with requires a score system. I have been having trouble making my 8 digit display module do what I am after. I am using an Arduino Compatible 8 Digit Display Module (https://www.wiltronics.com.au/wp-content/uploads/datasheets/ARD2-2073%20Data%20Sheet.pdf) and want the screen to initially display the number 0 on the far right. I then want the number on the screen to increase by 100 when ever my bump sensor is hit. (E.g start at 0 and each time the sensor is hit the score will increase by 100). I have been playing around with my code for a number and days and am struggling to find examples to refer to that I understand (I am a beginner with the arduino code)
The current code I have is:

const int clock = 7; //SCK
const int latch = 5; //RCK
const int data = 6;  //DIO

int buttonpin = 3; // define the key switch sensor interface
int buttonState = 0;

int bumppin = 42;

int redpin = 11; // select the pin for the red LED
int greenpin = 10; // select the pin for the green LED


int val ; // define numeric variables val

byte value[] = {
  B11000000, // 0
  B11111001, // 1
  B10100100, // 2
  B10110000, // 3
  B10011001, // 4
  B10010010, // 5
  B10000010, // 6
  B11111000, // 7
  B10000000, // 8
  B10010000, // 9
  B11000000, // 0
  B11111111  // display nothing
};

byte digit[] = {
  B00000001, // left segment
  B00000010,
  B00000100,
  B00001000,
  B00010000,
  B00100000,
  B01000000,
  B10000000 // right segment
};

void setup() {
  pinMode (redpin, OUTPUT);
  pinMode (greenpin, OUTPUT);

  pinMode (bumppin, INPUT);

  pinMode (buttonpin, INPUT) ; // define the key switch sensoroutput interface

  Serial.begin(9600);
  pinMode(clock, OUTPUT);
  pinMode(latch, OUTPUT);
  pinMode(data, OUTPUT);

  digitalWrite(latch, LOW);
  shiftOut(data, clock, MSBFIRST, B11111111); // select all segments
  shiftOut(data, clock, MSBFIRST, B11111111); // display nothing
  digitalWrite(latch, HIGH);

  digitalWrite(latch, LOW);
  shiftOut(data, clock, MSBFIRST, digit[7]); // select the seventh segment from left
  shiftOut(data, clock, MSBFIRST, value[0]); // show the digit "0" ( the array starts with 0 to count!)
  digitalWrite(latch, HIGH);
}



void loop()
{
  buttonState = digitalRead(bumppin);
  if (buttonState == HIGH) // When the key switch when the sensor detects a signal, LED flashes
  {
    digitalWrite (redpin, HIGH);
  }
  else
  {
    digitalWrite (redpin, LOW);
  }
}

The current code I have displays the number 0 on the far right segment but I can not work out how to make the value on the screen increase by 100 when the bump sensor is hit.
I am using an Genuine Arduino Mega 2560 R3 and also have a breadboard.

If anyone could give me some pointers in the right direction or show me some examples that would be amazing!
Thanks,

Bump Sensor I am using:

8 Digit Display I am using:

Honestly, my advice would be to just chuck that display in a drawer and get a proper one using a MAX7219 - presumably from eBay. It is nothing more than a toy, badly conceived and I think also badly designed - I cannot see the eight resistors required - or are they on the back?

That datasheet does not even include the circuit diagram. The code given unnecessarily mucks about with the Arduino timers - everything about it is a kluge!

Get one (or three) of these:

Xenolithhh:

int bumppin = 42;

Forty-two! :astonished: What - HHGTTG fan?

Are you using a Mega? :roll_eyes:

Really! While you are getting the proper display, just get a couple of cheap Nano (clone)s. :grinning: These work well with breadboards; there are very few applications where it would make sense to use a Mega.

This seems to be one of these displays that needs to be updated all the time…

Something like this should work:

const int clock = 7; //SCK
const int latch = 5; //RCK
const int data = 6;  //DIO


byte value[] = {
  B11000000, // 0
  B11111001, // 1
  B10100100, // 2
  B10110000, // 3
  B10011001, // 4
  B10010010, // 5
  B10000010, // 6
  B11111000, // 7
  B10000000, // 8
  B10010000, // 9
  B11000000, // 0
  B11111111  // display nothing
};

byte digit[] = {
  B00000001, // left segment
  B00000010,
  B00000100,
  B00001000,
  B00010000,
  B00100000,
  B01000000,
  B10000000 // right segment
};

void setup() {
  pinMode(clock, OUTPUT);
  pinMode(latch, OUTPUT);
  pinMode(data, OUTPUT);
}

#define digitCount 8
uint8_t displayData[digitCount];
uint8_t activeDigit = 0;
void updateDisplay(){
  activeDigit = (activeDigit + 1) % digitCount;

  digitalWrite(latch, LOW);
  shiftOut(data, clock, MSBFIRST, digit[activeDigit]); // select the seventh segment from left
  shiftOut(data, clock, MSBFIRST, displayData[activeDigit]); // show the digit "0" ( the array starts with 0 to count!)
  digitalWrite(latch, HIGH);
}

void drawInt(int v){
  for(int x=0; x < digitCount; x++){
    displayData[x] = value[(v%10)];
    v = v / 10;
  }
}

unsigned long lastCount = 0;
int c = 0;
void loop()
{
    updateDisplay();

    unsigned long now = millis();
    if(now - lastCount > 500){
      c += 7;
      drawInt(c);
      lastCount = now;
    }
}

(Could not test it, I hope there are no bugs in the code.)

Better get a display with a HT16K33 or MAX7219 next time.

I had just replied to another similar question when I answered this. The problem is that you cannot just run through displaying all the digits, one after the other and then go and do something else because it will "stick" on the last digit illuminated. Or switch off that digit and the display may then flicker.

Multiplexing in software requires a strict discipline in code where the outermost task is to step from one digit to the next and - using millis() to clock when to change to the next digit - all tasks within the loop must be able to be completed within that timeframe in order not to alter that timing. Your whole code is dedicated to the multiplexing rather than the task you originally intended! :astonished:

You can use a timer interrupt to do the multiplexing, but that necessarily "consumes" a timer function which you then cannot use for something else - and of course, you must get that code right and it must not interfere with any other time-critical function.

Alright, thank you very much for the help guys! What i'll do is get another display and hopefully that will work out better. Thanks for the help :slight_smile: