I'm confused...
I can get this code to work using the buttons on the ADAFRUIT shield, but using a rotary encoder with the rotary.h library doesn't seem to do anything. I feel like its not reading the encoder quick enough.
I'm using the MenuSystems Library (New Arduino library: MenuSystem - Libraries - Arduino Forum), a Rotary Library (GitHub - brianlow/Rotary: Rotary encoder library for Arduino) and the ADAFRUIT RGB LCD library. I choose the MenuSystems and Rotary libraries because they were very straight forward and seemed easy to use.
I'm just learning all of this, so i'm sure I am making all sorts of mistakes.
a nudge in the right direction is all I need. Here is my code (its not %100 done yet)
// ADAFRUIT Library
#include <Wire.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>
//Rotary Library
#include <Rotary.h>
//Menu Library
#include <MenuSystem.h>
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
Rotary r = Rotary(5, 6);
const int buttonPin1 = 4; //Rotary pin for push button
// These 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
// Menu variables
MenuSystem ms;
Menu mm("");
MenuItem mm_mi1("TIMED GAME ");
MenuItem mm_mi2("SHOTS GAME ");
Menu mu1("SETTINGS ");
MenuItem mu1_mi1("BACKLIGHT ");
MenuItem mu1_mi2("PLAYERS ");
// variables
int buttonState1 = 1;
int colorInt = 1;
void on_item1_selected(MenuItem* p_menu_item)
{
lcd.setCursor(0, 1);
lcd.print("Item1 Selected");
delay(3000);
}
void on_item2_selected(MenuItem* p_menu_item)
{
lcd.setCursor(0, 1);
lcd.print("Item2 Selected");
delay(3000);
}
void on_item3_selected(MenuItem* p_menu_item)
{
lcd.setCursor(0, 1);
lcd.print("Item3 Selected");
delay(3000);
}
void on_item4_selected(MenuItem* p_menu_item)
{
lcd.setCursor(0, 1);
lcd.print("Item4 Selected");
delay(3000);
}
void setup()
{
Serial.begin(9600);
lcd.begin(16, 2);
lcd.clear();
pinMode(buttonPin1, INPUT);
// Menu setup
mm.add_item(&mm_mi1, &on_item1_selected);
mm.add_item(&mm_mi2, &on_item2_selected);
mm.add_menu(&mu1);
mu1.add_item(&mu1_mi1, &on_item3_selected);
mu1.add_item(&mu1_mi2, &on_item4_selected);
ms.set_root_menu(&mm);
}
void loop()
{
process_input();
update_menu();
}
void update_menu()
{
lcd.setCursor(0, 0);
// Display the menu
lcd.print(ms.get_current_menu()->get_selected()->get_name());
lcd.setCursor(0, 1);
}
void process_input()
{
unsigned char result = r.process();
if (result)
{
if (result == DIR_CW)
ms.next();
if (result == DIR_CCW)
ms.prev();
}
}