hi, I'm looking for some guidance on my Touch Buttons Project
I'm using ILI9341 display and stm32 bluepill board
I currently have a touch grid set up that prints 1-16 on screen
up button prints 1
select button prints 2
down button prints 3
the other buttons I don't need
what I want is up and down to cycle through 16 numbers (this i'm struggling with)
and the text; shimmer reverb, dwell, pitch, blend, to all change based on the 1-16 position
so position 2 would print; hall reverb, size, depth, reflection
and so on (this I can probably figure out when I have the above figured out)
load button will keep 1-16 position and info on screen,
if load is not pressed within 5 seconds while scrolling through the 16 presets the display is to default to the last loaded position
I also want 3 b100k potentiometers 0v - 3.3v displayed as 0 - 100 values (I have pin 2 from the pots connected to analog inputs, pin 1 to gnd, pin 3 to 3.3v
I've tried a few things in the code, commented out, that didn't quite work out
so just hoping for some advice for things to try or things to read up on
thank you
(I will also be sending high or low to 4 output pins based on the 1-16 position, they connect to a fv1 chip for loading the algorithms, I've done this previously using a rotary encoder so should be able to figure this part out)
my previous finished project;
/**
* XPT2046 touch screen buttons.
*
* It divides the touch screen into COLUMNS * LINES areas (4*2=8 buttons) and creates virtual buttons.
* if the touch screen area is pressed and prints on Serial Port 1 the X,Y coordinates.
*
* Copyright (c) 02 Dec 2015 by Vassilis Serasidis
* Home: http://www.serasidis.gr
* email: avrsite@yahoo.gr
*
* The sketch example has been created for using it with STM32Duino (http://www.stm32duino.com)
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "XPT2046_touch.h"
#include <SPI.h>
#include <Fonts/FreeMonoBoldOblique12pt7b.h>;
// For the Adafruit shield, these are the default.
#define TFT_DC PB9
#define TFT_CS PB8
#define CS_PIN PB6 // Chip Select pin
#define LINES 4
#define COLUMNS 3
//char sensorPrintout[4];
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
SPIClass mySPI(1); //Create an SPI instance on SPI1 port.
XPT2046_touch ts(CS_PIN, mySPI); // Chip Select pin, SPI port
uint16_t xy[2];
void setup() {
Serial.begin(9600);
Serial.println("-------------------------------------------------");
Serial.println("XPT2046 touch screen buttons");
Serial.println("Copyright (c) 02 Dec 2015 by Vassilis Serasidis");
Serial.println("Home: http://www.serasidis.gr");
Serial.println("-------------------------------------------------");
tft.begin();
ts.begin(); //Begin TouchScreen.
ts.setButtonsNumber(COLUMNS, LINES); //Divide the Touch screen area into 4 columns and 2 lines and make them act as buttons.
tft.fillScreen(ILI9341_BLACK);
tft.setRotation(0);
// tft.drawRoundRect(20, 20, 20, 20, 20, 20);
// tft.drawRoundRect(50, 50, 50, 50, 50, 50);
tft.fillRoundRect(170, 10, 78, 60, 8, 0xFC28);
tft.fillRoundRect(170, 90, 78, 60, 8, 0x968B);
tft.fillRoundRect(170, 170, 78, 60, 8, 0xCA00);
tft.setFont(&FreeMonoBoldOblique12pt7b);
tft.setCursor(25, 300);
// int color = 0xF800;
tft.setTextColor(ILI9341_YELLOW);
tft.setTextSize(1);
//tft.setTextWrap(true);
tft.print("Shimmer Reverb");
tft.setTextColor(ILI9341_PINK);
tft.setCursor(10, 30);
tft.print("Dwell 1");
tft.setCursor(10, 70);
tft.print("Pitch 2");
tft.setCursor(10, 110);
tft.print("Blend 3");
tft.setTextColor(ILI9341_BLACK);
tft.setCursor(175, 50);
tft.print("UP");
tft.setTextColor(ILI9341_BLACK);
tft.setCursor(175, 130);
tft.print("Load");
tft.setTextColor(ILI9341_BLACK);
tft.setCursor(175, 200);
tft.print("DOWN");
//tft.fillTriangle(63, 63, 20, 20, 106, 20, ILI9341_CYAN);
//tft.fillRoundRect;
// tft.setCursor(10, 10);
}
void loop() {
if(ts.read_XY(xy)){ //If the touch screen is preesed, read the X,Y coordinates and print them on Serial port.
uint8_t buttonNumber = ts.getButtonNumber();
if(buttonNumber > 0)
Serial.print("Button: ");
Serial.println(buttonNumber);
tft.fillRoundRect(-10, 180, 60, 30, 8, ILI9341_RED);
tft.setTextColor(ILI9341_GREEN);
tft.setCursor(10, 200);
tft.println(buttonNumber);
Serial.print("X: ");
Serial.println(xy[0]); //Print X value
Serial.print("Y: ");
Serial.println(xy[1]); //Print Y value
Serial.println();
//int yPosit;
// for(int y = 0; y < 87; y++){
// yPosit = 20 + y;
// tft.drawTriangle(63, 63, 20, yPosit, 106, yPosit, ILI9341_CYAN);
// tft.drawTriangle(63, 63, 20, yPosit, 106, yPosit, ILI9341_BLACK); }
delay(250);
// int sensorValue = analogRead(PA0);
// int voltage = sensorValue * (26 / 1023.0);
// if(sensorValue > 0)
// Serial.println(voltage);
// tft.setCursor(10, 70);
// tft.println(voltage);
// String sensorVal = String(analogRead(PA0));
// sensorVal.toCharArray(sensorPrintout, 4);
// tft.fillRoundRect(0, 10, 78, 30, 8, ILI9341_BLACK);
// delay(250);
//tft.println(sensorPrintout);
}
//delay(200);
}