@@ -7,7 +7,7 @@ http://www.r-site.net/?at=//op%5B%40id=%273090%27%5D
77Sept. 2014 Rui Azevedo - ruihfazevedo(@rrob@)gmail.com
88
99creative commons license 3.0: Attribution-ShareAlike CC BY-SA
10- This software is furnished "as is", without technical support, and with no
10+ This software is furnished "as is", without technical support, and with no
1111warranty, express or implied, as to its usefulness for any purpose.
1212
1313Thread Safe: No
2424********/
2525#include < SPI.h>
2626#include < menu.h> // menu macros and objects
27+ #include < menuFields.h>
2728#include < pcint.h> // this is incompatible with software serial (arduino needs an handler!)
2829#include < quadEncoder.h> // quadrature encoder driver and fake stream
2930#include < keyStream.h> // keyboard driver and fake stream (for the encoder button)
3334#include < Adafruit_ST7735.h> // Hardware-specific library
3435#include < menuGFX.h>
3536
37+ #define LEDPIN A4
38+
3639#if defined(__AVR_ATmega2560__)
3740 // /////////////////////////////////////////////////////////////////////////
3841 // TFT + SD
4952 // /////////////////////////////////////////////////////////////////////////
5053 // TFT + SD
5154 // #define sdCS 9//not using SD card
52- #define tftCS 10
53- #define dc 7
54- #define rst 8
55+ #define TFT_CS A1
56+ #define TFT_DC A0
57+ #define TFT_RST A2
5558 // //////////////////////////////////////////
5659 // ENCODER (aka rotary switch) PINS
57- #define encA A2
58- #define encB A1
59- #define encBtn A3
60+ #define encA 2
61+ #define encB 3
62+ #define encBtn 4
6063#else
6164 #error "Uknown pinout"
6265#endif
6366
64- Adafruit_ST7735 tft (tftCS, dc, rst);
67+ Adafruit_ST7735 tft (TFT_CS, TFT_DC, TFT_RST);
68+
69+ // aux vars
70+ int ledCtrl=0 ;
71+ int percent;// just testing changing this var
72+ int counter=0 ;
73+
6574// /////////////////////////////////////////////////////////////////////////
6675// functions to wire as menu actions
76+ bool ledOn () {
77+ Serial.println (" set led on!" );
78+ digitalWrite (LEDPIN,ledCtrl=1 );
79+ return false ;
80+ }
6781
68- // aux function
69- bool nothing () {return false ;}
82+ bool ledOff () {
83+ Serial.println (" set led off!" );
84+ digitalWrite (LEDPIN,ledCtrl=0 );
85+ return false ;
86+ }
7087
71- bool setValue (int &value,prompt &p,menuOut &o, Stream &i,const char * text,const char * units=" " ,int sensivity=5 ,int low=0 ,int hi=100 ,int steps=0 ,bool (*func)()=nothing);
88+ bool quit () {
89+ Serial.println (" Quiting after action call" );
90+ return true ;
91+ }
7292
7393// ///////////////////////////////////////////////////////////////////////
7494// MENU DEFINITION
7595// here we define the menu structure and wire actions functions to it
76- MENU (subMenu," Sub-Menu" ,
77- OP (" Op1" ,nothing),
78- OP(" Op2" ,nothing),
79- OP(" Op3" ,nothing)
96+ // empty options are just for scroll testing
97+
98+ /* bool setLed() {
99+ digitalWrite(LEDPIN,ledCtrl);
100+ return false;
101+ }*/
102+ TOGGLE (ledCtrl,setLed," Led: " ,
103+ VALUE (" On" ,HIGH,ledOn),
104+ VALUE(" Off" ,LOW,ledOff)
105+ );
106+
107+ int selTest=0 ;
108+ SELECT (selTest,selMenu," Select" ,
109+ VALUE (" Zero" ,0 ),
110+ VALUE(" One" ,1 ),
111+ VALUE(" Two" ,2 )
80112);
81113
82- MENU (mainMenu," Sistema" ,
83- OP (" A" ,nothing),
84- OP(" B" ,nothing),
85- SUBMENU(subMenu)
114+ int chooseTest=-1 ;
115+ CHOOSE (chooseTest,chooseMenu," Choose " ,
116+ VALUE (" First" ,1 ),
117+ VALUE(" Second" ,2 ),
118+ VALUE(" Third" ,3 ),
119+ VALUE(" Last" ,-1 )
120+ );
121+
122+ MENU (subMenu," SubMenu"
123+ ,OP(" A" ,quit)
124+ ,OP(" B" ,quit)
125+ ,OP(" C" ,quit)
126+ ,OP(" D" ,quit)
127+ ,OP(" E" ,quit)
128+ ,OP(" F" ,quit)
129+ ,OP(" G" ,quit)
130+ ,OP(" H" ,quit)
131+ );
132+
133+ MENU (mainMenu," Main menu" ,
134+ SUBMENU (setLed),
135+ OP(" LED On" ,ledOn),
136+ OP(" LED Off" ,ledOff),
137+ SUBMENU(selMenu),
138+ SUBMENU(chooseMenu),
139+ SUBMENU(subMenu),
140+ FIELD(percent," Percent" ," %" ,0 ,100 ,10 ,1 )
86141);
87142
88143// the quadEncoder
@@ -102,39 +157,34 @@ Stream* in3[]={&enc,&encButton};
102157chainStream<3 > allIn (in3);
103158
104159// describing a menu output, alternatives so far are Serial or LiquidCrystal LCD
105- menuGFX gfx (tft);
160+ menuGFX gfx (tft,BLUE,BLACK,WHITE,SILVER, 6 , 9 );
106161
107162// ///////////////////////////////////////////////////////////////////////
108163void setup () {
164+ pinMode (LEDPIN,OUTPUT);
109165 SPI.begin ();
110166 tft.initR (INITR_BLACKTAB);
111167 tft.setRotation (3 );
112168 tft.setTextWrap (false );
113169 tft.setTextColor (ST7735_RED,ST7735_BLACK);
114- tft.setTextSize (2 );
115- gfx.resX *=2 ;// update resolution after font size change
116- gfx.resY *=2 ;// update resolution after font size change
170+ // tft.setTextSize(2);
171+ // gfx.resX*=2;//update resolution after font size change
172+ // gfx.resY*=2;//update resolution after font size change
117173 tft.fillScreen (ST7735_BLACK);
118174 tft.print (" Menu test on GFX" );
119175 // testing menu limits (not using all the screen)
120176 // size is within screen limits even after rotation
121177 // this limits are not constrained, please ensure your text fits
122- gfx.maxX =8 ;
123- gfx.maxY =3 ;
178+ gfx.maxX =16 ;
179+ gfx.maxY =5 ;
124180 gfx.bgColor =SILVER;
125-
126- pinMode (encBtn, INPUT);
127- digitalWrite (encBtn,1 );
128-
181+ pinMode (encBtn, INPUT_PULLUP);
129182 encoder.begin ();
130-
131- delay (300 );
132- tft.fillScreen (GREEN);
133183}
134184
135185// /////////////////////////////////////////////////////////////////////////////
136186// testing the menu system
137187void loop () {
138188 mainMenu.poll (gfx,allIn);
189+ digitalWrite (LEDPIN, ledCtrl);
139190}
140-
0 commit comments