This project uses a 5.6" serial touch screen with arduino control board LY-F2 design, the main accessories are as follows.
Main accessories
1, STONE 5.6" serial touch screen and adapter board V1.2.
2, gift box speaker.
Design idea
Serial screen carries piano keys, returns different key values, serial port notifies arduino decoding, arduino development board uses instruction tone (), outputs the corresponding key tone.
GUI design
Connection diagram
Part of code
int inDelay = 0;
String inString = ""; // String buffer
int ipage = 2;
int notes[] = {262, 294, 330, 349, 389, 430, 449, 469, 489, 509}; // Pronunciation frequency array table!
void setup()
{
Serial.begin(9600); // Open serial communication function wait for serial port to open, baud rate preset.
while (!Serial) {
Needed for Leonardo only
Needed for Leonardo only } }
void loop()
{
int inChar;
// Read the information sent by the serial port:
if (Serial.available() > 0) { inChar = Serial.read(); }
/* Piano key out music!
if (inChar >= 0x60) { // 0x0060--0x0069 is the Piano key value!
if (inChar <= 0x69) {
tone(8, notes[inChar - 96]); // 0x60 is 96!
delay(360); // every key is pressed, the music output 0.36s!
noTone(8); // close output!
/* Too, Can write sampe:
Tone(8,notes[inChar - 96],360);
*/
}
}}