Problem with LCD_I2C and 7-Segment

When I try to controll both my LCD (I2C) and my 7-segment together. It seems to be that the text I
want to get on my LCD is shown on the 7 segment, I know that's impossible but I don't understand what's happening. Segment A and B are brighter when I plug my LCD in the arduino.

I have an arduino Leonardo, the LCD has an VCC, GND, SDA and SCL pin.

Can someone please help me fix this problem?
Thanks!


// C++ code
//

const int welkdisplay = 9;

int lijst1[] = {3, 4};
int lijst2[] = {2, 3, 5, 6, 8};
int lijst3[] = {2, 3, 4, 5, 8};
int lijst4[] = {3, 4, 7, 8};
int lijst5[] = {2, 4, 5, 7, 8};
int lijst6[] = {2, 4, 5, 6, 7, 8};
const int selecteren1 = 10;
const int selecteren2 = 1;

const int pinButton1 = 11;
const int pinButton2 = 12;
const int pinButton3 = 13;

#include <LiquidCrystal_I2C.h> 
LiquidCrystal_I2C lcd(0x27,16,2);

void setup()
{
  pinMode(welkdisplay, OUTPUT);
  pinMode(selecteren1, OUTPUT);
  pinMode(selecteren2, OUTPUT);
  pinMode(pinButton1, INPUT_PULLUP);
  pinMode(pinButton2, INPUT_PULLUP);
  pinMode(pinButton3, INPUT_PULLUP);
  int aantal = 0;

  
  
}

void loop()
{
  int nummer1;
  int nummer2;
  int aantal;

  int state1 = digitalRead(pinButton1);
  int state2 = digitalRead(pinButton2);
  int state3 = digitalRead(pinButton3);
  
  if(state1 == LOW & state3 == HIGH & state2 == HIGH)
  {  
    delay(500);
    nummer1 = random(1,7);
    nummer2 = random(1,7);
 
    digitalWrite(selecteren1,0);
    digitalWrite(selecteren2,0);
    
    lcd.init();
    lcd.backlight();
    lcd.setCursor(1,0);
    lcd.print("Welkom");
    delay(10000);
    lcd.clear();
  }
  if(state1 == HIGH & state3 == LOW & state2 == HIGH)
  {
    nummer2 = random(1,7);
    digitalWrite(selecteren1,0);
    digitalWrite(selecteren2,0);
    delay(500);
  }
  if(state1 == HIGH & state3 == HIGH & state2 == LOW)
  {
    nummer1 = random(1,7);
    digitalWrite(selecteren1,0);
    digitalWrite(selecteren2,0);
    delay(500);
  }

  
  digitalWrite(welkdisplay, 0);
  if(nummer1 == 1)
  {
    for(int i = 0; i <= 1; i++)
    {
      digitalWrite(lijst1[i], 1);
    }
    digitalWrite(selecteren1, HIGH);     
  }
  
  if(nummer1 == 2)
  {
    for(int i = 0; i <= 4; i++)
    {
      digitalWrite(lijst2[i], 1);
    } 
    digitalWrite(selecteren1, HIGH); 
  }
  
  if(nummer1 == 3)
  {
    for(int i = 0; i <= 4; i++)
    {
      digitalWrite(lijst3[i], 1);
    }
  }

  if(nummer1 == 4)
  {
    for(int i = 0; i <= 3; i++)
    {
      digitalWrite(lijst4[i], 1);
    }
  }

  if(nummer1 == 5)
  {
    for(int i = 0; i <= 4; i++)
    {
      digitalWrite(lijst5[i], 1);
    }
  }

  if(nummer1 == 6)
  {
    for(int i = 0; i <= 5; i++)
    {
      digitalWrite(lijst6[i], 1);
    }
  }
  for(int i = 2; i <= 8; i++)
  {
    digitalWrite(i, 0);
  }

  digitalWrite(welkdisplay, 1);
  if(nummer2 == 1)
  {
    for(int i = 0; i <= 1; i++)
    {
      digitalWrite(lijst1[i], 1);
    }
    digitalWrite(selecteren2, HIGH);
  }
  
  if(nummer2 == 2)
  {
    for(int i = 0; i <= 4; i++)
    {
      digitalWrite(lijst2[i], 1);
    }
    digitalWrite(selecteren2, HIGH);
  }

  if(nummer2 == 3)
  {
    for(int i = 0; i <= 4; i++)
    {
      digitalWrite(lijst3[i], 1);
    }
  }

  if(nummer2 == 4)
  {
    for(int i = 0; i <= 3; i++)
    {
      digitalWrite(lijst4[i], 1);
    }
  }

  if(nummer2 == 5)
  {
    for(int i = 0; i <= 4; i++)
    {
      digitalWrite(lijst5[i], 1);
    }
  }

  if(nummer2 == 6)
  {
    for(int i = 0; i <= 5; i++)
    {
      digitalWrite(lijst6[i], 1);
    }
  }
  for(int i = 2; i <= 8; i++)
  {
    digitalWrite(i, 0);
  }
}

Before asking questions, read the forum’s guidelines.

please post

  • a schematic
  • real pictures where we can see each single wire
  • the sketch in code tags you have uploaded. If you are using any libraries don't let us guess and Link to the used libraries.
1 Like

You're powering the LED from the Arduino. You're probably near the current limit. Power the LED separately and see if that helps.

Why do you have these resistors on the I2C lines :thinking:

ALL I.C.s should have decoupling capacitors.

Did you mean:

if(state1 == LOW && state3 == HIGH && state2 == HIGH)

Always show us a good schematic of your proposed circuit.
Give links to components.

Before we go on, you have used bitwise "and", the '&' operator. That is not appropriate for operations on boolean variables, where you should use the boolean "and", '&&'.

Enhancements to the language now permit you to use the word "and" as a key word, I recommend using it, especially if you are confused about the difference.

  if(state1 == LOW and state3 == HIGH and state2 == HIGH)

Have you considered, what will happen to your display when your program executes

delay(500);

?
The display is multiplexed, it will freeze on whatever state it happens to be in, and remain in that state for as much as half a second. Perhaps that is what you see?

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