Seven segment flashes when combined with other programs

excuse me I want to ask,
I'm working on a bank queue system project based on Arduino Mega 2560, the components used are
an ultrasonic sensor as a queue number paper printer, seven-segment as a display viewer,
df player and speaker as service caller,

long story short, after the program, is put together then the seven-segment flashes...
the question is, how to prevent the seven-segment flicker from happening when it is combined with other programs? here is the program

#include "PString.h"
#include "Adafruit_Thermal.h"
#include "SoftwareSerial.h"
#define TX_PIN 15  // Pin 11 Arduino ke RX Printer
#define RX_PIN 14  // Pin 10 Arduino ke TX Printe
SoftwareSerial mySerial(RX_PIN, TX_PIN); 
Adafruit_Thermal printer(&mySerial);  

int hitung_teller = 0;
int hitung_CS = 0;

int trig_teller = 13; // membuat varibel trig di set ke-pin 11 
int echo_teller = 44; // membuat variabel echo di set ke-pin 12 
long durasi_teller, jarak_teller; // membuat variabel durasi dan jarak 

int trig_CS = 45;
int echo_CS = 46;
long durasi_CS, jarak_CS;

const int buttonPin = A4;
long lastDebounceTime = 0;
long debounceDelay = 50;
int buttonState = 0;
int lastButtonState = LOW;

//=================seven segmen=====================//
long lastButton = 0;
long delayAntiBouncing = 50;
byte panggilTeller, panggilCS;
byte seven_seg_digits[10][7] {
 {0, 0, 0, 0, 0, 0, 1},
 {1, 0, 0, 1, 1, 1, 1},
 {0, 0, 1, 0, 0, 1, 0},
 {0, 0, 0, 0, 1, 1, 0},
 {1, 0, 0, 1, 1, 0, 0},
 {0, 1, 0, 0, 1, 0, 0},
 {0, 1, 0, 0, 0, 0, 0},
 {0, 0, 0, 1, 1, 1, 1},
 {0, 0, 0, 0, 0, 0, 0},
 {0, 0, 0, 0, 1, 0, 0},
};

//================SPEAKER====================//
#include <miniMP3.h>

#define belas 12 //belas.mp3
#define puluh 13 //puluh.mp3
#define seratus 14 //seratus.mp3
#define ratus 15 //ratus.mp3
#define seribu 16 //seribu.mp3
#define ribu 17 //ribu.mp3

#define nomorantrian 170 //nomor antrian.mp3
#define teller 190
#define customers 191
  uint32_t NomorPanggilTeller = 0;
  uint16_t NomorPanggilCS2 = 0;
  

//===================SETUP===============//
void setup(){
 
 pinMode(trig_teller, OUTPUT); // set pin trig menjadi OUTPUT
 pinMode(echo_teller, INPUT); // set pin echo menjadi INPUT 
 pinMode(trig_CS, OUTPUT);
 pinMode(echo_CS, INPUT);
 pinMode(buttonPin, INPUT_PULLUP);
 Serial.begin(9600);
 mySerial.begin(9600); // digunakan untuk komunikasi Serial dengan komputer 
 printer.begin();
 mp3_set_serial (Serial1, 17);
 mp3_set_volume(30);
for(char i=2; i<13; i++){
pinMode(i,OUTPUT);
}
pinMode(A0,INPUT); //buttonTeller
pinMode(A2,INPUT); //buttonCS
pinMode(A4,INPUT); //buttonRiset
digitalWrite(A0,HIGH);
digitalWrite(A2,HIGH);
digitalWrite(A4,HIGH);
}

//====================program utama================//
void loop(){
  digitalWrite(trig_teller, LOW);
 delayMicroseconds(8); 
 digitalWrite(trig_teller, HIGH); 
 delayMicroseconds(8); 
 digitalWrite(trig_teller, LOW); 
 delayMicroseconds(8);
 durasi_teller= pulseIn(echo_teller, HIGH); // menerima suara ultrasonic 

 digitalWrite(trig_CS, LOW);
 delayMicroseconds(8); 
 digitalWrite(trig_CS, HIGH); 
 delayMicroseconds(8); 
 digitalWrite(trig_CS, LOW); 
 delayMicroseconds(8);
 durasi_CS= pulseIn(echo_CS, HIGH); // menerima suara ultrasonic 
 
 jarak_teller= (durasi_teller/2) / 29.1; // mengubah durasi menjadi jarak (cm) 
 jarak_CS = (durasi_CS/2) / 29.1; // mengubah durasi menjadi jarak (cm)
 Serial.println(jarak_teller); // menampilkan jarak pada Serial Monitor 
 Serial.println(jarak_CS); // menampilkan jarak pada Serial Monitor 

 if (jarak_teller <= 6) {
   printer.wake();
   printer.setDefault();
   hitung_teller += 1;
   char buffer[40];
   PString str(buffer, sizeof(buffer));
   if (hitung_teller < 10)
   {
     str.print(0);
     if (hitung_teller > 10)
     {
       str.print(1);
     }
   }
  
   str.print(hitung_teller);

   printer.boldOn();
   printer.setSize('L');
   printer.println("Nomor Antrian");
   printer.justify('C');
   printer.setSize('M');
   printer.println(str);
   printer.setSize('M');
   printer.println("Teller");
   printer.feed(3);
   printer.sleep(); 
 }

 else {
   printer.sleep();
 }

 if (jarak_CS < 6) {
   printer.wake();
   printer.setDefault();
   hitung_CS += 1;
   char buffer[40];
   PString str(buffer, sizeof(buffer));
   if (hitung_CS < 10)
   {
     str.print(0);
     if (hitung_CS > 10)
     {
       str.print(1);
     }
   }
 
   str.print(hitung_CS);

   printer.boldOn();
   printer.setSize('L');
   printer.println("Nomor Antrian");
   printer.justify('C');
   printer.setSize('M');
   printer.println(str);
   printer.setSize('M');
   printer.println("Customer service");
   printer.feed(3);
   printer.sleep(); 
 }

 else {
   printer.sleep();
 }

 if (!(digitalRead(buttonPin)))  {
   printer.wake();
   printer.setDefault();
   hitung_teller = 0;
   hitung_CS = 0;
   char buffer[40];
   PString str(buffer, sizeof(buffer));
   printer.justify('C');
   printer.setSize('M');
   printer.println(F("Printer direset"));
   hitung_teller = 0;
   hitung_CS = 0;
   printer.feed(3);
   printer.sleep();
 }

 else {
   printer.sleep();
 }
 
tampilSkor();
tombol();
}

void tampilSkor(){
digitalWrite(10,LOW); digitalWrite(9,HIGH);
digitalWrite(11,HIGH); digitalWrite(12,HIGH);
sevenSegWrite(panggilTeller / 10);
delay(5);
digitalWrite(10,HIGH); digitalWrite(9,LOW);
digitalWrite(11,HIGH); digitalWrite(12,HIGH);
sevenSegWrite(panggilTeller % 10);
delay(5);
digitalWrite(10,HIGH); digitalWrite(9,HIGH);
digitalWrite(11,LOW); digitalWrite(12,HIGH);
sevenSegWrite(panggilCS/ 10);
delay(5);
digitalWrite(10,HIGH); digitalWrite(9,HIGH);
digitalWrite(11,HIGH); digitalWrite(12,LOW);
sevenSegWrite(panggilCS % 10);
delay(5);
}

void sevenSegWrite(byte segment){
 byte pin = 2;
 for (byte segCount = 0; segCount < 7; ++segCount) {
 digitalWrite(pin, seven_seg_digits[segment][segCount]);
 ++pin;
 }
}

void tombol(){
//-----------------tombol Teller =================
if(digitalRead(A0)==0){
if(hitung_teller > panggilTeller){
if ((millis() - lastButton) > delayAntiBouncing ){
panggilTeller++;
mp3_play(nomorantrian);
suaraBilangan(panggilTeller);
 mp3_play(teller);
if(panggilTeller>=100)panggilTeller = 0;
}
lastButton = millis();
}
}

//-----------------tombol CS ====================
if(digitalRead(A2)==0){
if (hitung_CS > panggilCS){
if ((millis() - lastButton) > delayAntiBouncing){
panggilCS++;
mp3_play(nomorantrian);
      suaraBilangan(panggilCS);
      mp3_play(customers);
if(panggilCS>=100)panggilCS= 0;
}
lastButton = millis();
}
}

//---------------tombol RESET
if(digitalRead(A4)==0){
if ((millis() - lastButton) > delayAntiBouncing){
panggilTeller=0;
panggilCS=0;
}
lastButton = millis();
}
}

void suaraBilangan(uint32_t Bilangan)
{
 if (Bilangan < 12)
 {
   mp3_play(Bilangan);
 }
 else if (Bilangan < 20)
 {
   suaraBelasan(Bilangan);
 }
 else if (Bilangan < 100)
 {
   suaraPuluhan(Bilangan);
 }
}
void suaraBelasan(uint8_t Bilangan)
{
 mp3_play(Bilangan - 10);
 mp3_play(belas);
}
void suaraPuluhan(uint8_t Bilangan)
{
 uint8_t puluhan = Bilangan / 10;
 mp3_play(puluhan);
 mp3_play(puluh);

 uint8_t satuan = Bilangan % 10;
 if (satuan)
 {
   suaraBilangan(satuan);
 }
}

Maybe using a separate chip for 7-segment LED control like the MAX7219 (MAX7221).

It looks like you are using dynamic indication.
Then from the beginning of the loop() to the tampilSkor() call your indication does not work.
Use a 7-segment display with a chip (SparkFun 7-Segment Serial Display, TM1637 4-Digit 7-Segment Display) or a dedicated chip to drive a 7-segment display as recommended by @flashko.

what is the program for the seven segment? does anything need to be added to get rid of the blink.

Hi, @muhamadrivaldi

Can you please post a circuit diagram?

Because your code is directly controlling each segment, and the code does other things, it cannot update the display regualrly.
You need to have a 7seg display with its own driver that will keep your display alive while your code does other things.
Like in this tutorial;

Using modules like this,


Tom... :smiley: :+1: :coffee: :australia:

You don't hear the answers.
Explore your code.
You must understand every line in your code.
Then we will continue the conversation.

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