I am working on a project for work that has reached a road block. My programming knowledge is limited therefore I have been researching example code resources to achieve a workable solution. I have found many resources on this forum and elsewhere that give menu examples for LCDs but I do not understand for the life of me how to implement it into my project. Basically this is a "hand holding" request, ie walk me through this so that I can learn.
I can work the LCD with the general commands and I understand arrays, switch case and general coding to an extent. I can figure out the button side of the issue.
I am looking to make a menu on my 16x2 8bit/4bit LCD that with my 3 analog menu buttons the use can change some settings.
Item1 Printed and held at (0,0), moving to item 2 tree at button press
It1Child1 Printed at (1,0) and cycling through child with button press
It1Child2
It1Child3
It1Child4
It1Child5
Look im sure its a simple request, but im really at a loss and need to finish this project soon. Can you help?
Dont just give me hyper links, I have been searching for 2 days and have found everything there is, again its the implementation of it that causes me trouble. Do you want me to pick one or would you have a better idea? Let me know. Thanks in advance.
Code Part 1
/*
Source for DiscountingApparatus with Atmega328
-----------------------------------------------
Outputs are 8 Servos, 16x2 LCD, 4 tricolor led's
Inputs are 2 Animal buttons, and 3 menu buttons
*/
// Define Libraries
#include <LiquidCrystal.h>
// Begin defining constants...
const int buttonPin = 0; // The number of the Analog pushbutton pin
const int lcd_backlight_pin = 8; // Its the LED LCD backlight
const int warninglight_pin = 19; // The number of the warning LED
const int blue_green_pin = 18; // The blue/green LED pin
const int green_blue_pin = 17; // The green/blue LED pin
// Initialize the LCD library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// Define the analog buttons
const int button1 = 1; //Animal button1
const int button2 = 2; //Animal button2
const int button3 = 3; //Menu button1
const int button4 = 4; //Menu button2
const int button5 = 5; //Menu button3
// button states for the analog button input values
// CHECK THAT THESE VALS ARE IN CORRECT ORDER AND ARE CORRECT VALUES
const int button1LOW = 40;
const int button1HIGH = 47;
const int button2LOW = 125;
const int button2HIGH = 132;
const int button3LOW = 87;
const int button3HIGH = 105;
const int button4LOW = 924;
const int button4HIGH = 934;
const int button5LOW = 225;
const int button5HIGH = 244;
// Begin defining variables
boolean user_select = false;
char group_1_patt; // Is group 1 fast or slow
char group_2_patt; // Is group 2 fast or slow
boolean Seq_running = false; // Check val for running processes
char group_1_seq;
char group_2_seq;
int delay_short = 0; // Short delay
int delay_long = 1000; // Long delay
int buttonState; // the current reading from the input pin
int lastbuttonState = LOW; // the previous reading from the input pin
// Debounce timers and delays are big b/c the can grow beyond the int limit
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 1;
// Begin listing of functions!
void put(int servo, int angle)
{
//servo is the servo number 0-7, angle is the absolute position from 500 to 5500
unsigned char buff[6];
unsigned int temp;
unsigned char pos_hi,pos_low;
temp=angle&0x1f80; pos_hi=temp>>7; pos_low=angle & 0x7f; //Convert the angle data into two 7-bit bytes
//Construct a Pololu Protocol command sentence
buff[0]=0x80; //start byte
buff[1]=0x01; //device id
buff[2]=0x04; //command number
buff[3]=servo; //servo number
buff[4]=pos_hi; //data1
buff[5]=pos_low; //data2
//Send the command to the servo controller
for(int i=0;i<6;i++){
Serial.print(buff[i],BYTE);
}
}
void put(unsigned char servo, unsigned int angle){
//servo is the servo number 0-7, angle is the absolute position from 500 to 5500
//Send a Pololu Protocol command
Serial.print(0x80,BYTE); //start byte
Serial.print(0x01,BYTE); //device id
Serial.print(0x04,BYTE); //command number
Serial.print(servo,BYTE); //servo number
//Convert the angle data into two 7-bit bytes
Serial.print(((angle>>7)&0x3f),BYTE); //data1
Serial.print((angle&0x7f),BYTE); //data2
}
void servoOff(unsigned char servo){
//servo will go limp until next position command
//servo is the servo number (typically 0-7)
//Send a Pololu Protocol command
Serial.print(0x80,BYTE);//start byte
Serial.print(0x01,BYTE);//device id
Serial.print(0x00,BYTE);//command number
Serial.print(servo,BYTE);//servo number
Serial.print(0x0f,BYTE);//data1 (turn servo off, keep full range)
}
void servoSetSpeed(unsigned char servo, unsigned char speedcmd){
//servo is the servo number 0-7
//speed is servo speed (1=slowest, 127=fastest)
//set speed to zero to turn off speed limiting
speedcmd=speedcmd&0x7f;//take only lower 7 bits of the speed
//Send a Pololu Protocol command
Serial.print(0x80,BYTE);//start byte
Serial.print(0x01,BYTE);//device id
Serial.print(0x01,BYTE);//command number
Serial.print(servo,BYTE);//servo number
Serial.print(speedcmd,BYTE);//data1
}
// Startup reset all servos to horizontal pos
void servo_reset_all(){
put(0,4600);
put(1,4600);
put(2,4600);
put(3,4600);
put(4,4600);
put(5,4600);
put(6,4600);
put(7,4600);
}
// Now define the Group1 sequences
void group_1_longdelay(unsigned int action){
if (action == 1){
put(0,2600); // Make paddle vertical
delay(delay_long);
put(1,2600); // Make paddle vertical
delay(delay_long);
put(2,2600); // Make paddle vertical
delay(delay_long);
put(3,2600); // Make paddle vertical
}else if (action == 0){
put(0,4600); // Make paddle horizontal
put(1,4600); // Make paddle horizontal
put(2,4600); // Make paddle horizontal
put(3,4600); // Make paddle horizontal
}
}
void group_1_shortdelay(unsigned int action){
if (action == 1){
delay(delay_short);
put(0,2600); // Make paddle vertical
}else if (action == 0){
put(0,4600); // Make paddle horizontal
put(1,2600); // Make paddle vertical
put(2,2600); // Make paddle vertical
put(3,2600); // Make paddle vertical
}
}
// Now define the Group2 sequences
void group_2_longdelay(unsigned int action){
if (action == 1){
put(4,2600); // Make paddle vertical
delay(delay_long);
put(5,2600); // Make paddle vertical
delay(delay_long);
put(6,2600); // Make paddle vertical
delay(delay_long);
put(7,2600); // Make paddle vertical
}else if (action == 0){
put(4,4600); // Make paddle horizontal
put(5,4600); // Make paddle horizontal
put(6,4600); // Make paddle horizontal
put(7,4600); // Make paddle horizontal
}
}
void group_2_shortdelay(unsigned int action){
if (action == 1){
delay(delay_short);
put(4,2600); // Make paddle vertical
}else if (action == 0){
put(4,4600); // Make paddle horizontal
put(5,2600); // Make paddle vertical
put(6,2600); // Make paddle vertical
put(7,2600); // Make paddle vertical
}
}
void setup() {
// Set pins as I/O
pinMode(lcd_backlight_pin, OUTPUT);
pinMode(buttonPin, INPUT);
pinMode(warninglight_pin, OUTPUT);
pinMode(green_blue_pin, OUTPUT);
pinMode(blue_green_pin, OUTPUT);
// Set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Turn on the backlight
digitalWrite(lcd_backlight_pin, HIGH);
// Set the serial library at 9600 baud
Serial.begin(9600);
// Reset the paddles
servo_reset_all();
}