I am trying to write some code to make it easy to add different buttons to a touch screen. I need each object to be a different object of class 'touchButton'. I'd like to be able to run a touchButton.Draw
function, which in turn will run LCD library commands. Is there a way I could do that? Here is my source code:
TouchScreen.ino:
#include "touchButton.h"
#include <UTFT.h>
#include <UTouch.h>
#include <avr/pgmspace.h>
UTFT myGLCD(ITDB32S, 38, 39, 40, 41);
UTouch myTouch( 6, 5, 4, 3, 2);
extern uint8_t SmallFont[];
void setup() {
myGLCD.InitLCD();
myGLCD.setFont(SmallFont);
myGLCD.clrScr();
myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);
myGLCD.fillScr(51, 51, 51);
//what I want to be able to do:
//touchButton Button1 (10, 10, 20, 20, 'p');
//Button1.Draw();
}
void loop() {
}
touchButton.h
#ifndef touchButton_h
#define touchButton_h
#include "Arduino.h"
class touchButton {
public:
touchButton(int x, int y, int xs, int ys, char use);
void Draw();
int x1;
int y1;
int xsize;
int ysize;
char use;
boolean toggle = false;
};
#endif
touchButton.cpp
#include "Arduino.h"
#include "touchButton.h"
touchButton::touchButton(int x, int y, int xs, int ys, char myuse) {
x1 = x;
y1 = y;
xsize = xs;
ysize = ys;
use = myuse;
}
void touchButton::Draw() {
switch (use) {
case 'p':
//this is what I would like to have called from the main file.
//myGLCD.drawRoundRect(x1, y1, x1+xsize, y1+ysize);
break;
default:
break;
}
}