I wasn't sure if I should post this here or in LCD, but it seemed more appropriate here to me.
I'm trying to a handle on Arduino programming, since I have a number of ideas to use these for. I've started with a rather elaborate display that will connect to the ECM in my car, but decided that it was well beyond my programming skill level, so I decided to do something that should be much simpler, and it is... sort of.
What I decided to do was make a simple LCD display that will show a few different functions of my car, and plan to add to it in the future.
What I have started is something that will display the left and right turn signal display, along with a "CHECK ENGINE" message that can be displayed on the LCD (16x2). The three inputs are triggered right now from a button on a breadboard, using the button example circuit.
So far, for only working this for a few hours (Still very new to programming), I have a 95% successful item.
My biggest issue is getting the items to display on the screen without appearing to be flashing, or almost scrolling reset, might be more accurate description. I am using "<---" for left turn, "--->" for right turn and "CHECK ENGINE" for, well... check engine. lol What happens is that each item when displayed will flash almost as if each pixel is being reset from left to right. I can stop this by not using the "lcd.clear" command, but then once each item is triggered, they just stay on the LCD, I need them to blank when the input is not present. I would also eventually like to display other messages in the same areas, so writing to the same locations of the LCD with something like " " won't work in the long run. Eventually I'd like to use some large digits as well, that uses more than one line of the display for an item displayed. I also have an LED illuminating when the "CHECK ENGINE" light pin is triggered.
I've looked at the "switch case" examples, and some threads on here, but I'm not sure if that's what I need to use, and I haven't grasped it's use or implementation yet.
I know I'm missing something, I just can't figure out what, so I am asking for a bit of guidance on this.
I have tried only using a single "lcd.clear" statement at the end of the loop, which worked, but still had the same flickering message display.
I have also tried using "lcd.noDisplay" and had nothing displayed on the LCD at all. If I trigger all 3 inputs at the same time, the flashing doesn't occur, I would suspect this would be due to the "true" IF statements bypassing the "else" statements.
Please be gentle, I have tried searching and just trying some things both from examples and just some random ideas I though may or may not work. I'm just starting in this programming and I actually feel pretty good about my progress so far, mostly started from scratch, though much of the code was copied and modified from example sketches, I have made something work almost the way I want it to. I know there are probably some shortcuts to cleaning up the sketch, and making it more efficient, but taking the long route works for me for now, once I understand it, then I will worry about shortcuts and using more advanced programming.
Here is the code:
/*
This is a display that will take dedicate inputs and display their function
on an LCD.
The list of functions so far:
- Right Turn Signal
- Left Turn Signal
- Check Engine Light (message?)
The circuit:
* LED attached from pin 4 to ground (CHECK ENGINE indicator)
* pushbutton attached through buttons from +5V
* 10K resistor attached to pin 2 from ground
* Right turn input to pin 2
* Left Turn Signal to pin 3
* Check Engine light to pin 5
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Button
*/
// constants won't change. They're used here to
// set pin numbers:
const int rightturnPin = 2; // the number of the pushbutton pin
const int lefttturnPin = 3; // the number of the pushbutton pin
const int celPin = 5; // the number of the pushbutton pin
const int ledPin = 4; // the number of the LED pin
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 7, 8, 9, 10);
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
lcd.begin(16, 2);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(rightturnPin, INPUT);
pinMode(lefttturnPin, INPUT);
pinMode(celPin, INPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(rightturnPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
lcd.setCursor(12, 1);
// write to LCD:
lcd.print("--->");
}
else {
//clear LCD
lcd.clear();
}
// read the state of the pushbutton value:
buttonState = digitalRead(lefttturnPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
lcd.setCursor(0, 1);
// write to LCD:
lcd.print("<---");
}
else {
// clear LCD
lcd.clear();
}
{
// read the state of the pushbutton value:
buttonState = digitalRead(celPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
lcd.setCursor(2, 0);
// write to LCD:
lcd.print("CHECK ENGINE");
}
else {
//clear LCD
lcd.clear();
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
}