PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 satır
2.7KB

  1. /***************************************************
  2. This is an example for the Adafruit STMPE610 Resistive
  3. touch screen controller breakout
  4. ----> http://www.adafruit.com/products/1571
  5. Check out the links above for our tutorials and wiring diagrams
  6. These breakouts use SPI or I2C to communicate
  7. Adafruit invests time and resources providing this open source code,
  8. please support Adafruit and open-source hardware by purchasing
  9. products from Adafruit!
  10. Written by Limor Fried/Ladyada for Adafruit Industries.
  11. MIT license, all text above must be included in any redistribution
  12. ****************************************************/
  13. #include <SPI.h>
  14. #include <Wire.h>
  15. #include "Adafruit_STMPE610.h"
  16. // Pick one of three wiring options below!
  17. // Option #1 - uses I2C, connect to hardware I2C port only!
  18. // SCL to I2C clock (#A5 on Uno) and SDA to I2C data (#A4 on Uno)
  19. // tie MODE to GND and POWER CYCLE (there is no reset pin)
  20. Adafruit_STMPE610 touch = Adafruit_STMPE610();
  21. // Option #2 - use hardware SPI, connect to hardware SPI port only!
  22. // SDI to MOSI, SDO to MISO, and SCL to SPI CLOCK
  23. // on Arduino Uno, that's 11, 12 and 13 respectively
  24. // Then pick a CS pin, any pin is OK but we suggest #10 on an Uno
  25. // tie MODE to 3.3V and POWER CYCLE the STMPE610 (there is no reset pin)
  26. //Adafruit_STMPE610 touch = Adafruit_STMPE610(STMPE_CS);
  27. // Option #3 - use software SPI, connect to *any* 4 I/O pins!
  28. // define the following pins to whatever 4 you want and wire up!
  29. // Tie MODE to 3.3V and POWER CYCLE the STMPE610 (there is no reset pin)
  30. // Adafruit_STMPE610 touch = Adafruit_STMPE610(STMPE_CS, STMPE_SDI, STMPE_SDO, STMPE_SCK);
  31. /******************/
  32. void setup() {
  33. Serial.begin(9600);
  34. Serial.println("Adafruit STMPE610 example");
  35. Serial.flush();
  36. // if using hardware SPI on an Uno #10 must be an output, remove line
  37. // if using software SPI or I2C
  38. pinMode(10, OUTPUT);
  39. // If using I2C you can select the I2C address (there are two options) by calling
  40. // touch.begin(0x41), the default, or touch.begin(0x44) if A0 is tied to 3.3V
  41. // If no address is passed, 0x41 is used
  42. if (! touch.begin()) {
  43. Serial.println("STMPE not found!");
  44. while(1);
  45. }
  46. Serial.println("Waiting for touch sense");
  47. }
  48. void loop() {
  49. uint16_t x, y;
  50. uint8_t z;
  51. if (touch.touched()) {
  52. // read x & y & z;
  53. while (! touch.bufferEmpty()) {
  54. Serial.print(touch.bufferSize());
  55. touch.readData(&x, &y, &z);
  56. Serial.print("->(");
  57. Serial.print(x); Serial.print(", ");
  58. Serial.print(y); Serial.print(", ");
  59. Serial.print(z);
  60. Serial.println(")");
  61. }
  62. touch.writeRegister8(STMPE_INT_STA, 0xFF); // reset all ints
  63. }
  64. delay(10);
  65. }