My LCD works fine and so does my program..but it is not that bright and I can barely see it. Can you please help me change the brightness from the code. (Using a potientmter would not be my first choice to control the brightness..I would rather it stay at one brightness level.)
Here is my code:
#include <Servo.h>
const int trigPin = 9;
const int echoPin = 10;
static unsigned long timer = 0;
unsigned long interval = 1000;
static int seconds = 0;
#define LCD_Backlight 9
int x = 0;
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
float duration, distance;
//this is the threshold where the sensor will trigger the
//countdown. If you are getting extra countdowns or the
//countdown won't start, you may need to adjust this for your sink
int threshold = 20;
Servo countServo;
void setup() {
Serial.begin(9600);
lcd.begin();
// Turn on the blacklight and print a message.
lcd.backlight();
//attach pin 7 to servo and sweep it to indicate that the timer is on
countServo.attach(7);
countServo.write(180);
delay(700);
countServo.write(0);
delay(700);
countServo.write(180);
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * .0343/ 2;
Serial.println(distance);
if (distance < threshold) {
countdownServo();
Serial.println("Working");
}
delay(100);
}
//this moves the servo 4.5 degrees every half second
//to smooth out the movemnt (vs 9 degrees every second)
//for 20 seconds.
void countdownServo() {
Serial.println("Counting down");
//start of loop Robojax code for LCD with I2C
lcd.setCursor (0,1); // go to start of 2nd line
lcd.print("Hello World!");
//lcd.print(millis() / 1000);
delay(500);
//end of loopcode Robojax code for LCD with I2C
int halfseconds = 19;
for (int i = halfseconds; i >= 0; i--) {
countServo.write((int)(i * 4.5));
delay(500);
//start of loop Robojax code for LCD with I2C
lcd.clear();
if(millis() - timer >= interval)
{
timer = millis();
seconds++;
Serial.print("seconds elapsed = ");
Serial.println(seconds);
}
lcd.print(seconds);
lcd.setCursor (0,1); // go to start of 2nd line
lcd.print("");
//lcd.print(millis() / 1000);
delay(500);
//end of loopcode Robojax code for LCD with I2C
}
//reset the servo, clear the queue
countServo.write(180);
seconds = 0;
lcd.print("You finished!");
delay(700);
}
Backlight always has a strap that must be in place. There is no code in the world that can affect the backlight if it is missing, which looks very likeöly to me.
Start looking in the data sheets for the display and check the display library,LiquidCrystal_I2C.h, for useful functions.
I don't see any code telling what pins should be used for the LCD. In Your code pin 9 is assigned to the back light. Check that! But nowhere it's told about the data pins, enable pin etc.
I'm pretty sure that pin 15 on the display needs +5 volt. Look at the pictures of the back side of the display. You can se some pads and the signs "K" (cathode== GND) and "A" (Anode == +5 volt). I'm sure that's the backlight connected there. Check Your wiring!
@Wawa
No backlight? I think I see clear signs of a backlight. An LCD without backlight… Never heard of or seen such a one. A reflective type? It says "Backlight" in the link.
@Wava
Look at the leftmost picture out of those 4. Look at the right side of the LCD. There You see a white tag emerging from under the display. I interpret that as the backlight. My LCD looks like that. I'm sure You know that backlight has nothing to do with I2C or ni I2C.
The vias I also noted. Often there is a strap invold in the neighbourhead.
Railroader:
Never heard of or seen such a one. A reflective type? It says "Backlight" in the link.
I use the 'transflective' LCDs, very good.
They are highly visible in the strongest of direct sunlight and with the backlight on highly visible in dark or dim conditions. As they mostly dont need the backlight on to see them, they are low power too.
Not sure why you would want to use the other types really, unless you are peversly keen on blue displays.
@srnet
What would "transreflective" be? Both reflective and using trans-light, light from behind?
Reflective LCD calls for light from outside. In darkness You would see nothing. Out the 20 LCD I've bought from Ebay they all have the backlight, but not always the needed strap to make it shine…..