I can’t get the code in outPut to show on my lcd screen, what am I doing wrong or missing? Also I am not 100% sure that lcd is a object. This is for a Leonardo Arduino with Arduino ide but I have never been able to figure this out with Java and C++ also. Any help or guidance is greatly appreciated.
#include <LiquidCrystal.h>
#include <Keyboard.h> // The main library for sending keystrokes.
//LCD pin to Arduino
const int pin_RS = 8;
const int pin_EN = 9;
const int pin_d4 = 4;
const int pin_d5 = 5;
const int pin_d6 = 6;
const int pin_d7 = 7;
const int pin_BL = 10;
int y = 0;
int z = 0;
LiquidCrystal lcd( pin_RS, pin_EN, pin_d4, pin_d5, pin_d6, pin_d7);
void setup() {
Keyboard.begin(); // Initialise the library.
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("Electropeak.com");
lcd.setCursor(0,1);
lcd.print("Press Key:");
}
void loop() {
Keyboard.press('f12'); // Press and hold the 'f12' key.
delay(100); // Wait for the computer to register the press.
Keyboard.releaseAll(); // Release both of the above keys.
delay(1000);
int x;
x = analogRead (0);
lcd.setCursor(10,1);
output();
}
void outPut(){
lcd.print("Does not show");
}
1
In this case, since lcd
is a global variable, it’s available in all functions that can see its declaration (which is all of the functions shown). No need to send it to a function explicitly.
If you actually do want to pass an object to a function you can either pass by copy or pass by reference (you want this one for lcd
). You’d write the function differently, like this:
// passing a LiquidCrystal object by reference
void my_function(LiquidCrystal& lcd) {
// now lcd is available to use below
lcd.print("It works!");
}