LCD display zeigt nur 2 seiten

Hallo zusammen,

Ich habe ein 128x64 display für ein gps tripmeter.

Das funktioniert soweit auch.
Mit einem knopf setze ich die starposition zurück und mit einem zweiten knopf schalte ich die angezeigte seite um.

Das funktioniert bei der ersten und zweiten seite aber die dritte wird mir nicht angezeigt :frowning:

Kann mir bite jemand erklären warum?

#define SwitchPIN 8
#include "U8glib.h"
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2

TinyGPSPlus gps;
SoftwareSerial ss(3, 4);    //rx tx

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);


U8GLIB_ST7920_128X64 u8g(5, 6, 7, U8G_PIN_NONE);



float TargetGpsLAT = 48.3581916;  // Coordinates EIFFEL_TOWER in France
float TargetGpsLON = 12.5119766;
bool DistanceInKM = false;
bool Button1Pressed = false;
double Distance = 0;
double courseToT = 0;

int car;
int sensor = 0;
int pwm = 0;
const int potiPin = A5;
int trigger = A0;
int echo = A1;
long dauer = 0;
long entfernung = 0;

////////////////////////////////////////////////////////////////////////////
//int Ledblau = ;
//int Ledrot = ;
//int Ledgruen = ;
//int Ledorange = ;
//int buttonpin = ;
//int val = 0;
////////////////////////////////////////////////////////////////////////////
#include "U8glib.h"

RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001";

#define botao A2
int estado_botao = 0;
void draw1() {
  if (gps.altitude.isValid() )
  {
    ////////////////////////////////////////////////////////////////////////////
    //   digitalWrite( Ledblau, HIGH);
    ////////////////////////////////////////////////////////////////////////////
    if (gps.altitude.isUpdated() || gps.satellites.isUpdated() || gps.course.isUpdated() )
    {

      u8g.setFont(u8g_font_fixed_v0);
      u8g.setPrintPos(75, 20);
      u8g.print("Alt:");
      u8g.setPrintPos(100, 20);
      u8g.print(gps.altitude.meters());
      u8g.setPrintPos(95, 10);
      u8g.print("S:");
      u8g.setPrintPos(110, 10);
      u8g.print(gps.satellites.value());
      u8g.setPrintPos(42, 20);
      u8g.print("C:");
      u8g.setPrintPos(52, 20);
      u8g.print(gps.course.deg()); // Course in degrees (double)
    }
  }
  else
  {

    u8g.setFont(u8g_font_fixed_v0);
    u8g.setPrintPos(75, 20);
    u8g.print("Alt:");
    u8g.setPrintPos(100, 20);
    u8g.print("000");

    u8g.setPrintPos(42, 20);
    u8g.print("C:");
    u8g.setPrintPos(52, 20);
    u8g.print("000"); // Course in degrees (double)
    //u8g.print("No valid Data");
  }

  if (gps.location.isValid())
  {
    if (gps.location.isUpdated() || gps.location.isValid())
    {
      u8g.setFont(u8g_font_fixed_v0);
      u8g.setPrintPos(15, 30);
      u8g.print("POS. Aktuel:");
      u8g.setPrintPos(1, 40);
      u8g.print("BG:");
      u8g.setPrintPos(20, 40);
      u8g.print(gps.location.lat(), 4); // Raw latitude

      u8g.setPrintPos(68, 40);
      u8g.print("LG:");
      u8g.setPrintPos(86, 40);
      u8g.print(gps.location.lng(), 4); // Raw longitude
      u8g.setPrintPos(5, 50);
      u8g.print("Start:");
    }
  }
  else
  {
    u8g.setFont(u8g_font_fixed_v0);
    u8g.setPrintPos(35, 30);
    u8g.print("POS. Aktuel:");
    u8g.setPrintPos(1, 40);
    u8g.print("BG:");
    u8g.setPrintPos(20, 40);
    u8g.print("00.0000"); // Raw latitude

    u8g.setPrintPos(68, 40);
    u8g.print("LG:");
    u8g.setPrintPos(86, 40);
    u8g.print("00.0000"); // Raw longitude

    u8g.setPrintPos(5, 50);
    u8g.print("Start:");
  }
  if (gps.date.isValid() & gps.date.isValid())
  {
    u8g.setFont(u8g_font_fixed_v0);
    u8g.setPrintPos(5, 10);
    u8g.print(gps.date.day());
    u8g.setPrintPos(10, 10);
    u8g.print(".");
    u8g.setPrintPos(15, 10);
    u8g.print(gps.date.month());
    u8g.setPrintPos(20, 10);
    u8g.print(".");
    u8g.setPrintPos(25, 10);
    u8g.print(gps.date.year());

    u8g.setPrintPos(55, 10);
    u8g.print(gps.time.hour() + 2);
    u8g.setPrintPos(70, 10);
    u8g.print(":");
    u8g.setPrintPos(75, 10);
    u8g.print(gps.time.minute());
  }
  else
  {
    u8g.setFont(u8g_font_fixed_v0);
    u8g.setPrintPos(10, 10);
    u8g.print("No valid Timestamp  ");
  }

  if (gps.speed.isValid())
  {
    u8g.setFont(u8g_font_fixed_v0);
    u8g.setPrintPos(5, 20);
    u8g.print(gps.speed.kmph());


  } else
  {
    u8g.setFont(u8g_font_fixed_v0);
    u8g.setPrintPos(1, 20);
    u8g.print("GS:");
    u8g.setPrintPos(20, 20);
    u8g.print("00");

  }

  if (TargetGpsLAT < 90 & TargetGpsLON < 180  )
  {

    u8g.setFont(u8g_font_fixed_v0);

    u8g.setPrintPos(1, 60);
    u8g.print("BG:");
    u8g.setPrintPos(20, 60);
    u8g.print(TargetGpsLAT, 4); // Raw latitude

    u8g.setPrintPos(68, 60);
    u8g.print("LG:");
    u8g.setPrintPos(86, 60);
    u8g.print(TargetGpsLON, 4); // Raw longitude

  } else
  {
    u8g.setFont(u8g_font_fixed_v0);

    u8g.setPrintPos(1, 60);
    u8g.print("00000");
  }

  if (gps.location.isValid() & TargetGpsLAT < 90 & TargetGpsLON < 180 )
  {
    DistanceInKM = false;
    Distance = gps.distanceBetween(gps.location.lat(), gps.location.lng(), TargetGpsLAT, TargetGpsLON);
    courseToT = gps.courseTo(gps.location.lat(), gps.location.lng(), TargetGpsLAT, TargetGpsLON);
    if (Distance > 1000)
    {
      Distance = Distance / 1000;
      DistanceInKM = true;
    }
    u8g.setFont(u8g_font_fixed_v0);
    u8g.setPrintPos(50, 50);
    u8g.print("dst:");
    u8g.setPrintPos(75, 50);
    u8g.print(Distance);

    if (DistanceInKM)  {
      u8g.print("km ");
    } else {
      u8g.print("m ");
    }

  } else
  {
    ////////////////////////////////////////////////////////////////////////////
    //digitalWrite( Ledblau, LOW);
    ////////////////////////////////////////////////////////////////////////////

    u8g.setFont(u8g_font_fixed_v0);

    u8g.setPrintPos(50, 50);
    u8g.print("00000");
  }
  smartdelay(50);
}

void draw2()
{
  u8g.setFont(u8g_font_fixed_v0);
  u8g.setPrintPos(5, 10);
  u8g.print( sensors.getTempCByIndex(0));


  u8g.setFont(u8g_font_fixed_v0);
  u8g.setPrintPos(110, 20);
  u8g.print(pwm);

  if (entfernung >= 500 || entfernung <= 0)
  {
    u8g.setFont(u8g_font_fixed_v0);
    u8g.setPrintPos(5, 20);
    u8g.print("Kein Messwert");

  }
  else
  {
    u8g.setFont(u8g_font_fixed_v0);
    u8g.setPrintPos(5, 20);
    u8g.print(entfernung);
  }


  if (entfernung <= pwm )
  {
    u8g.setFont(u8g_font_fixed_v0);
    u8g.setPrintPos(60, 20);
    u8g.print("CAR");
    u8g.setPrintPos(5, 30);
    u8g.print("Radio: OK");
    const char text[] = "Your Button State is HIGH";
    radio.write(&text, sizeof(text));

  }
  else
  {
    u8g.setFont(u8g_font_fixed_v0);
    u8g.setPrintPos(60, 20);
    u8g.print("--");
    const char text[] = "Your Button State is LOW";
    radio.write(&text, sizeof(text));                  //Sending the message to receiver
  }
  radio.write(&car, sizeof(car));  //Sending the message to receiver



  smartdelay(10);

}
void draw3()
{
  u8g.setFont(u8g_font_helvB14);
  u8g.setPrintPos(15, 38);
  u8g.print("xx");
}


void setup(void) {
  radio.begin();                  //Starting the Wireless communication
  radio.openWritingPipe(address); //Setting the address where we will send the data
  radio.setPALevel(RF24_PA_MIN);  //You can set it as minimum or maximum depending on the distance between the transmitter and receiver.
  radio.stopListening();
  sensors.begin();

  pinMode(trigger, OUTPUT);
  pinMode(echo, INPUT);


  if ( u8g.getMode() == U8G_MODE_R3G3B2 )
    u8g.setColorIndex(255);     // white
  else if ( u8g.getMode() == U8G_MODE_GRAY2BIT )
    u8g.setColorIndex(3);         // max intensity
  else if ( u8g.getMode() == U8G_MODE_BW )
    u8g.setColorIndex(1);         // pixel on

  pinMode(SwitchPIN, INPUT_PULLUP); // Setzt den Digitalpin 13 als Outputpin

  ////////////////////////////////////////////////////////////////////////////
  //pinMode (Ledblau, OUTPUT);
  //pinMode (Ledrot, OUTPUT);
  //pinMode (Ledgruen, OUTPUT);
  //pinMode (Ledorange, OUTPUT);
  //pinMode (buttonpin, INPUT);
  ////////////////////////////////////////////////////////////////////////////
  ss.begin(9600);
  smartdelay(1);

}

void loop(void) {

  sensors.requestTemperatures();
  float tempC = sensors.getTempCByIndex(0);

  sensor = analogRead(potiPin);
  pwm = map(sensor, 0, 1023, 0, 400);

  digitalWrite(trigger, LOW);
  delay(5);
  digitalWrite(trigger, HIGH);
  delay(10);
  digitalWrite(trigger, LOW);
  dauer = pulseIn(echo, HIGH);
  entfernung = (dauer / 2) * 0.03432;









  boolean valor_botao = digitalRead(A2);
  if (valor_botao != 1)
  {
    while (digitalRead(A2) != 1)
    {
      delay(10);
    }
    // Inverte o estado
    estado_botao = !estado_botao;
  }

  //picture loop
  u8g.firstPage();
  do {
    if (estado_botao == 0)
    {
      draw1();
    }
    if (estado_botao == 1)
    {
      draw2();
    }
    if (estado_botao == 2)
    {
      draw3();
    }
  }
  while ( u8g.nextPage() );
  delay(10);



  ////////////////////////////////////////////////////////////////////////////
  // val=digitalRead(buttonpin);   //connect mic sensor to Analog 0
  // if (val == HIGH)
  // {
  //   digitalWrite( Ledorange, HIGH);
  //   }
  //   else
  //   {
  //    digitalWrite( Ledorange, LOW);

  ////////////////////////////////////////////////////////////////////////////


}

static void smartdelay(unsigned long ms)
{
  unsigned long start = millis();
  do
  {
    if (!(digitalRead(SwitchPIN)))   // read the input pin
    {
      delay(100);   //debouncing
      if (!Button1Pressed)
      {
        Button1Pressed = true;
        TargetGpsLAT = gps.location.lat();
        TargetGpsLON = gps.location.lng();
        u8g.setFont(u8g_font_fixed_v0);
        u8g.setPrintPos(5, 60);
        u8g.print("W:");
        u8g.setPrintPos(10, 60);
        u8g.print(TargetGpsLAT, 4); // Raw longitude in whole degrees
        u8g.setPrintPos(80, 60);
        u8g.print(" L:");
        u8g.setPrintPos(90, 60);
        u8g.print(TargetGpsLON, 4); // Raw longitude in whole degrees
      }
    }  else
    {
      Button1Pressed = false;
    }

    while (ss.available())
      gps.encode(ss.read());
  } while (millis() - start < ms);
}

der button zum weiter schalten der seiten ist hier der botao.

grüße

Georg

die estado_botao Variable wechselt zwischen 0 und 1. Sie werden nie 2 bekommen, also rufen Sie nie die draw3()-Funktion auf

do {
    if (estado_botao == 0)
    {
      draw1();
    }
    if (estado_botao == 1)
    {
      draw2();
    }
    if (estado_botao == 2)
    {
      draw3();
    }
  }
  while ( u8g.nextPage() );

ok.
und wie muss ich es machen damit es nicht mehr so ist?

estado_botao++;
estado_botao %= 3;

Gruß Tommy

1 Like

Juhu es geht :slight_smile:

Vielen vielen dank!!!!!!!!

1 Like

oder estado_botao = (estado_botao + 1) % 3; wenn Sie den Code lesbarer machen möchten

1 Like

Vergib Herzchen (haste schon) und mach den Haken in dem Beitrag, wo gelöst. Hilft der Nachwelt. :wink:

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