If we want to write to the second line, we can use lcd.setCursor(COLUMN, LINE)
such that the column is 0 and the line is 1:
lcd.setCursor(0,1);
void loop() { // set the cursor to column 0, line 1 // (note: line 1 is the second row, since counting begins with 0): lcd.setCursor(0, 1); // print the number of seconds since reset: lcd.print(millis() / 1000); }
Let's try writing the output of the light sensor to the character LCD.
This will require an extra part:
Note: While the rail is connected to 5V, the light sensor is connected to 3V.
Copy and paste the code below into the Arduino editor. Then, compile and upload it to your board.
/* CIRC14 - Make It Better * Character LCD + TMP36 * * by Brent Rubell for Adafruit Industries. Support Open Source, buy Adafruit! */ // include the library code: #include <LiquidCrystal.h> // modified wiring for Metro Explorers Guide LiquidCrystal lcd(7, 8, 9, 10, 11, 12); // photo light sensor int lightPin = A0; void setup() { // set up the LCD's number of columns and rows: lcd.begin(16, 2); // print to the first line of the LCD lcd.print("Light Value:"); } void loop() { // read the light level int lightLevel = analogRead(lightPin); // map and constrain the light sensor values lightLevel = map(lightLevel, 0, 900, 0, 255); lightLevel = constrain(lightLevel, 0, 255); // set the cursor to column 0, line 1 lcd.setCursor(0, 1); // write lightLevel to the LCD lcd.print(lightLevel); }
The Thermometer (CIRC15) gets into the nitty-gritty of the character LCD. You'll learn how to display custom characters, full strings of text, and multi-line data output!
Text editor powered by tinymce.