With the Uno R3 and Adafruit LCD shield with buttons and blue 16x2 LCD, I played with the LCD tutorial and some nice bit of code from unknown source (thought I had saved it, sorry to the person I can't thank more loudly ) and here we are:
Code: Select all
/*********************
*
* Example code for the Adafruit RGB Character LCD Shield and Library
*
* This code displays text on the shield, and also reads the buttons on the keypad.
* When a button is pressed, the backlight changes color.
*
**********************/
// include the library code:
#include <Wire.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>
// The shield uses the I2C SCL and SDA pins. On classic Arduinos
// this is Analog 4 and 5 so you can't use those for analogRead() anymore
// However, you can connect other I2C sensors to the I2C bus and share
// the I2C bus.
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
// These #defines make it easy to set the backlight color
#define RED 0x1
#define YELLOW 0x3
#define GREEN 0x2
#define TEAL 0x6
#define BLUE 0x4
#define VIOLET 0x5
#define WHITE 0x7
const int button1 = 7;
const int button2 = 10;
int pos = 0;
int cpos1 = 0;
int cpos2 = 0;
String output = "----------------BANNED----------------";
void setup() {
// Debugging output
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD. We track how long it takes since
// this library has been optimized a bit and we're proud of it :)
int time = millis();
lcd.print(output);
lcd.setBacklight(WHITE);
//Setup some buttons
pinMode (button1, INPUT);
pinMode (button2, INPUT);
//Turn the internal resistors on so the thing does go kaput
digitalWrite(button1, HIGH);
digitalWrite(button2, HIGH);
}
uint8_t i=0;
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
uint8_t buttons = lcd.readButtons();
//Change the position
if (buttons) {
lcd.setCursor(0,0);
if (buttons & BUTTON_RIGHT)
pos ++;
cpos1 ++;
delay (500);
}
if (buttons) {
lcd.setCursor(0,0);
if (buttons & BUTTON_LEFT)
pos --;
cpos1 --;
delay (500);
}
if (pos >= 16 && pos <= 39)
{
pos = 40;
cpos1 = 0;
cpos2 = 1;
}
if (pos >= 56)
{
pos = 0;
cpos1 = 0;
cpos2 = 0;
}
// Cycles through the characters on the selected spot
if (buttons) {
lcd.setCursor(0,0);
if (buttons & BUTTON_UP)
{
lcd.clear();
lcd.print(output);
output [pos] = (output [pos] ++);
lcd.clear();
lcd.print(output);
delay (400);
}
if (buttons & BUTTON_DOWN)
{
lcd.clear();
lcd.print(output);
output [pos] = (output [pos] --);
lcd.clear();
lcd.print(output);
delay (400);
}
lcd.setCursor (cpos1, cpos2);
lcd.blink();
}
}
thanks