I don't understand why my Screen doesn't show me the information



#include <LCD5110_Graph.h>

LCD5110 myGLCD(8,9,10,12,11);

extern uint8_t SmallFont[];

// Mux control pins
int s0 = 2;
int s1 = 3;
int s2 = 4;
int s3 = 5;

// Mux in "SIG" pin
int SIG_pin = A0;

void setup() {
  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);
  randomSeed(analogRead(7));

  pinMode(s0, OUTPUT);
  pinMode(s1, OUTPUT);
  pinMode(s2, OUTPUT);
  pinMode(s3, OUTPUT);

  digitalWrite(s0, LOW);
  digitalWrite(s1, LOW);
  digitalWrite(s2, LOW);
  digitalWrite(s3, LOW);

  Serial.begin(9600);

  myGLCD.clrScr();
  myGLCD.print(const_cast<char*>("Ready?"), CENTER, 20);
  myGLCD.update();
}

int gameRounds = 0;
int totalScore = 0;

void loop() {
  bool sensorTriggered = false;
  while (!sensorTriggered) {
    for (int i = 0; i < 4; i++) {
      if (readMux(i) > 0.35) {
        sensorTriggered = true;
        break;
      }
    }
  }

  if (gameRounds < 10) {
    int score = startGame();
    totalScore += score;
    gameRounds++;
  } else {
    displayEndMessage();
    delay(10000); // Attendre 10 secondes avant de redémarrer les rounds
    gameRounds = 0;
    totalScore = 0;
  }
  delay(1000);
}

void displayEndMessage() {
  myGLCD.clrScr();
  myGLCD.print(const_cast<char*>("Felicitation!"), CENTER, 0);
  myGLCD.print(const_cast<char*>("Les 10 rounds"), CENTER, 10);
  myGLCD.print(const_cast<char*>("sont termines."), CENTER, 20);
  myGLCD.print(const_cast<char*>("Score total:"), CENTER, 30);
  myGLCD.printNumI(totalScore, CENTER, 40);
  myGLCD.update();
}

int startGame() {
  int targetChannel = random(4);
  myGLCD.clrScr();
  myGLCD.print(const_cast<char*>("Eclairez"), CENTER, 0);
  myGLCD.print(const_cast<char*>("capteur"), CENTER, 10);
  myGLCD.printNumI(targetChannel, CENTER, 20);
  myGLCD.update();

  unsigned long startTime = millis();
  int remainingTime = 30;
  bool answeredCorrectly = false;
  bool wrongSensorTriggered = false;
  int score = 0;

  while (remainingTime > 0 && !answeredCorrectly && !wrongSensorTriggered) {
    unsigned long currentTime = millis();
    if (currentTime - startTime >= 1000) {
      startTime = currentTime;
      remainingTime--;

      // Afficher le temps restant
      myGLCD.clrRect(0, 40, 83, 47); // Effacer la zone du timer
      myGLCD.print(const_cast<char*>("Temps: "), LEFT, 40);
      myGLCD.printNumI(remainingTime, 40, 40);
      myGLCD.update();
    }

        float luxValue = readMux(targetChannel);
    if (luxValue > 0.35) {
      answeredCorrectly = true;
      score = remainingTime * 100 / 30;
    }

    // Vérifier si un mauvais capteur a été éclairé
    for (int i = 0; i < 4; i++) {
      if (i != targetChannel) {
        if (readMux(i) > 0.35) {
          wrongSensorTriggered = true;
          break;
        }
      }
    }
  }

  myGLCD.clrScr();
  if (answeredCorrectly) {
    myGLCD.print(const_cast<char*>("Bien joue !"), CENTER, 20);
    myGLCD.print(const_cast<char*>("Score: "), LEFT, 30);
    myGLCD.printNumI(score, 40, 30);
  } else if (wrongSensorTriggered) {
    myGLCD.print(const_cast<char*>("Reessaie"), CENTER, 20);
  } else {
    myGLCD.print(const_cast<char*>("Temps ecoule"), CENTER, 20);
  }
  myGLCD.update();
  delay(3000);

  return score;
}

float readMux(int channel) {
  int controlPin[] = {s0, s1, s2, s3};

  int muxChannel[16][4] = {
    {0, 0, 0, 0},
    {1, 0, 0, 0},
    {0, 1, 0, 0},
    {1, 1, 0, 0},
    {0, 0, 1, 0},
    {1, 0, 1, 0},
    {0, 1, 1, 0},
    {1, 1, 1, 0},
    {0, 0, 0, 1},
    {1, 0, 0, 1},
    {0, 1, 0, 1},
    {1, 1, 0, 1},
    {0, 0, 1, 1},
    {1, 0, 1, 1},
    {0, 1, 1, 1},
    {1, 1, 1, 1}
  };

  for (int i = 0; i < 4; i++) {
    digitalWrite(controlPin[i], muxChannel[channel][i]);
  }

  int val = analogRead(SIG_pin);

  float voltage = (val * 5.0) / 1024.0;
  float resistance = (5.0 - voltage) * 10000.0 / voltage;
  float lux = 500.0 / resistance;

  return lux;
}

moderator edit: code tags


Posting an annotated schematic would help a lot. You took great pictures but I cannot follow your design nor can I read the pin designates.

2 Likes

As @gilshultz says
How to make a schematic you can post. - Using Arduino / Introductory Tutorials - Arduino Forum

1 Like

@pvac was asked twice to provide a schematic of this circuit on another thread, does not seem to be interested in doing that.

2 Likes

do you have a good app for this type of schematic ?

Sheet of A4 and a pencil

We do not understand why you do not want to provide an annotated schematic. Speaking the language helps all of us understand your problem. This is not the first time you have avoided posting the schematic. If you do not know how there are many tutorials, books, etc on how to do it and a lot of help online as well.

Don't see any level shifters..
Check the screen manual, page 3..
SBC-LCD84x48_Manual_2023-04-24.pdf

good luck.. ~q

1 Like


there is my LCD PART, sorry for my absence, i was in college

Better?

image

And this LCD?

Have you wired the SPI interface connections correctly?

Needs level shifters.

Page 3:

Does it really matter if I don’t have a Level Shifter? There won’t be another way because I don’t have a level shifter.

Precisely, this is where I think there is a mistake, I tried the PIN of the data sheet but it does not work, it is that I ask you the question: is what I did well as in the data sheet? knowing that I don’t have a "level Shifter"

Normal resistors configured in a voltage divider that drops each lead of the 5v (Arduino) to 3v3 (display)... so, two resistors per lead.

(Late edit... i forgot to include this tutorial link)

1 Like

i did something, and it's actualy working without level shifter so it's okay, thanks for your precious help !!

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