3333#include < Adafruit_GFX.h> // Core graphics library
3434#include < Adafruit_ST7735.h> // Hardware-specific library
3535#include < menuGFX.h>
36- #include < menuFields.h>
3736
3837
3938#if defined(__AVR_ATmega2560__)
5251 #define LEDPIN A3
5352 // /////////////////////////////////////////////////////////////////////////
5453 // TFT + SD
55- // TFT + SD
56- // #define sdCS 9//not using SD card
57- #define tftCS A1
58- #define dc A0
59- #define rst A2
54+ #define TFT_DC A0
55+ #define TFT_CS A1
56+ #define TFT_RST A2
6057 // //////////////////////////////////////////
6158 // ENCODER (aka rotary switch) PINS
62- #define encA 2
63- #define encB 3
64- #define encBtn 4
59+ #define encA 2
60+ #define encB 3
61+ #define encBtn 4
6562#else
6663 #error "Uknown pinout"
6764#endif
6865
69- Adafruit_ST7735 tft (tftCS, dc, rst);
70-
71- // wire led here because default led is already used by hardware SPI
72- #define LEDPIN A3
66+ Adafruit_ST7735 tft (TFT_CS, TFT_DC, TFT_RST);
7367
7468// aux vars
7569int ledCtrl=0 ;
76- bool runMenu=false ;
77- bool scrSaverEnter=true ;
7870int percent;// just testing changing this var
79- double fps=0 ;
80- unsigned long lastFpsChk=0 ;
8171int counter=0 ;
8272
8373// /////////////////////////////////////////////////////////////////////////
8474// functions to wire as menu actions
85- bool pauseMenu () {
86- runMenu=false ;
87- scrSaverEnter=true ;
88- }
8975bool ledOn () {
9076 Serial.println (" set led on!" );
9177 digitalWrite (LEDPIN,ledCtrl=1 );
@@ -150,23 +136,9 @@ MENU(mainMenu,"Main menu",
150136 SUBMENU(selMenu),
151137 SUBMENU(chooseMenu),
152138 SUBMENU(subMenu),
153- FIELD(percent," Percent" ," %" ,0 ,100 ,10 ,1 ),
154- FIELD(fps," fps [" ," ]" ,0 ,0 ,0 ,0 ),
155- FIELD(counter," counter [" ," ]" ,0 ,0 ,0 ,0 ),
156- OP(" Exit" ,pauseMenu)
139+ FIELD(percent," Percent" ," %" ,0 ,100 ,10 ,1 )
157140);
158141
159- void scrSaver () {
160- if (scrSaverEnter) {
161- tft.fillScreen (ST7735_BLACK);
162- tft.print (" |www.r-site.net|" );
163- tft.setCursor (0 ,1 );
164- tft.print (" |click to enter|" );
165- scrSaverEnter=false ;
166- }
167- }
168-
169-
170142// the quadEncoder
171143quadEncoder encoder (encA,encB);// simple quad encoder driver
172144quadEncoderStream enc (encoder,5 );// simple quad encoder fake Stream
@@ -180,7 +152,7 @@ Stream* in[]={&enc,&encButton};
180152chainStream<2 > quadEncoder_button (in);
181153
182154// alternative to previous but now we can input from Serial too...
183- Stream* in3[]={&enc,&encButton,&Serial };
155+ Stream* in3[]={&enc,&encButton};
184156chainStream<3 > allIn (in3);
185157
186158// describing a menu output, alternatives so far are Serial or LiquidCrystal LCD
@@ -194,16 +166,16 @@ void setup() {
194166 tft.setRotation (3 );
195167 tft.setTextWrap (false );
196168 tft.setTextColor (ST7735_RED,ST7735_BLACK);
197- tft.setTextSize (1 );
198- gfx.resX *=1 ;// update resolution after font size change
199- gfx.resY *=1 ;// update resolution after font size change
169+ // tft.setTextSize(2 );
170+ // gfx.resX*=2 ;//update resolution after font size change
171+ // gfx.resY*=2 ;//update resolution after font size change
200172 tft.fillScreen (ST7735_BLACK);
201173 tft.print (" Menu test on GFX" );
202174 // testing menu limits (not using all the screen)
203175 // size is within screen limits even after rotation
204176 // this limits are not constrained, please ensure your text fits
205177 gfx.maxX =16 ;
206- gfx.maxY =10 ;
178+ gfx.maxY =5 ;
207179 gfx.bgColor =SILVER;
208180 pinMode (encBtn, INPUT_PULLUP);
209181 encoder.begin ();
@@ -212,16 +184,6 @@ void setup() {
212184// /////////////////////////////////////////////////////////////////////////////
213185// testing the menu system
214186void loop () {
215- if (runMenu) mainMenu.poll (gfx,allIn);
216- else if (allIn.read ()==menu::enterCode) runMenu=true ;
217- else scrSaver ();
218- // simulate the delay of your program... if this number rises too much the menu will have bad navigation experience
219- // if so, then the menu can be wired into a timmer... leaving the shorter end to your code while it is running
220- counter=millis ()/1000 %60 ;
221- int d=micros ()-lastFpsChk;
222- if (d>0 ) {
223- fps=1000000.0 /d;
224- lastFpsChk+=d;
225- }
226- delay (50 );
187+ mainMenu.poll (gfx,allIn);
188+ digitalWrite (LEDPIN, ledCtrl);
227189}
0 commit comments