For some reason the serial moniter and the lcd screen prints the same value for numbers increasing by 5 from 0 to 255, but then when it gets down to 100 the lcd starts printing random values while the serial moniter continues printing the correct numbers, why would this be?
Code Used:
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
// The pin connected to the LED
int brightness = 0; // Initial brightness value
int fadeAmount = 5; // How much to increment the brightness each time (adjustable)
int i =0;
void setup() {
Serial.begin(9600);
pinMode(3, OUTPUT); // Set the LED pin as an output
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Light Level: ");
}
void loop() {
lcd.setCursor(8, 2);
/------------------------------------------------/
analogWrite(3, brightness); // Set the LED brightness
// Increment the brightness
brightness += fadeAmount;
delay(900);
i = i +fadeAmount;
// Reverse the direction of fading when brightness reaches its limits
if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount;
}
lcd.print(brightness);
Serial.print(brightness);
Serial.print(" ");
Serial.println();
}