First Commit
This commit is contained in:
26
libraries/Adafruit_TouchScreen/README.md
Normal file
26
libraries/Adafruit_TouchScreen/README.md
Normal file
@@ -0,0 +1,26 @@
|
||||
# Adafruit TouchScreen Library [](https://github.com/adafruit/Adafruit_TouchScreen/actions)
|
||||
|
||||
This is the 4-wire resistive touch screen firmware for Arduino. Works with all Arduinos and Teensy
|
||||
|
||||
|
||||
Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!
|
||||
|
||||
# Contributing
|
||||
|
||||
Contributions are welcome! Please read our [Code of Conduct](https://github.com/adafruit/Adafruit_TouchScreen/blob/master/CODE_OF_CONDUCT.md>)
|
||||
before contributing to help this project stay welcoming.
|
||||
|
||||
## Documentation and doxygen
|
||||
Documentation is produced by doxygen. Contributions should include documentation for any new code added.
|
||||
|
||||
Some examples of how to use doxygen can be found in these guide pages:
|
||||
|
||||
https://learn.adafruit.com/the-well-automated-arduino-library/doxygen
|
||||
|
||||
https://learn.adafruit.com/the-well-automated-arduino-library/doxygen-tips
|
||||
|
||||
Written by Limor Fried for Adafruit Industries.
|
||||
BSD license, check license.txt for more information
|
||||
All text above must be included in any redistribution
|
||||
|
||||
To install, use the Arduino Library Manager and search for "Adafruit TouchScreen" and install the library.
|
||||
291
libraries/Adafruit_TouchScreen/TouchScreen.cpp
Normal file
291
libraries/Adafruit_TouchScreen/TouchScreen.cpp
Normal file
@@ -0,0 +1,291 @@
|
||||
// Touch screen library with X Y and Z (pressure) readings as well
|
||||
// as oversampling to avoid 'bouncing'
|
||||
// (c) ladyada / adafruit
|
||||
// Code under MIT License
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "pins_arduino.h"
|
||||
|
||||
#ifdef __AVR
|
||||
#include <avr/pgmspace.h>
|
||||
#elif defined(ESP8266)
|
||||
#include <pgmspace.h>
|
||||
#endif
|
||||
#include "TouchScreen.h"
|
||||
|
||||
// increase or decrease the touchscreen oversampling. This is a little different
|
||||
// than you make think: 1 is no oversampling, whatever data we get is
|
||||
// immediately returned 2 is double-sampling and we only return valid data if
|
||||
// both points are the same 3+ uses insert sort to get the median value. We
|
||||
// found 2 is precise yet not too slow so we suggest sticking with it!
|
||||
|
||||
#define NUMSAMPLES 2
|
||||
|
||||
TSPoint::TSPoint(void) { x = y = z = 0; }
|
||||
/**
|
||||
* @brief Construct a new TSPoint::TSPoint object
|
||||
*
|
||||
* @param x0 The point's X value
|
||||
* @param y0 The point's Y value
|
||||
* @param z0 The point's Z value
|
||||
*/
|
||||
TSPoint::TSPoint(int16_t x0, int16_t y0, int16_t z0) {
|
||||
x = x0;
|
||||
y = y0;
|
||||
z = z0;
|
||||
}
|
||||
/**
|
||||
* @brief Check if the current point is equivalent to another point
|
||||
*
|
||||
* @param p1 The other point being checked for equivalence
|
||||
* @return `true` : the two points are equivalent
|
||||
* `false`: the two points are **not** equivalent
|
||||
*/
|
||||
bool TSPoint::operator==(TSPoint p1) {
|
||||
return ((p1.x == x) && (p1.y == y) && (p1.z == z));
|
||||
}
|
||||
/**
|
||||
* @brief Check if the current point is **not** equivalent to another point
|
||||
*
|
||||
* @param p1 The other point being checked for equivalence
|
||||
|
||||
* @return `true` :the two points are **not** equivalent
|
||||
* `false`: the two points are equivalent
|
||||
*/
|
||||
bool TSPoint::operator!=(TSPoint p1) {
|
||||
return ((p1.x != x) || (p1.y != y) || (p1.z != z));
|
||||
}
|
||||
|
||||
#if (NUMSAMPLES > 2)
|
||||
static void insert_sort(int array[], uint8_t size) {
|
||||
uint8_t j;
|
||||
int save;
|
||||
|
||||
for (int i = 1; i < size; i++) {
|
||||
save = array[i];
|
||||
for (j = i; j >= 1 && save < array[j - 1]; j--)
|
||||
array[j] = array[j - 1];
|
||||
array[j] = save;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/**
|
||||
* @brief Measure the X, Y, and pressure and return a TSPoint with the
|
||||
* measurements
|
||||
*
|
||||
* @return TSPoint The measured X, Y, and Z/pressure values
|
||||
*/
|
||||
TSPoint TouchScreen::getPoint(void) {
|
||||
int x, y, z;
|
||||
int samples[NUMSAMPLES];
|
||||
uint8_t i, valid;
|
||||
|
||||
valid = 1;
|
||||
|
||||
pinMode(_yp, INPUT);
|
||||
pinMode(_ym, INPUT);
|
||||
pinMode(_xp, OUTPUT);
|
||||
pinMode(_xm, OUTPUT);
|
||||
|
||||
#if defined(USE_FAST_PINIO)
|
||||
*xp_port |= xp_pin;
|
||||
*xm_port &= ~xm_pin;
|
||||
#else
|
||||
digitalWrite(_xp, HIGH);
|
||||
digitalWrite(_xm, LOW);
|
||||
#endif
|
||||
|
||||
#ifdef __arm__
|
||||
delayMicroseconds(20); // Fast ARM chips need to allow voltages to settle
|
||||
#endif
|
||||
|
||||
for (i = 0; i < NUMSAMPLES; i++) {
|
||||
samples[i] = analogRead(_yp);
|
||||
}
|
||||
|
||||
#if NUMSAMPLES > 2
|
||||
insert_sort(samples, NUMSAMPLES);
|
||||
#endif
|
||||
#if NUMSAMPLES == 2
|
||||
// Allow small amount of measurement noise, because capacitive
|
||||
// coupling to a TFT display's signals can induce some noise.
|
||||
if (samples[0] - samples[1] < -4 || samples[0] - samples[1] > 4) {
|
||||
valid = 0;
|
||||
} else {
|
||||
samples[1] = (samples[0] + samples[1]) >> 1; // average 2 samples
|
||||
}
|
||||
#endif
|
||||
|
||||
x = (1023 - samples[NUMSAMPLES / 2]);
|
||||
|
||||
pinMode(_xp, INPUT);
|
||||
pinMode(_xm, INPUT);
|
||||
pinMode(_yp, OUTPUT);
|
||||
pinMode(_ym, OUTPUT);
|
||||
|
||||
#if defined(USE_FAST_PINIO)
|
||||
*ym_port &= ~ym_pin;
|
||||
*yp_port |= yp_pin;
|
||||
#else
|
||||
digitalWrite(_ym, LOW);
|
||||
digitalWrite(_yp, HIGH);
|
||||
#endif
|
||||
|
||||
#ifdef __arm__
|
||||
delayMicroseconds(20); // Fast ARM chips need to allow voltages to settle
|
||||
#endif
|
||||
|
||||
for (i = 0; i < NUMSAMPLES; i++) {
|
||||
samples[i] = analogRead(_xm);
|
||||
}
|
||||
|
||||
#if NUMSAMPLES > 2
|
||||
insert_sort(samples, NUMSAMPLES);
|
||||
#endif
|
||||
#if NUMSAMPLES == 2
|
||||
// Allow small amount of measurement noise, because capacitive
|
||||
// coupling to a TFT display's signals can induce some noise.
|
||||
if (samples[0] - samples[1] < -4 || samples[0] - samples[1] > 4) {
|
||||
valid = 0;
|
||||
} else {
|
||||
samples[1] = (samples[0] + samples[1]) >> 1; // average 2 samples
|
||||
}
|
||||
#endif
|
||||
|
||||
y = (1023 - samples[NUMSAMPLES / 2]);
|
||||
|
||||
// Set X+ to ground
|
||||
// Set Y- to VCC
|
||||
// Hi-Z X- and Y+
|
||||
pinMode(_xp, OUTPUT);
|
||||
pinMode(_yp, INPUT);
|
||||
|
||||
#if defined(USE_FAST_PINIO)
|
||||
*xp_port &= ~xp_pin;
|
||||
*ym_port |= ym_pin;
|
||||
#else
|
||||
digitalWrite(_xp, LOW);
|
||||
digitalWrite(_ym, HIGH);
|
||||
#endif
|
||||
|
||||
int z1 = analogRead(_xm);
|
||||
int z2 = analogRead(_yp);
|
||||
|
||||
if (_rxplate != 0) {
|
||||
// now read the x
|
||||
float rtouch;
|
||||
rtouch = z2;
|
||||
rtouch /= z1;
|
||||
rtouch -= 1;
|
||||
rtouch *= x;
|
||||
rtouch *= _rxplate;
|
||||
rtouch /= 1024;
|
||||
|
||||
z = rtouch;
|
||||
} else {
|
||||
z = (1023 - (z2 - z1));
|
||||
}
|
||||
|
||||
if (!valid) {
|
||||
z = 0;
|
||||
}
|
||||
|
||||
return TSPoint(x, y, z);
|
||||
}
|
||||
|
||||
TouchScreen::TouchScreen(uint8_t xp, uint8_t yp, uint8_t xm, uint8_t ym,
|
||||
uint16_t rxplate = 0) {
|
||||
_yp = yp;
|
||||
_xm = xm;
|
||||
_ym = ym;
|
||||
_xp = xp;
|
||||
_rxplate = rxplate;
|
||||
|
||||
#if defined(USE_FAST_PINIO)
|
||||
xp_port = portOutputRegister(digitalPinToPort(_xp));
|
||||
yp_port = portOutputRegister(digitalPinToPort(_yp));
|
||||
xm_port = portOutputRegister(digitalPinToPort(_xm));
|
||||
ym_port = portOutputRegister(digitalPinToPort(_ym));
|
||||
|
||||
xp_pin = digitalPinToBitMask(_xp);
|
||||
yp_pin = digitalPinToBitMask(_yp);
|
||||
xm_pin = digitalPinToBitMask(_xm);
|
||||
ym_pin = digitalPinToBitMask(_ym);
|
||||
#endif
|
||||
|
||||
pressureThreshhold = 10;
|
||||
}
|
||||
/**
|
||||
* @brief Read the touch event's X value
|
||||
*
|
||||
* @return int the X measurement
|
||||
*/
|
||||
int TouchScreen::readTouchX(void) {
|
||||
pinMode(_yp, INPUT);
|
||||
pinMode(_ym, INPUT);
|
||||
digitalWrite(_yp, LOW);
|
||||
digitalWrite(_ym, LOW);
|
||||
|
||||
pinMode(_xp, OUTPUT);
|
||||
digitalWrite(_xp, HIGH);
|
||||
pinMode(_xm, OUTPUT);
|
||||
digitalWrite(_xm, LOW);
|
||||
|
||||
return (1023 - analogRead(_yp));
|
||||
}
|
||||
/**
|
||||
* @brief Read the touch event's Y value
|
||||
*
|
||||
* @return int the Y measurement
|
||||
*/
|
||||
int TouchScreen::readTouchY(void) {
|
||||
pinMode(_xp, INPUT);
|
||||
pinMode(_xm, INPUT);
|
||||
digitalWrite(_xp, LOW);
|
||||
digitalWrite(_xm, LOW);
|
||||
|
||||
pinMode(_yp, OUTPUT);
|
||||
digitalWrite(_yp, HIGH);
|
||||
pinMode(_ym, OUTPUT);
|
||||
digitalWrite(_ym, LOW);
|
||||
|
||||
return (1023 - analogRead(_xm));
|
||||
}
|
||||
/**
|
||||
* @brief Read the touch event's Z/pressure value
|
||||
*
|
||||
* @return int the Z measurement
|
||||
*/
|
||||
uint16_t TouchScreen::pressure(void) {
|
||||
// Set X+ to ground
|
||||
pinMode(_xp, OUTPUT);
|
||||
digitalWrite(_xp, LOW);
|
||||
|
||||
// Set Y- to VCC
|
||||
pinMode(_ym, OUTPUT);
|
||||
digitalWrite(_ym, HIGH);
|
||||
|
||||
// Hi-Z X- and Y+
|
||||
digitalWrite(_xm, LOW);
|
||||
pinMode(_xm, INPUT);
|
||||
digitalWrite(_yp, LOW);
|
||||
pinMode(_yp, INPUT);
|
||||
|
||||
int z1 = analogRead(_xm);
|
||||
int z2 = analogRead(_yp);
|
||||
|
||||
if (_rxplate != 0) {
|
||||
// now read the x
|
||||
float rtouch;
|
||||
rtouch = z2;
|
||||
rtouch /= z1;
|
||||
rtouch -= 1;
|
||||
rtouch *= readTouchX();
|
||||
rtouch *= _rxplate;
|
||||
rtouch /= 1024;
|
||||
|
||||
return rtouch;
|
||||
} else {
|
||||
return (1023 - (z2 - z1));
|
||||
}
|
||||
}
|
||||
80
libraries/Adafruit_TouchScreen/TouchScreen.h
Normal file
80
libraries/Adafruit_TouchScreen/TouchScreen.h
Normal file
@@ -0,0 +1,80 @@
|
||||
// Touch screen library with X Y and Z (pressure) readings as well
|
||||
// as oversampling to avoid 'bouncing'
|
||||
// (c) ladyada / adafruit
|
||||
// Code under MIT License
|
||||
|
||||
#ifndef _ADAFRUIT_TOUCHSCREEN_H_
|
||||
#define _ADAFRUIT_TOUCHSCREEN_H_
|
||||
#include <stdint.h>
|
||||
|
||||
#if (defined(__AVR_ATmega328P__) || defined(__AVR_ATmega32U4__) || \
|
||||
defined(TEENSYDUINO) || defined(__AVR_ATmega2560__) || \
|
||||
defined(__AVR_ATmega4809__)) && \
|
||||
!defined(__IMXRT1062__)
|
||||
typedef volatile uint8_t RwReg;
|
||||
#elif defined(ARDUINO_STM32_FEATHER)
|
||||
typedef volatile uint32 RwReg;
|
||||
#elif defined(NRF52_SERIES) || defined(ESP32) || defined(ESP8266) || \
|
||||
defined(ARDUINO_ARCH_STM32) || defined(__IMXRT1062__)
|
||||
typedef volatile uint32_t RwReg;
|
||||
#else
|
||||
typedef volatile uint32_t RwReg;
|
||||
#endif
|
||||
|
||||
#if defined(__AVR__) || defined(TEENSYDUINO) || defined(ARDUINO_ARCH_SAMD)
|
||||
#define USE_FAST_PINIO
|
||||
#endif
|
||||
|
||||
/** Object that encapsulates the X,Y, and Z/pressure measurements for a touch
|
||||
* event. */
|
||||
class TSPoint {
|
||||
public:
|
||||
TSPoint(void);
|
||||
TSPoint(int16_t x, int16_t y, int16_t z);
|
||||
|
||||
bool operator==(TSPoint);
|
||||
bool operator!=(TSPoint);
|
||||
|
||||
int16_t x, ///< state variable for the x value
|
||||
y, ///< state variable for the y value
|
||||
z; ///< state variable for the z value
|
||||
};
|
||||
/** Object that controls and keeps state for a touch screen. */
|
||||
|
||||
class TouchScreen {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new Touch Screen object
|
||||
*
|
||||
* @param xp X+ pin. Must be an analog pin
|
||||
* @param yp Y+ pin. Must be an analog pin
|
||||
* @param xm X- pin. Can be a digital pin
|
||||
* @param ym Y- pin. Can be a digital pin
|
||||
* @param rx The resistance in ohms between X+ and X- to calibrate pressure
|
||||
* sensing
|
||||
*/
|
||||
TouchScreen(uint8_t xp, uint8_t yp, uint8_t xm, uint8_t ym, uint16_t rx);
|
||||
|
||||
/**
|
||||
* @brief **NOT IMPLEMENTED** Test if the screen has been touched
|
||||
*
|
||||
* @return true : touch detected false: no touch detected
|
||||
*/
|
||||
bool isTouching(void);
|
||||
uint16_t pressure(void);
|
||||
int readTouchY();
|
||||
int readTouchX();
|
||||
TSPoint getPoint();
|
||||
int16_t pressureThreshhold; ///< Pressure threshold for `isTouching`
|
||||
|
||||
private:
|
||||
uint8_t _yp, _ym, _xm, _xp;
|
||||
uint16_t _rxplate;
|
||||
|
||||
#if defined(USE_FAST_PINIO)
|
||||
volatile RwReg *xp_port, *yp_port, *xm_port, *ym_port;
|
||||
RwReg xp_pin, xm_pin, yp_pin, ym_pin;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
127
libraries/Adafruit_TouchScreen/code-of-conduct.md
Normal file
127
libraries/Adafruit_TouchScreen/code-of-conduct.md
Normal file
@@ -0,0 +1,127 @@
|
||||
# Adafruit Community Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and leaders pledge to making participation in our project and
|
||||
our community a harassment-free experience for everyone, regardless of age, body
|
||||
size, disability, ethnicity, gender identity and expression, level or type of
|
||||
experience, education, socio-economic status, nationality, personal appearance,
|
||||
race, religion, or sexual identity and orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
We are committed to providing a friendly, safe and welcoming environment for
|
||||
all.
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment
|
||||
include:
|
||||
|
||||
* Be kind and courteous to others
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Collaborating with other community members
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and sexual attention or advances
|
||||
* The use of inappropriate images, including in a community member's avatar
|
||||
* The use of inappropriate language, including in a community member's nickname
|
||||
* Any spamming, flaming, baiting or other attention-stealing behavior
|
||||
* Excessive or unwelcome helping; answering outside the scope of the question
|
||||
asked
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic
|
||||
address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate
|
||||
|
||||
The goal of the standards and moderation guidelines outlined here is to build
|
||||
and maintain a respectful community. We ask that you don’t just aim to be
|
||||
"technically unimpeachable", but rather try to be your best self.
|
||||
|
||||
We value many things beyond technical expertise, including collaboration and
|
||||
supporting others within our community. Providing a positive experience for
|
||||
other community members can have a much more significant impact than simply
|
||||
providing the correct answer.
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project leaders are responsible for clarifying the standards of acceptable
|
||||
behavior and are expected to take appropriate and fair corrective action in
|
||||
response to any instances of unacceptable behavior.
|
||||
|
||||
Project leaders have the right and responsibility to remove, edit, or
|
||||
reject messages, comments, commits, code, issues, and other contributions
|
||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||
permanently any community member for other behaviors that they deem
|
||||
inappropriate, threatening, offensive, or harmful.
|
||||
|
||||
## Moderation
|
||||
|
||||
Instances of behaviors that violate the Adafruit Community Code of Conduct
|
||||
may be reported by any member of the community. Community members are
|
||||
encouraged to report these situations, including situations they witness
|
||||
involving other community members.
|
||||
|
||||
You may report in the following ways:
|
||||
|
||||
In any situation, you may send an email to <support@adafruit.com>.
|
||||
|
||||
On the Adafruit Discord, you may send an open message from any channel
|
||||
to all Community Helpers by tagging @community helpers. You may also send an
|
||||
open message from any channel, or a direct message to @kattni#1507,
|
||||
@tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, or
|
||||
@Andon#8175.
|
||||
|
||||
Email and direct message reports will be kept confidential.
|
||||
|
||||
In situations on Discord where the issue is particularly egregious, possibly
|
||||
illegal, requires immediate action, or violates the Discord terms of service,
|
||||
you should also report the message directly to Discord.
|
||||
|
||||
These are the steps for upholding our community’s standards of conduct.
|
||||
|
||||
1. Any member of the community may report any situation that violates the
|
||||
Adafruit Community Code of Conduct. All reports will be reviewed and
|
||||
investigated.
|
||||
2. If the behavior is an egregious violation, the community member who
|
||||
committed the violation may be banned immediately, without warning.
|
||||
3. Otherwise, moderators will first respond to such behavior with a warning.
|
||||
4. Moderators follow a soft "three strikes" policy - the community member may
|
||||
be given another chance, if they are receptive to the warning and change their
|
||||
behavior.
|
||||
5. If the community member is unreceptive or unreasonable when warned by a
|
||||
moderator, or the warning goes unheeded, they may be banned for a first or
|
||||
second offense. Repeated offenses will result in the community member being
|
||||
banned.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct and the enforcement policies listed above apply to all
|
||||
Adafruit Community venues. This includes but is not limited to any community
|
||||
spaces (both public and private), the entire Adafruit Discord server, and
|
||||
Adafruit GitHub repositories. Examples of Adafruit Community spaces include
|
||||
but are not limited to meet-ups, audio chats on the Adafruit Discord, or
|
||||
interaction at a conference.
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces
|
||||
when an individual is representing the project or its community. As a community
|
||||
member, you are representing our community, and are expected to behave
|
||||
accordingly.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
||||
version 1.4, available at
|
||||
<https://www.contributor-covenant.org/version/1/4/code-of-conduct.html>,
|
||||
and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html).
|
||||
|
||||
For other projects adopting the Adafruit Community Code of
|
||||
Conduct, please contact the maintainers of those projects for enforcement.
|
||||
If you wish to use this code of conduct for your own project, consider
|
||||
explicitly mentioning your moderation policy or making a copy with your
|
||||
own moderation policy so as to avoid confusion.
|
||||
@@ -0,0 +1,35 @@
|
||||
// Touch screen library with X Y and Z (pressure) readings as well
|
||||
// as oversampling to avoid 'bouncing'
|
||||
// This demo code returns raw readings, public domain
|
||||
|
||||
#include <stdint.h>
|
||||
#include "TouchScreen.h"
|
||||
|
||||
#define YP A2 // must be an analog pin, use "An" notation!
|
||||
#define XM A3 // must be an analog pin, use "An" notation!
|
||||
#define YM 8 // can be a digital pin
|
||||
#define XP 9 // can be a digital pin
|
||||
|
||||
// For better pressure precision, we need to know the resistance
|
||||
// between X+ and X- Use any multimeter to read it
|
||||
// For the one we're using, its 300 ohms across the X plate
|
||||
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
|
||||
|
||||
void setup(void) {
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop(void) {
|
||||
// a point object holds x y and z coordinates
|
||||
TSPoint p = ts.getPoint();
|
||||
|
||||
// we have some minimum pressure we consider 'valid'
|
||||
// pressure of 0 means no pressing!
|
||||
if (p.z > ts.pressureThreshhold) {
|
||||
Serial.print("X = "); Serial.print(p.x);
|
||||
Serial.print("\tY = "); Serial.print(p.y);
|
||||
Serial.print("\tPressure = "); Serial.println(p.z);
|
||||
}
|
||||
|
||||
delay(100);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// Touch screen library with X Y and Z (pressure) readings as well
|
||||
// as oversampling to avoid 'bouncing'
|
||||
// This demo code returns raw readings, public domain
|
||||
|
||||
#include <stdint.h>
|
||||
#include "TouchScreen.h"
|
||||
|
||||
// These are the pins for the shield!
|
||||
#define YP A1 // must be an analog pin, use "An" notation!
|
||||
#define XM A2 // must be an analog pin, use "An" notation!
|
||||
#define YM 7 // can be a digital pin
|
||||
#define XP 6 // can be a digital pin
|
||||
|
||||
#define MINPRESSURE 10
|
||||
#define MAXPRESSURE 1000
|
||||
|
||||
// For better pressure precision, we need to know the resistance
|
||||
// between X+ and X- Use any multimeter to read it
|
||||
// For the one we're using, its 300 ohms across the X plate
|
||||
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
|
||||
|
||||
void setup(void) {
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop(void) {
|
||||
// a point object holds x y and z coordinates
|
||||
TSPoint p = ts.getPoint();
|
||||
|
||||
// we have some minimum pressure we consider 'valid'
|
||||
// pressure of 0 means no pressing!
|
||||
if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
|
||||
Serial.print("X = "); Serial.print(p.x);
|
||||
Serial.print("\tY = "); Serial.print(p.y);
|
||||
Serial.print("\tPressure = "); Serial.println(p.z);
|
||||
}
|
||||
}
|
||||
9
libraries/Adafruit_TouchScreen/library.properties
Normal file
9
libraries/Adafruit_TouchScreen/library.properties
Normal file
@@ -0,0 +1,9 @@
|
||||
name=Adafruit TouchScreen
|
||||
version=1.1.5
|
||||
author=Adafruit
|
||||
maintainer=Adafruit <info@adafruit.com>
|
||||
sentence=Adafruit TouchScreen display library.
|
||||
paragraph=Adafruit TouchScreen display library.
|
||||
category=Display
|
||||
url=https://github.com/adafruit/Adafruit_TouchScreen
|
||||
architectures=*
|
||||
26
libraries/Adafruit_TouchScreen/license.txt
Normal file
26
libraries/Adafruit_TouchScreen/license.txt
Normal file
@@ -0,0 +1,26 @@
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2019 Limor Fried for Adafruit Industries
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holders nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
Reference in New Issue
Block a user