Skip to content

Instantly share code, notes, and snippets.

@fxprime
Created October 16, 2020 03:05
Show Gist options
  • Select an option

  • Save fxprime/11f6cb5c12e4de6797ee222083382b23 to your computer and use it in GitHub Desktop.

Select an option

Save fxprime/11f6cb5c12e4de6797ee222083382b23 to your computer and use it in GitHub Desktop.
/**
* www.ModuleMore.com
* ตัวอย่างการใช้งาน Shield LCD พร้อมปุ่มกด
*/
#include <Arduino.h>
#include <Wire.h>
#include <LiquidCrystal.h>
const int LCD_RS = 8;
const int LCD_EN = 9;
const int LCD_D0 = 4;
const int LCD_D1 = 5;
const int LCD_D2 = 6;
const int LCD_D3 = 7;
const int BUTTON_INPUT = A0;
// const int LCD_BLACKLIGHT = 10;
LiquidCrystal lcd(LCD_RS, LCD_EN, LCD_D0, LCD_D1, LCD_D2, LCD_D3);
void setup()
{
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("ModuleMore.com");
lcd.setCursor(0, 1);
lcd.print("Press Key:");
}
void loop()
{
int val = analogRead(BUTTON_INPUT);
lcd.setCursor(10, 1);
if (val < 60)
{
lcd.print("Right ");
}
else if (val < 200)
{
lcd.print("Up ");
}
else if (val < 400)
{
lcd.print("Down ");
}
else if (val < 600)
{
lcd.print("Left ");
}
else if (val < 800)
{
lcd.print("Select");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment