Skip to content

Commit

Permalink
Fixed pin settings after completion of pressure(); corrected spelling…
Browse files Browse the repository at this point in the history
… of pressureThreshold; fix issue adafruit#8 by implementing isTouching
  • Loading branch information
jtickle committed Dec 21, 2017
1 parent 2d5821f commit 023002c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
25 changes: 22 additions & 3 deletions TouchScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ TouchScreen::TouchScreen(uint8_t xp, uint8_t yp, uint8_t xm, uint8_t ym,
ym_pin = digitalPinToBitMask(_ym);
#endif

pressureThreshhold = 10;
pressureThreshold = 10;
}

int TouchScreen::readTouchX(void) {
Expand Down Expand Up @@ -243,6 +243,8 @@ uint16_t TouchScreen::pressure(void) {
int z1 = analogRead(_xm);
int z2 = analogRead(_yp);

uint16_t retval;

if (_rxplate != 0) {
// now read the x
float rtouch;
Expand All @@ -253,8 +255,25 @@ uint16_t TouchScreen::pressure(void) {
rtouch *= _rxplate;
rtouch /= 1024;

return rtouch;
retval = rtouch;
} else {
return (1023-(z2-z1));
retval = (1023-(z2-z1));
}

//Clean the touchScreen settings after function is used
//Because LCD may use the same pins
pinMode(_xm, OUTPUT);
digitalWrite(_xm, LOW);
pinMode(_yp, OUTPUT);
digitalWrite(_yp, HIGH);
pinMode(_ym, OUTPUT);
digitalWrite(_ym, LOW);
pinMode(_xp, OUTPUT);
digitalWrite(_xp, HIGH);

return retval;
}

bool TouchScreen::isTouching(void) {
return pressure() > pressureThreshold;
}
2 changes: 1 addition & 1 deletion TouchScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class TouchScreen {
int readTouchY();
int readTouchX();
TSPoint getPoint();
int16_t pressureThreshhold;
int16_t pressureThreshold;

private:
uint8_t _yp, _ym, _xm, _xp;
Expand Down

0 comments on commit 023002c

Please sign in to comment.