- Samsung Galaxy Watch6 Classic - tekerd!
- Samsung Galaxy S25 - végre van kicsi!
- Elkészült és telepíthető az Android 16
- iPhone topik
- Honor 400 - és mégis mozog a kép
- Apple iPhone 16 Pro - rutinvizsga
- Google Pixel topik
- Android alkalmazások - szoftver kibeszélő topik
- Motorola Edge 50 Neo - az egyensúly gyengesége
- Térerő gondok, tapasztalatok
-
Mobilarena
Arduino hardverrel és szoftverrel foglakozó téma. Minden mikrovezérlő ami arduinoval programozható, és minden arduino program, board, és hardverrel kapcsolatos kérdések helye.
Új hozzászólás Aktív témák
-
olli
tag
[CODE// URTouch_ButtonTest
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
// web: http://www.RinkyDinkElectronics.com/
//
// This program is a quick demo of how create and use buttons.
//
// This program requires the UTFT library.
//
// It is assumed that the display module is connected to an
// appropriate shield or that you know how to change the pin
// numbers in the setup.
//#include <UTFT.h>
#include <URTouch.h>// Initialize display
// ------------------
// Set the pins to the correct ones for your development board
// -----------------------------------------------------------
// Standard Arduino Uno/2009 Shield : <display model>,19,18,17,16
// Standard Arduino Mega/Due shield : <display model>,38,39,40,41
// CTE TFT LCD/SD Shield for Arduino Due : <display model>,25,26,27,28
// Teensy 3.x TFT Test Board : <display model>,23,22, 3, 4
// ElecHouse TFT LCD/SD Shield for Arduino Due : <display model>,22,23,31,33
//
// Remember to change the model parameter to suit your display module!
UTFT myGLCD(CTE32,25,26,27,28);// Initialize touchscreen
// ----------------------
// Set the pins to the correct ones for your development board
// -----------------------------------------------------------
// Standard Arduino Uno/2009 Shield : 15,10,14, 9, 8
// Standard Arduino Mega/Due shield : 6, 5, 4, 3, 2
// CTE TFT LCD/SD Shield for Arduino Due : 6, 5, 32, 3, 2
// Teensy 3.x TFT Test Board : 26,31,27,28,29
// ElecHouse TFT LCD/SD Shield for Arduino Due : 25,26,27,29,30
//
URTouch myTouch( 6, 5, 32, 3, 2);// Declare which fonts we will be using
extern uint8_t BigFont[];int x, y;
char stCurrent[20]="";
int stCurrentLen=0;
char stLast[20]="";/*************************
** Custom functions **
*************************/void drawButtons()
{
// Draw the upper row of buttons
for (x=0; x<5; x++)
{
myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect (10+(x*60), 10, 60+(x*60), 60);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (10+(x*60), 10, 60+(x*60), 60);
myGLCD.printNumI(x+1, 27+(x*60), 27);
}
// Draw the center row of buttons
for (x=0; x<5; x++)
{
myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect (10+(x*60), 70, 60+(x*60), 120);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (10+(x*60), 70, 60+(x*60), 120);
if (x<4)
myGLCD.printNumI(x+6, 27+(x*60), 87);
}
myGLCD.print("0", 267, 87);
// Draw the lower row of buttons
myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect (10, 130, 150, 180);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (10, 130, 150, 180);
myGLCD.print("Clear", 40, 147);
myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect (160, 130, 300, 180);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (160, 130, 300, 180);
myGLCD.print("Enter", 190, 147);
myGLCD.setBackColor (0, 0, 0);
}void updateStr(int val)
{
if (stCurrentLen<20)
{
stCurrent[stCurrentLen]=val;
stCurrent[stCurrentLen+1]='\0';
stCurrentLen++;
myGLCD.setColor(0, 255, 0);
myGLCD.print(stCurrent, LEFT, 224);
}
else
{
myGLCD.setColor(255, 0, 0);
myGLCD.print("BUFFER FULL!", CENTER, 192);
delay(500);
myGLCD.print(" ", CENTER, 192);
delay(500);
myGLCD.print("BUFFER FULL!", CENTER, 192);
delay(500);
myGLCD.print(" ", CENTER, 192);
myGLCD.setColor(0, 255, 0);
}
}// Draw a red frame while a button is touched
void waitForIt(int x1, int y1, int x2, int y2)
{
myGLCD.setColor(255, 0, 0);
myGLCD.drawRoundRect (x1, y1, x2, y2);
while (myTouch.dataAvailable())
myTouch.read();
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (x1, y1, x2, y2);
}/*************************
** Required functions **
*************************/void setup()
{
// Initial setup
myGLCD.InitLCD();
myGLCD.clrScr();myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);myGLCD.setFont(BigFont);
myGLCD.setBackColor(0, 0, 255);
drawButtons();
}void loop()
{
while (true)
{
if (myTouch.dataAvailable())
{
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();if ((y>=10) && (y<=60)) // Upper row
{
if ((x>=10) && (x<=60)) // Button: 1
{
waitForIt(10, 10, 60, 60);
updateStr('1');
}
if ((x>=70) && (x<=120)) // Button: 2
{
waitForIt(70, 10, 120, 60);
updateStr('2');
}
if ((x>=130) && (x<=180)) // Button: 3
{
waitForIt(130, 10, 180, 60);
updateStr('3');
}
if ((x>=190) && (x<=240)) // Button: 4
{
waitForIt(190, 10, 240, 60);
updateStr('4');
}
if ((x>=250) && (x<=300)) // Button: 5
{
waitForIt(250, 10, 300, 60);
updateStr('5');
}
}if ((y>=70) && (y<=120)) // Center row
{
if ((x>=10) && (x<=60)) // Button: 6
{
waitForIt(10, 70, 60, 120);
updateStr('6');
}
if ((x>=70) && (x<=120)) // Button: 7
{
waitForIt(70, 70, 120, 120);
updateStr('7');
}
if ((x>=130) && (x<=180)) // Button: 8
{
waitForIt(130, 70, 180, 120);
updateStr('8');
}
if ((x>=190) && (x<=240)) // Button: 9
{
waitForIt(190, 70, 240, 120);
updateStr('9');
}
if ((x>=250) && (x<=300)) // Button: 0
{
waitForIt(250, 70, 300, 120);
updateStr('0');
}
}if ((y>=130) && (y<=180)) // Upper row
{
if ((x>=10) && (x<=150)) // Button: Clear
{
waitForIt(10, 130, 150, 180);
stCurrent[0]='\0';
stCurrentLen=0;
myGLCD.setColor(0, 0, 0);
myGLCD.fillRect(0, 224, 319, 239);
}
if ((x>=160) && (x<=300)) // Button: Enter
{
waitForIt(160, 130, 300, 180);
if (stCurrentLen>0)
{
for (x=0; x<stCurrentLen+1; x++)
{
stLast[x]=stCurrent[x];
}
stCurrent[0]='\0';
stCurrentLen=0;
myGLCD.setColor(0, 0, 0);
myGLCD.fillRect(0, 208, 319, 239);
myGLCD.setColor(0, 255, 0);
myGLCD.print(stLast, LEFT, 208);
}
else
{
myGLCD.setColor(255, 0, 0);
myGLCD.print("BUFFER EMPTY", CENTER, 192);
delay(500);
myGLCD.print(" ", CENTER, 192);
delay(500);
myGLCD.print("BUFFER EMPTY", CENTER, 192);
delay(500);
myGLCD.print(" ", CENTER, 192);
myGLCD.setColor(0, 255, 0);
}
}
}
}
}
}
]URTouch.h
/*
URTouch.h - Arduino/chipKit library support for Color TFT LCD Touch screens
Copyright (C)2016 Rinky-Dink Electronics, Henning Karlsen. All right reservedBasic functionality of this library are based on the demo-code provided by
ITead studio.You can find the latest version of the library at
http://www.RinkyDinkElectronics.com/This library is free software; you can redistribute it and/or
modify it under the terms of the CC BY-NC-SA 3.0 license.
Please see the included documents for further information.Commercial use of this library requires you to buy a license that
will allow commercial use. This includes using the library,
modified or not, as a tool to sell products.The license applies to all part of the library including the
examples and tools supplied with the library.
*/#ifndef URTouch_h
#define URTouch_h#define URTOUCH_VERSION 201
#if defined(__AVR__)
#include "Arduino.h"
#include "hardware/avr/HW_AVR_defines.h"
#elif defined(__PIC32MX__)
#include "WProgram.h"
#include "hardware/pic32/HW_PIC32_defines.h"
#elif defined(__arm__)
#include "Arduino.h"
#include "hardware/arm/HW_ARM_defines.h"
#endif#define PORTRAIT 0
#define LANDSCAPE 1#define PREC_LOW 1
#define PREC_MEDIUM 2
#define PREC_HI 3
#define PREC_EXTREME 4class URTouch
{
public:
int16_t TP_X ,TP_Y;URTouch(byte tclk, byte tcs, byte tdin, byte dout, byte irq);
void InitTouch(byte orientation = LANDSCAPE);
void read();
bool dataAvailable();
int16_t getX();
int16_t getY();
void setPrecision(byte precision);void calibrateRead();
private:
regtype *P_CLK, *P_CS, *P_DIN, *P_DOUT, *P_IRQ;
regsize B_CLK, B_CS, B_DIN, B_DOUT, B_IRQ;
byte T_CLK, T_CS, T_DIN, T_DOUT, T_IRQ;
long _default_orientation;
byte orient;
byte prec;
byte display_model;
long disp_x_size, disp_y_size, default_orientation;
long touch_x_left, touch_x_right, touch_y_top, touch_y_bottom;void touch_WriteData(byte data);
word touch_ReadData();#if defined(ENERGIA)
volatile uint32_t* portOutputRegister(int value);
volatile uint32_t* portInputRegister(int value);
#endif
};#endif
Új hozzászólás Aktív témák
- Milyen videókártyát?
- Témázgatunk, témázgatunk!? ... avagy mutasd az Android homescreened!
- Samsung Galaxy Watch6 Classic - tekerd!
- Formula-1
- Fejhallgató erősítő és DAC topik
- Samsung Galaxy S25 - végre van kicsi!
- Counter-Strike: Global Offensive (CS:GO) / Counter-Strike 2 (CS2)
- Kecskemét és környéke adok-veszek-beszélgetek
- AMD Ryzen 9 / 7 / 5 9***(X) "Zen 5" (AM5)
- Hamarosan megkezdődik a nubia 2,8K-s táblagépének szállítása
- További aktív témák...
- DELL G2724D / Samsung Odyssey G5 1440p 165hz árak leírásban.
- Asus RTX 4070 12GB DDR6X - DUAL-RTX4070-O12G-EVO-DLSS 3 Garancia
- Apple iPhone 14 128GB, Kártyafüggetlen, 1 Év Garanciával
- Apple iPhone 14 Pro Max 128GB, Kártyafüggetlen, 1 Év Garanciával
- Új Apple iPhone 16 Pro 128GB, Kártyafüggetlen, 3 Év Garanciával
- Felújított számítógépek/merevlemezek Számlával, garanciával! Ingyen Foxpost!
- ÁRGARANCIA!Épített KomPhone i5 10600KF 16/32/64GB RAM RTX 3060 12GB GAMER PC termékbeszámítással
- BESZÁMÍTÁS! Gigabyte H370 i5 9500 32GB DDR4 512GB SSD RTX 2060 Super 8GB ZALMAN S2 TG be quiet! 650W
- MikroTik CCR1009-7G-1C-1S+ Cloud Router
- BESZÁMÍTÁS! Apple MacBook Pro 14 M4 16GB RAM 512GB SSD garanciával hibátlan működéssel
Állásajánlatok
Cég: CAMERA-PRO Hungary Kft
Város: Budapest
Cég: PC Trade Systems Kft.
Város: Szeged