I am trying to understand how to use an ec11 encoder with push button function.
I have used the demo software and adapted it to my display.
It works fine with turning the encoder. But when I press the push button function nothing happens unless I turn the button at the same time. So I have to hold the button down while turning.
I expected that just pressing the push button is what switches between Count enable and Counting disabled in the program.
What I would like to learn is how to jump to a menu by pressing the push button, change and save a value in a variable, and then jump back to the main program by pressing the push button again.
How do I do that?
'''A demonstration program for GCBASIC.'''--------------------------------------------------------------------------------------------------------------------------------''' This program:'''MechanicalRotaryEncoder-ALPSEC11-w_o-Interrupts_LCD_18F2520.gcb''' demonstrates the use of mechanical rotary encoder'''withoutusinginterrupts''' with the ALPS-EC11.h include file.''''''@author Immo, DL5KB'''@licenceGPL'''@version 1.0b'''@dateDec.2019''' *****************************************'''Program:ReadsarotaryencoderALPSEC11''''''Turningtheknobcountsanumberupordowninsinglesteps,''' corresponding to turning sense.'''Pushingencoderswitch,disablescounting.''' Pushing encoder switch again, enables counting again.'''EncoderworkstoVss(0V),portsarepulledupinternal.''' LCD is 2x16 connected as 4 Wire Data (LCD_IO 4).'''*****************************************''' CHANGE CHIP AND PORTS ACCORDING TO YOUR TESTING BOARD!'''*****************************************;----configuration#chip 16F18877'load encoder header file#include <alps-ec11.h>#include <glcd.h>#startup InitPPS, 85#define PPSToolPart 16F18877SubInitPPS//Module:MSSP1//SSP1DATPPS=0x0014//RC4>SDA1//RC4PPS=0x0015//SDA1>RC4(bi-directional)//RC3PPS=0x0014//SCL1>RC3//SSP1CLKPPS=0x0013//RC3>SCL1(bi-directional)SSP1DATPPS=0x0013//RC3>SDA1RC3PPS=0x0015//SDA1>RC3(bi-directional)RC2PPS=0x0014//SCL1>RC2SSP1CLKPPS=0x0012//RC2>SCL1(bi-directional)EndSub;ANSELC=0x00;-----DefineI2CHardwaresettings#define HI2C_BAUD_RATE 400#define HI2C_DATA PORTC.3#define HI2C_CLOCK PORTC.2;InitialiseI2CMasterDirHI2C_DATAinDirHI2C_CLOCKin;MASTERHI2CModeMaster;-----DefineGLCDHardwaresettings#define GLCD_TYPE GLCD_TYPE_SH1106#define GLCD_I2C_Address 0x78;-----DefineportsI/ODirPORTA.0InDirPORTA.1InDirPORTA.2InDirPORTA.3InDirPORTA.4InDirPORTA.5InDirPORTB.0InDirPORTB.1InDirPORTB.2InDirPORTB.3InDirPORTD.0OutDirPORTD.1Out;-----NamePORTS#DEFINE RELAY1 PORTD.0#DEFINE RELAY2 PORTD.1;setweakpullupsoninputsportBWPUB=0xFF;----LCD-Settings'encoder connections defined here#define ALPS_ENCODER_A PortB.2 'clk#define ALPS_ENCODER_B PortB.0 'cw#define ALPS_ENCODER_SW PortB.3 'encoder-switch'''--------------------------------------------'''-------Endofboard-specificsettings-------'''-------------------------------------------- ; ---- variables 'value to be displayed DIM result as integer ; ---- main body of program begins here main: 'StartTimer-value to count result = 0 'switch not pressed Alps_ESB_Bit = OFF GLCDPrint(15, 5, "INVERTED TEXT", 0) GLCDPrint(15, 20, "NORMAL TEXT", 1) wait 5 s GLCDCLS GLCDPrint(1, 0 , "Rotary Enc. Demo", 0) GLCDPrint(1, 10 , "GCBASIC", 0) wait 2 s GLCDCLS GLCDPrint(1, 0 , "Dec 2023") GLCDPrint(1, 10 , "Immo's&Ano Code") wait 2 s GLCDCLS GLCDBackground = 0 GLCDForeground = 1 'Show what happening with encoder on the LCD GLCDPrint(1, 0 , "Counting enabled") GLCDPrint(1, 5 , "Rotate encoder ") 'now begin working...count: 'get encoder values (from include File) 'returns only, when encoder is turned 'or encoder_sw has been pressed (Alps_ESB_Bit = 1) if ! Alps_ESB_Bit then Alps_Encoder_Read '-------------------------- 'here you can insert any stuff you want ' ' 'to get back to counting, press button again '-------------------------- 'switch was pressed to escape reading loop if Alps_ESB_Bit = 1 then ' show me GLCDPrint(1, 0 , " count disabled ") GLCDPrint(1, 5 , " press button ") GLCDPrint (5, 40, Alps_ESB_Bit) 'toggle Alps_ESB_Bit, if you want/need Alps_Switch_Read if ! Alps_ESB_Bit Then 'switch was pressed again 'show me old display GLCDCLS GLCDPrint(1, 0 , "Counting enabled") GLCDPrint(1, 10 , " ") if result > -1 Then GLCDPrint(1, 20 , " ") end if GLCDPrint(5, 20 , result) GLCDPrint (5, 40, Alps_ESB_Bit) end if 'start work - loop counting goto count end if 'show detected direction of turning if Alps_directN = 1 then 'if enc_directN = 1 then GLCDPrint(45, 20 , " CW (+) ") Else GLCDPrint(45, 20 , "CCW (-) ") end if 'make new result result = result + Alps_Count_delta 'show me at same place as negatives if result > -1 Then GLCDPrint(1, 30 , " ") end if GLCDPrint(5, 30 , result) GLCDPrint (5, 40, Alps_ESB_Bit) goto count end
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Gert,
You might be chasing a red herring. Some manufacturers of the ECS11 do not bring out the switch connection to the pcb. You need to check this. You can activate the switch, but nothing happens.
Keyes model KY-040 has the switch available.
Cheers,
Geoffrey Younger
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I am trying to understand how to use an ec11 encoder with push button function.
I have used the demo software and adapted it to my display.
It works fine with turning the encoder. But when I press the push button function nothing happens unless I turn the button at the same time. So I have to hold the button down while turning.
I expected that just pressing the push button is what switches between Count enable and Counting disabled in the program.
What I would like to learn is how to jump to a menu by pressing the push button, change and save a value in a variable, and then jump back to the main program by pressing the push button again.
How do I do that?
Hi Gert,
You might be chasing a red herring. Some manufacturers of the ECS11 do not bring out the switch connection to the pcb. You need to check this. You can activate the switch, but nothing happens.
Keyes model KY-040 has the switch available.
Cheers,
Geoffrey Younger
Hi Geoffrey,
Thank you for your reply.
I have checked the pin for the switch, and it work as expected.
Cheers
Gert