Help with Variable for LCD 5110 / PCD8544

Hallo

Sorry my bad english!!

I can’t get my LCD to show a Light variable =(

My code:

 #include "pitches.h"
 #include <LCD5110.h>
 
const int maxi = 20;
const int mini = 1;

// The update interval
const int refresh = 500;

int ldrPin = 0;
int light = 0;

const int startFreq = 10000;
const int stopFreq = 15000;

// notes in the melody:
int melody[] = {
  NOTE_G3, NOTE_G3, NOTE_G3, NOTE_DS3,0, NOTE_F3, NOTE_F3, NOTE_F3, NOTE_D3};

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
  4, 4, 4, 2, 4, 4, 4, 4, 2 };


void setup(void)
{
  LcdInitialise();
  LcdClear();
 
  gotoXY(12,0);
  LcdString("NJA Light");
}


void loop(void)
{
light = analogRead(ldrPin);
light = light/10;

// Serial.print("Light reading = ");
// Serial.println(light);
delay(refresh);



// ************ START ******************

  LcdInitialise();
  gotoXY(1,2);
  LcdString("Light:");
  gotoXY(45,2);
  LcdString(light);  // !! This Line1 will not work!!
 
 delay(1000);

if (light <mini){  
// Serial.println("Dark");
delay(5000);
  // iterate over the notes of the melody:
  for (int thisNote = 0; thisNote < 9; thisNote++) {

    // to calculate the note duration, take one second 
    // divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = 1000/noteDurations[thisNote];
    tone(8, melody[thisNote],noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    // stop the tone playing:
    noTone(8);
  }  
} else if (light >maxi){ 
  // Serial.println("High Sun!");
    int i;
  
  for (i = startFreq; i <= stopFreq; i++) {
    tone(8, i);
    delayMicroseconds(10);}
    
   for (i = stopFreq; i >= startFreq; i--) {
      tone(8, i);
      delayMicroseconds(1000);}
    noTone(8);
}

// ************ END

  }

And i can’t see what i do wrong, plz help me someone, somebody. :wink: (Then your will make a danish boy happy)

Thanks for helping :slight_smile:

I read this post and now it’s work as I will. :smiley:

My New Code:

#include <LCD5110.h>

int lcdled = 9;

const int minvalue=1; // 0-255 and 0=Dark 255=Low Light
const int maxvalue=20; // 0-255 and 0=Dark 255=High Light
int light = 0;
const int startFreq = 10000;
const int stopFreq = 15000;
const int refresh = 1000;

void setup() {
  pinMode(lcdled, OUTPUT);
  Serial.begin(9600);                //Start the Serial connection
  LcdInitialise();
  LcdClear();
 
  gotoXY(12,0);
  LcdString("NJA Light");
}

void loop() {
  noTone(8);
  int sensorValue1 = analogRead(0); 
  sensorValue1 = sensorValue1/4;
  
  int sensorValue2 = analogRead(0); 
  sensorValue2 = sensorValue2/4;
  
  if(sensorValue1>maxvalue)
  {
    Serial.println("High");
      // analogWrite(lcdled, sensorValue);    
    int i;
  
  for (i = startFreq; i <= stopFreq; i++) {
    tone(8, i);
    delayMicroseconds(10);}
    
   for (i = stopFreq; i >= startFreq; i--) {
      tone(8, i);
      delayMicroseconds(100);}
    noTone(8);
  }
  else if (sensorValue1<minvalue)
  {
    Serial.println("Low");
      // analogWrite(lcdled, sensorValue);    
  noTone(8);
  }
      analogWrite(lcdled, sensorValue2);
  LcdInitialise();
  LcdClear();
  gotoXY(12,0);
  LcdString("NJA Light");
  gotoXY(1,2);
  LcdString("LDR:");
  
  char buf [0];
sprintf (buf, "%i", sensorValue1);
gotoXY(45,2);
LcdString(buf);

gotoXY(68,2);
LcdString("%");

  gotoXY(1,4);
  LcdString("LCD:");
  
   char buf2 [0];
sprintf (buf2, "%i", sensorValue2);
gotoXY(45,4);
LcdString(buf2); 

gotoXY(68,4);
LcdString("%");

  Serial.println("NJA Light: ");
  Serial.println(sensorValue1);
  Serial.println(sensorValue2);
  delay(refresh);

}