Skip to content

Commit

Permalink
woo!
Browse files Browse the repository at this point in the history
  • Loading branch information
ladyada committed Oct 25, 2013
1 parent 92a46af commit 94bfd43
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Adafruit_STMPE610.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/***************************************************
This is a library for the Adafruit STMPE610 Resistive
touch screen controller breakout
----> http://www.adafruit.com/products/1571
Check out the links above for our tutorials and wiring diagrams
These breakouts use SPI or I2C to communicate
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
MIT license, all text above must be included in any redistribution
****************************************************/


#if ARDUINO >= 100
#include "Arduino.h"
#else
Expand All @@ -15,18 +32,21 @@
@brief Instantiates a new STMPE610 class
*/
/**************************************************************************/
// software SPI
Adafruit_STMPE610::Adafruit_STMPE610(uint8_t cspin, uint8_t mosipin, uint8_t misopin, uint8_t clkpin) {
_CS = cspin;
_MOSI = mosipin;
_MISO = misopin;
_CLK = clkpin;
}

// hardware SPI
Adafruit_STMPE610::Adafruit_STMPE610(uint8_t cspin) {
_CS = cspin;
_MOSI = _MISO = _CLK = -1;
}

// I2C
Adafruit_STMPE610::Adafruit_STMPE610() {
// use i2c
_CS = -1;
Expand Down
17 changes: 17 additions & 0 deletions Adafruit_STMPE610.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/***************************************************
This is a library for the Adafruit STMPE610 Resistive
touch screen controller breakout
----> http://www.adafruit.com/products/1571
Check out the links above for our tutorials and wiring diagrams
These breakouts use SPI or I2C to communicate
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
MIT license, all text above must be included in any redistribution
****************************************************/


#if ARDUINO >= 100
#include "Arduino.h"
#else
Expand Down
81 changes: 81 additions & 0 deletions examples/TouchTest/TouchTest.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/***************************************************
This is an example for the Adafruit STMPE610 Resistive
touch screen controller breakout
----> http://www.adafruit.com/products/1571
Check out the links above for our tutorials and wiring diagrams
These breakouts use SPI or I2C to communicate
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
MIT license, all text above must be included in any redistribution
****************************************************/

#include <SPI.h>
#include <Wire.h>

#include "Adafruit_STMPE610.h"

// Pick one of three wiring options below!

// Option #1 - uses I2C, connect to hardware I2C port only!
// SCL to I2C clock (#A5 on Uno) and SDA to I2C data (#A4 on Uno)
// tie MODE to GND and POWER CYCLE (there is no reset pin)
Adafruit_STMPE610 touch = Adafruit_STMPE610();

// Option #2 - use hardware SPI, connect to hardware SPI port only!
// SDI to MOSI, SDO to MISO, and SCL to SPI CLOCK
// on Arduino Uno, that's 11, 12 and 13 respectively
// Then pick a CS pin, any pin is OK but we suggest #10 on an Uno
// tie MODE to 3.3V and POWER CYCLE the STMPE610 (there is no reset pin)

//Adafruit_STMPE610 touch = Adafruit_STMPE610(STMPE_CS);

// Option #3 - use software SPI, connect to *any* 4 I/O pins!
// define the following pins to whatever 4 you want and wire up!
// Tie MODE to 3.3V and POWER CYCLE the STMPE610 (there is no reset pin)
// Adafruit_STMPE610 touch = Adafruit_STMPE610(STMPE_CS, STMPE_SDI, STMPE_SDO, STMPE_SCK);

/******************/

void setup() {
Serial.begin(9600);
Serial.println("Adafruit STMPE610 example");
Serial.flush();

// if using hardware SPI on an Uno #10 must be an output, remove line
// if using software SPI or I2C
pinMode(10, OUTPUT);

// If using I2C you can select the I2C address (there are two options) by calling
// touch.begin(0x41), the default, or touch.begin(0x44) if A0 is tied to 3.3V
// If no address is passed, 0x41 is used
if (! touch.begin()) {
Serial.println("STMPE not found!");
while(1);
}
Serial.println("Waiting for touch sense");
}

void loop() {
uint16_t x, y;
uint8_t z;
if (touch.touched()) {
// read x & y & z;
while (! touch.bufferEmpty()) {
Serial.print(touch.bufferSize());
touch.readData(&x, &y, &z);
Serial.print("->(");
Serial.print(x); Serial.print(", ");
Serial.print(y); Serial.print(", ");
Serial.print(z);
Serial.println(")");
}
touch.writeRegister8(STMPE_INT_STA, 0xFF); // reset all ints
}
delay(10);
}

0 comments on commit 94bfd43

Please sign in to comment.