void setup() {
// put your setup code here, to run once:
//////////////////////////////////////////////
// Arduino Rotary Encoder Menu //
// v1.0 //
// http://www.educ8s.tv //
/////////////////////////////////////////////
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
#include <ClickEncoder.h>
#include <TimerOne.h>
int menuitem = 1;
int frame = 1;
int page = 1;
int lastMenuItem = 1;
String menuItem1 = "Contrast";
String menuItem2 = "Volume";
String menuItem3 = "Language";
String menuItem4 = "Difficulty";
String menuItem5 = "Light: ON";
String menuItem6 = "Reset";
boolean backlight = true;
int contrast=60;
int volume = 50;
String language[3] = { "EN", "ES", "EL" };
int selectedLanguage = 0;
String difficulty[2] = { "EASY", "HARD" };
int selectedDifficulty = 0;
boolean up = false;
boolean down = false;
boolean middle = false;
ClickEncoder *encoder;
int16_t last, value;
Adafruit_PCD8544 display = Adafruit_PCD8544( 5, 4, 3);//This only works with recent Adafruit Nokia 5110 library. Ensure yours is up to date
CLOCKWISE STUFF
https://circuitdigest.com/microcontroller-projects/interfacing-rotary-encoder-with-arduino
/*
* Interfacing Rotary Encoder with Arduino
* Dated: 6-7-2018
* Website: www.circuitdigest.com
*
* Power LCD and Rotary encoder from the +5V pin of Arduino
* LCD RS -> pin 7
* LCD EN -> pin 6
* LCD D4 -> pin 5
* LCD D5 -> pin 4
* LCD D6 -> pin 3
* LCD D7 -> pin 2
* Encoder Switch -> pin 10
* Encoder Output A -> pin 9
* Encoder Output B -> pin 8
*/
int Encoder_OuputA = 4;
int Encoder_OuputB = 3;
int Encoder_Switch = 2;
int Previous_Output;
int Encoder_Count;
#include <LiquidCrystal.h> //Default Arduino LCD Librarey is included
const int rs = 7, en = 8, d4 = 10, d5 = 11, d6 = 12, d7 = 13; //Mention the pin number for LCD connection
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
lcd.begin(16, 2); //Initialise 16*2 LCD
lcd.print(" Rotary Encoder "); //Intro Message line 1
lcd.setCursor(0, 1);
lcd.print(" With Arduino "); //Intro Message line 2
delay(2000);
lcd.clear();
//pin Mode declaration
pinMode (Encoder_OuputA, INPUT);
pinMode (Encoder_OuputB, INPUT);
pinMode (Encoder_Switch, INPUT);
Previous_Output = digitalRead(Encoder_OuputA); //Read the inital value of Output A
}
void loop() {
//aVal = digitalRead(pinA);
if (digitalRead(Encoder_OuputA) != Previous_Output)
{
if (digitalRead(Encoder_OuputB) != Previous_Output)
{
Encoder_Count ++;
lcd.clear();
lcd.print(Encoder_Count);
lcd.setCursor(0, 1);
lcd.print("Clockwise");
}
else
{
Encoder_Count--;
lcd.clear();
lcd.print(Encoder_Count);
lcd.setCursor(0, 1);
lcd.print("Anti - Clockwise");
}
}
Previous_Output = digitalRead(Encoder_OuputA);
if (digitalRead(Encoder_Switch) == 0)
{
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Switch pressed");
}
}
}
void loop() {
// put your main code here, to run repeatedly:
}