Professional Documents
Culture Documents
h>
#include <Encoder.h>
//LiquidCrystal lcd(LCD_RS, LCD_EN, LCD_D4, LCD_D5, LCD_D6, LCD_D7);
LiquidCrystal lcd(11, 10, 5, 4, 3, 2); // select the pins used on the LCD panel
int lcd_key = 0;
int adc_key_in = 0;
const int pinA = 7;
const int pinB = 8;
long lastPosition = 0;
Encoder encoder(pinA, pinB);
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
#define POTENTIOMETER_PIN A1
int mode = 1;
int read_LCD_buttons(){
adc_key_in = analogRead(0); // read the value from the sensor
return btnNONE;
}
void setup(){
lcd.begin(16, 2);
lcd.clear();
}
void loop(){
}
if(mode==3)
{
delay(200);
offset=offset+0.1 ;
delay(100);
if(offset >= 2.5)
offset=2.5;
}
break;
}
case btnDOWN:{
lcd.clear();
if(mode==2)
{
delay(200);
gain=gain-1.0 ;
delay(100);
if (gain <=0.01)
gain=0.01;
}
if(mode==3)
{
delay(200);
offset=offset-0.1 ;
delay(100);
if(offset <= -2.5)
offset=-2.5;
}
break;
}
case btnSELECT:{
lcd.clear();
if (mode==4)
mode=1;
else
mode=mode+1;
delay(500);
break;
}
case btnNONE:{
if(mode==1)
{
lcd.setCursor(0,0);
lcd.print("Mode:");
lcd.print(mode);
lcd.setCursor(0,0);
lcd.print("Mode:");
lcd.print(mode);
lcd.setCursor(0,1);
lcd.print("gain=");
lcd.print(gain);
}
if (mode==3)
{
lcd.setCursor(0,0);
lcd.print("Mode:");
lcd.print(mode);
lcd.setCursor(0,1);
lcd.print("offset=");
lcd.print(offset);
}
if(mode==4)
{
lcd.setCursor(0,0);
lcd.print("Mode:");
lcd.print(mode);
lcd.setCursor(7,0);
lcd.print("max=");
lcd.print(maxValue);
lcd.setCursor(7,1);
lcd.print("min=");
lcd.print(minValue);
}
if (mode==2)
{
long newPosition = encoder.read();
if (newPosition != lastPosition) {
lastPosition = newPosition;
}
}
if(mode==3)
{
long newPosition = encoder.read();
if (newPosition != lastPosition) {
lastPosition = newPosition;
}
}
break;
}
}