Go Down

Topic: LCD display coding lack of knowledge for autopilot controlls (Read 33 times) previous topic - next topic


Hello everyone, this is my first post but I have been reading a lot of posts in the last 2 weeks since receiving my first Arduino Mega.

I've tried to learn coding (from scratch), I have limited knowledge still but am working on it. I've been reading Arduino for dummies and working through the assignments.

Below is a sketch that has causing me brain ache for a number of days, hopefully you will be kind enough to help?

I'm trying to construct a program, using the LCD 5 button shield and a pot, to eventually integrate with my flight sim.

Right now I have managed to hook up a pot and program 2 buttons, one says 'Heading' and t'other 'Altitude'. I've managed to work out a division to read the pot as 360 degrees, so that's great and I had fun researching and implementing this. Eventually the other buttons will be assigned to other commands (hopefully!).

Problems are:
- When I change value for the altitude, it automatically changed the Heading value. I assume this is because the pot is shared and hence always being read?
- I then had the idea to use the Select button, to 'store' the pot value for heading whilst I moved the pot with altitude button. After much research I couldn't find anything. I don't know how to do this.
- I like when I experimented using the 'while' command, as it let me see the pot value change on screen; with the 'if' command I have to keep the button pressed to see the pot value change on the screen. Is there a workaround for this with the if command (if 'if' is the way forward)?

So, ladies and gents, do you know of a way of storing the pot value to one button only. Like an 'Enter' command.
Should I use something other than a pot?
I'm trying to clone the Saitek Pro Flight Multi Panel, which has only 1 pot (or encoder?) to control altitude, heading, Nav, climb/decent rate.

My code is below. Again, I'm very new to this, along with incorrectly, I've probably coded it a very long a convoluted way. For now, this is the limit of my knowledge. I look forward to learning from you! If you have the time, please explain your answers so that I can learn and not just copy/paste.

Thank you for your time in advance.

Code: [Select]

#include <LiquidCrystal.h> // include the LCD library
LiquidCrystal lcd(8,9,4,5,6,7);

int potPin = A13; //Potentiometer input pin
int potValue1 = 0;
int potValue2 = 0;
int potValue3 = 0; // I added potValue3 and 4 thinking that it would separate the pot
// value from potValue 1 and 2 in my coding. I was wrong.
int potValue4 = 0;

void setup() {
lcd.begin(16, 2); // lcd rows and columns

void loop() {

int x; // put this int in setup in case I could use 'int y' for different buttons. Int y didn't help.

x = analogRead (0);
if (x <100) { // allocation for 'right' button on shield
lcd.setCursor(0,0); // top line of display
lcd.print("Select Heading"); // says on the tin
lcd.setCursor(0,1); // 2nd line lcd
potValue1 = analogRead(potPin) / 2.838; // divide pot by 2.838 to get 360 'degrees' for heading
potValue2 = potValue1; //work out pV2
lcd.print(potValue2); // shows heading on 2nd line of LCD
lcd.print("   ");

else if (x <200) {
x = analogRead (0); // allocation for 'up' button on shield
lcd.setCursor(0,0); // top line of display
lcd.print ("Altitude       "); // ronseal
lcd.setCursor(0,1); // 2nd line lcd
potValue3 = analogRead(potPin)*3; // Does this now affect the heading reading? (No, hurray!)
                          // *3 to give me some height in flight sim as 1024 feet isn't heigh enough
// ideally I would like this to increment in hundreds, ie, 1000, 1100, 1200 feet - any idea??
// for some reason the LCD climbs to 9062, then starts at 1000 again! Why?
potValue4 = potValue3; // set cursor to second row, first column
delay (100);
lcd.print(potValue4); // shows heading

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131