Skip to content

Commit 8d1242c

Browse files
authored
Add files via upload
1 parent 3fa5859 commit 8d1242c

File tree

4 files changed

+306
-0
lines changed

4 files changed

+306
-0
lines changed

SD_Card_Files.zip

305 KB
Binary file not shown.

TouchScreen.cpp

+185
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
/*
2+
* TouchScreen.cpp
3+
*
4+
* Created on: 29.03.2020
5+
* Author: rom3
6+
*/
7+
8+
#include "Arduino.h"
9+
#include "TouchScreen.h"
10+
11+
#define NUMSAMPLES 3 //.kbv
12+
#if defined(__STM32F1__) || defined(ESP32) //Maple core
13+
#define ADC_ADJUST >>2
14+
#else
15+
#define ADC_ADJUST
16+
#endif
17+
18+
TSPoint_kbv::TSPoint_kbv(void) {
19+
x = y = z = 0;
20+
}
21+
22+
TSPoint_kbv::TSPoint_kbv(int16_t x0, int16_t y0, int16_t z0) {
23+
x = x0;
24+
y = y0;
25+
z = z0;
26+
}
27+
28+
bool TSPoint_kbv::operator==(TSPoint_kbv p1) {
29+
return ((p1.x == x) && (p1.y == y) && (p1.z == z));
30+
}
31+
32+
bool TSPoint_kbv::operator!=(TSPoint_kbv p1) {
33+
return ((p1.x != x) || (p1.y != y) || (p1.z != z));
34+
}
35+
36+
static void insert_sort(int array[], uint8_t size) {
37+
uint8_t j;
38+
int save;
39+
40+
for (int i = 1; i < size; i++) {
41+
save = array[i];
42+
for (j = i; j >= 1 && save < array[j - 1]; j--)
43+
array[j] = array[j - 1];
44+
array[j] = save;
45+
}
46+
}
47+
48+
TSPoint_kbv TouchScreen_kbv::getPoint(void) {
49+
int x, y, z;
50+
int samples[NUMSAMPLES];
51+
uint8_t i;
52+
53+
pinMode(_yp, INPUT);
54+
pinMode(_ym, INPUT);
55+
56+
digitalWrite(_yp, LOW);
57+
digitalWrite(_ym, LOW);
58+
59+
pinMode(_xp, OUTPUT);
60+
pinMode(_xm, OUTPUT);
61+
digitalWrite(_xp, HIGH);
62+
digitalWrite(_xm, LOW);
63+
64+
for (i = 0; i < NUMSAMPLES; i++) {
65+
samples[i] = analogRead(_yp) ADC_ADJUST;
66+
}
67+
insert_sort(samples, NUMSAMPLES);
68+
x = (1023 - samples[NUMSAMPLES / 2]); //choose median
69+
70+
pinMode(_xp, INPUT);
71+
pinMode(_xm, INPUT);
72+
digitalWrite(_xp, LOW);
73+
digitalWrite(_xm, LOW); //.kbv for Due
74+
75+
pinMode(_yp, OUTPUT);
76+
digitalWrite(_yp, HIGH);
77+
pinMode(_ym, OUTPUT);
78+
digitalWrite(_ym, LOW); //.kbv for Due
79+
80+
for (i = 0; i < NUMSAMPLES; i++) {
81+
samples[i] = analogRead(_xm) ADC_ADJUST;
82+
}
83+
84+
insert_sort(samples, NUMSAMPLES);
85+
86+
y = (1023 - samples[NUMSAMPLES / 2]);
87+
88+
// Set X+ to ground
89+
pinMode(_xp, OUTPUT);
90+
digitalWrite(_xp, LOW);
91+
92+
// Set Y- to VCC
93+
pinMode(_ym, OUTPUT); //.kbv
94+
digitalWrite(_ym, HIGH);
95+
96+
// Hi-Z X- and Y+
97+
digitalWrite(_xm, LOW); //.kbv
98+
pinMode(_xm, INPUT); //.kbv
99+
digitalWrite(_yp, LOW);
100+
pinMode(_yp, INPUT);
101+
102+
int z1 = analogRead(_xm) ADC_ADJUST;
103+
int z2 = analogRead(_yp) ADC_ADJUST;
104+
105+
z = (1023 - (z2 - z1));
106+
107+
pinMode(_yp, OUTPUT); //restore shared pins
108+
pinMode(_xm, OUTPUT);
109+
digitalWrite(_yp, HIGH); //because TFT control pins
110+
digitalWrite(_xm, HIGH);
111+
112+
return TSPoint_kbv(x, y, z); //XM, YP still in ANALOG mode
113+
}
114+
115+
TouchScreen_kbv::TouchScreen_kbv(uint8_t xp, uint8_t yp, uint8_t xm, uint8_t ym) {
116+
_yp = yp;
117+
_xm = xm;
118+
_ym = ym;
119+
_xp = xp;
120+
_rxplate = 0;
121+
pressureThreshhold = 10;
122+
}
123+
124+
125+
TouchScreen_kbv::TouchScreen_kbv(uint8_t xp, uint8_t yp, uint8_t xm, uint8_t ym,
126+
uint16_t rxplate) {
127+
_yp = yp;
128+
_xm = xm;
129+
_ym = ym;
130+
_xp = xp;
131+
_rxplate = rxplate;
132+
133+
pressureThreshhold = 10;
134+
}
135+
136+
int TouchScreen_kbv::readTouchX(void) {
137+
pinMode(_yp, INPUT);
138+
pinMode(_ym, INPUT);
139+
digitalWrite(_yp, LOW);
140+
digitalWrite(_ym, LOW);
141+
142+
pinMode(_xp, OUTPUT);
143+
digitalWrite(_xp, HIGH);
144+
pinMode(_xm, OUTPUT);
145+
digitalWrite(_xm, LOW);
146+
147+
return (1023 - (analogRead(_yp)) ADC_ADJUST);
148+
}
149+
150+
151+
int TouchScreen_kbv::readTouchY(void) {
152+
pinMode(_xp, INPUT);
153+
pinMode(_xm, INPUT);
154+
digitalWrite(_xp, LOW);
155+
digitalWrite(_xm, LOW);
156+
157+
pinMode(_yp, OUTPUT);
158+
digitalWrite(_yp, HIGH);
159+
pinMode(_ym, OUTPUT);
160+
digitalWrite(_ym, LOW);
161+
162+
return (1023 - (analogRead(_xm)) ADC_ADJUST);
163+
}
164+
165+
166+
uint16_t TouchScreen_kbv::pressure(void) {
167+
// Set X+ to ground
168+
pinMode(_xp, OUTPUT);
169+
digitalWrite(_xp, LOW);
170+
171+
// Set Y- to VCC
172+
pinMode(_ym, OUTPUT);
173+
digitalWrite(_ym, HIGH);
174+
175+
// Hi-Z X- and Y+
176+
digitalWrite(_xm, LOW);
177+
pinMode(_xm, INPUT);
178+
digitalWrite(_yp, LOW);
179+
pinMode(_yp, INPUT);
180+
181+
int z1 = analogRead(_xm) ADC_ADJUST;
182+
int z2 = analogRead(_yp) ADC_ADJUST;
183+
184+
return (1023 - (z2 - z1));
185+
}

TouchScreen.h

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* TouchScreen.h
3+
*
4+
* Created on: 29.03.2020
5+
* Author: rom3
6+
*/
7+
8+
#ifndef TOUCHSCREEN_H_
9+
#define TOUCHSCREEN_H_
10+
#include <stdint.h>
11+
12+
class TSPoint_kbv {
13+
public:
14+
TSPoint_kbv(void);
15+
TSPoint_kbv(int16_t x, int16_t y, int16_t z);
16+
17+
bool operator==(TSPoint_kbv);
18+
bool operator!=(TSPoint_kbv);
19+
20+
int16_t x, y, z;
21+
};
22+
23+
class TouchScreen_kbv {
24+
public:
25+
TouchScreen_kbv(uint8_t xp, uint8_t yp, uint8_t xm, uint8_t ym);
26+
TouchScreen_kbv(uint8_t xp, uint8_t yp, uint8_t xm, uint8_t ym, uint16_t rx);
27+
28+
uint16_t pressure(void);
29+
int readTouchY();
30+
int readTouchX();
31+
TSPoint_kbv getPoint();
32+
int16_t pressureThreshhold;
33+
34+
private:
35+
uint8_t _yp, _ym, _xm, _xp;
36+
uint16_t _rxplate;
37+
};
38+
39+
#endif

midi_player.ino

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
////////////////////////////////////////////
2+
// 3.5" TOUCH SCREEN GM Midi file player //
3+
// //
4+
// rom3 11.2020 //
5+
// //
6+
// //
7+
////////////////////////////////////////////
8+
#include "Arduino.h"
9+
#include "TouchScreen.h"
10+
11+
// include SPI, MP3 and SD libraries
12+
#include <SPI.h>
13+
#include <Adafruit_VS1053.h>
14+
#include <SD.h>
15+
16+
Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(52, 46, 48, 50, 10);
17+
18+
// *** display
19+
#include <Adafruit_GFX.h>
20+
#include <MCUFRIEND_kbv.h>
21+
MCUFRIEND_kbv tft;
22+
Adafruit_GFX_Button mybutton = Adafruit_GFX_Button();
23+
24+
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
25+
26+
// The files in the tune list should be located on the SD card
27+
// or an error will occur opening the file and the next in the
28+
// list will be opened (skips errors).
29+
char *tuneList[] =
30+
{
31+
"LOOPDEMO.MID", // simplest and shortest file
32+
"ELISE.MID",
33+
"TWINKLE.MID",
34+
"GANGNAM.MID",
35+
"FUGUEGM.MID",
36+
"POPCORN.MID",
37+
"AIR.MID",
38+
"PRDANCER.MID",
39+
"MINUET.MID",
40+
"FIRERAIN.MID",
41+
"MOZART.MID",
42+
"FERNANDO.MID",
43+
"SONATAC.MID",
44+
"SKYFALL.MID",
45+
"XMAS.MID",
46+
"GBROWN.MID",
47+
"PROWLER.MID",
48+
"IPANEMA.MID",
49+
"JZBUMBLE.MID",
50+
"SYMPH9.MID",
51+
"CHATCHOO.MID",
52+
"STRIPPER.MID"
53+
};
54+
void setup() {
55+
Serial.begin(9600);
56+
tft.begin(tft.readID());
57+
tft.setRotation(1);
58+
tft.setTextColor(TFT_WHITE, TFT_BLUE);
59+
tft.fillScreen(TFT_BLUE);
60+
// initialise the music player
61+
musicPlayer.begin();
62+
musicPlayer.sciWrite(VS1053_REG_WRAMADDR, VS1053_GPIO_DDR);
63+
musicPlayer.sciWrite(VS1053_REG_WRAM, 0x0003);
64+
musicPlayer.GPIO_digitalWrite(0x0000);
65+
musicPlayer.softReset();
66+
SD.begin(10, 11, 12, 13);
67+
68+
// Set volume for left, right channels. lower numbers == louder volume!
69+
musicPlayer.setVolume(10, 10);
70+
musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT);
71+
}
72+
73+
void loop() {
74+
for (uint8_t i = 0; i < ARRAY_SIZE(tuneList); i++)
75+
{
76+
Serial.println(tuneList[i]);
77+
musicPlayer.startPlayingFile(tuneList[i]);
78+
while (musicPlayer.playingMusic) {
79+
80+
}
81+
}
82+
}

0 commit comments

Comments
 (0)