4x7 segment display (multifunction shield)

what is wrong with this code I can't get it to work

#include <Arduino.h>

// Defineer de pinnen voor de shift registers
const int latchPin = 4; // Aanpassen aan je eigen configuratie (Links 74HC595)
const int clockPin = 7; // Aanpassen aan je eigen configuratie (Links 74HC595)
const int dataPin = 8; // Aanpassen aan je eigen configuratie (Links 74HC595)

// Pinnen voor het rechter shift register (Voer in waarde)
const int rightLatchPin = 5; // Aanpassen aan je eigen configuratie (Rechts 74HC595)
const int rightClockPin = 6; // Aanpassen aan je eigen configuratie (Rechts 74HC595)
const int rightDataPin = 9; // Aanpassen aan je eigen configuratie (Rechts 74HC595)

// Adressen voor de vier 7-segmenten
const int segment1 = 0xF1;
const int segment2 = 0xF2;
const int segment3 = 0xF4;
const int segment4 = 0xF8;

void setup() {
// Initialiseer de display
initDisplay();
}

void loop() {
// Toon het getal 1234 op de display
displayNumber(1234);
delay(2000); // Wacht 2 seconden
clearDisplay(); // Wis de display
delay(1000); // Wacht 1 seconde
}

void initDisplay() {
// Code voor initialisatie, zoals pininstellingen
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);

pinMode(rightLatchPin, OUTPUT);
pinMode(rightClockPin, OUTPUT);
pinMode(rightDataPin, OUTPUT);
}

void clearDisplay() {
// Code om alle segmenten op de display uit te schakelen
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 0);
shiftOut(dataPin, clockPin, LSBFIRST, 0);
digitalWrite(latchPin, HIGH);

digitalWrite(rightLatchPin, LOW);
shiftOut(rightDataPin, rightClockPin, LSBFIRST, 0);
shiftOut(rightDataPin, rightClockPin, LSBFIRST, 0);
digitalWrite(rightLatchPin, HIGH);
}

void displayDigit(int digit, int segment) {
// Code om het cijfer op het opgegeven segment weer te geven
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, segment);
shiftOut(dataPin, clockPin, LSBFIRST, digit);
digitalWrite(latchPin, HIGH);
}

void displayNumber(int number) {
// Code om elk cijfer van het getal weer te geven op de juiste segmenten
int segmentArray[4] = {segment1, segment2, segment3, segment4};

for (int i = 3; i >= 0; i--) {
int digit = number / pow(10, i);
number %= int(pow(10, i));

// Stel het juiste segment in
digitalWrite(rightLatchPin, LOW);
shiftOut(rightDataPin, rightClockPin, LSBFIRST, digit);
digitalWrite(rightLatchPin, HIGH);

// Toon het cijfer op het opgegeven segment
displayDigit(1 << i, segmentArray[3 - i]);

delay(500);  // Wacht 0.5 seconden tussen elk cijfer

}
}

Please read the forum guide in the sticky post, and then edit and fix your post above because it is breaking forum rules.

where do i find it

At the top of most forum sections. But but not this section. If you had read the post at the top of this forum section, you would have known that this is not the right section for your question.

I will move your post to an appropriate forum section. After I do that, you will see the sticky post I mean.

OK.

The sketch compiles without editing. Describe how you expect it to work, and how it is working.

I will guess that the display is not wired correctly. Do you know if your display is common anode or common cathode? Show the display, and how you have it wired.

many things.
it placed not between Code-Tags;
no description about hardware config;
then this:

this:

this:

and this

additional it is missing a conversion function to decode 0-9 number into segments constellation.

Digit pins and Segment pins not defined. (data x 2, clock x 2, latch x 2 were defined)

//Sketch for two 2x7 Common Cathode displays

// Defineer de pinnen voor de shift registers
const uint8_t latchPin = 7; // Aanpassen aan je eigen configuratie (Links 74HC595)
const uint8_t clockPin = 8; // Aanpassen aan je eigen configuratie (Links 74HC595)
const uint8_t dataPin = 9; // Aanpassen aan je eigen configuratie (Links 74HC595)

// Pinnen voor het rechter shift register (Voer in waarde)
const uint8_t rightLatchPin = 4; // Aanpassen aan je eigen configuratie (Rechts 74HC595)
const uint8_t rightClockPin = 5; // Aanpassen aan je eigen configuratie (Rechts 74HC595)
const uint8_t rightDataPin = 6; // Aanpassen aan je eigen configuratie (Rechts 74HC595)

const uint8_t digitCodeMap[] = {
  // GFEDCBA  Segments      7-segment map:
  0b00111111, // 0   "0"          AAA
  0b00000110, // 1   "1"         F   B
  0b01011011, // 2   "2"         F   B
  0b01001111, // 3   "3"          GGG
  0b01100110, // 4   "4"         E   C
  0b01101101, // 5   "5"         E   C
  0b01111101, // 6   "6"          DDD
  0b00000111, // 7   "7"
  0b01111111, // 8   "8"
  0b01101111 // 9   "9"
};

void setup() {
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);

  pinMode(rightLatchPin, OUTPUT);
  pinMode(rightClockPin, OUTPUT);
  pinMode(rightDataPin, OUTPUT);
}

void loop() {
  // Toon het getal 1234 op de display
  displayNumber(1234);
  delay(2000); // Wacht 2 seconden
  clearDisplay(); // Wis de display
  delay(1000); // Wacht 1 seconde
}

void clearDisplay() {
  // Code om alle segmenten op de display uit te schakelen
  digitalWrite(latchPin, LOW);
  digitalWrite(rightLatchPin, LOW);

  shiftOut(dataPin, clockPin, LSBFIRST, 0);
  shiftOut(dataPin, clockPin, LSBFIRST, 0);
  shiftOut(rightDataPin, rightClockPin, LSBFIRST, 0);
  shiftOut(rightDataPin, rightClockPin, LSBFIRST, 0);

  digitalWrite(latchPin, HIGH);
  digitalWrite(rightLatchPin, HIGH);
}

void displayNumber(int number) {

  // Toon het cijfer op het opgegeven segment
  shiftOut(dataPin, clockPin, MSBFIRST, digitCodeMap[(number / 1000) % 10]);
  shiftOut(dataPin, clockPin, MSBFIRST, digitCodeMap[(number / 100) % 10]);
  digitalWrite(latchPin, LOW);
  digitalWrite(latchPin, HIGH);

  shiftOut(rightDataPin, rightClockPin, MSBFIRST, digitCodeMap[(number / 10) % 10]);
  shiftOut(rightDataPin, rightClockPin, MSBFIRST, digitCodeMap[number % 10]);
  digitalWrite(rightLatchPin, LOW);
  digitalWrite(rightLatchPin, HIGH);

}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.