Arduino magic chinese music / ringtone gen
Moderators: adafruit_support_bill, adafruit

Arduino magic chinese music / ringtone gen

by CircuitBurner on Thu May 23, 2013 12:35 am

https://www.youtube.com/watch?v=j-dmlF7lcWI

This has to be the silliest and most randomly created thing ive ever built. lol
The mongolian translator speaking arduino device is possibly a close second...
But I think its cool enough to be shared publicly.
Lady Ada might think this is neat, with all the chinese language and culture exposure
shes been working at.

sketch for arduino is below.

Uses TFT touch screen, an arduino, and small speaker running on pin 53 to ground.
alter code to reflect whatever speaker pin you want.

code-
Code: Select all | TOGGLE FULL SIZE
    // Made from parts of the 'piano' sketch
    // inspired by music technique taught to me in 5th grade by chinese music teacher at the time.
    // prototyped on Arduino mega 2650 R3, seeed studios TFT touch screen using Adafruit's TFT library, small 8 ohm speaker.
    // concept and code by: Russ Reed ~aka~ "CircuitBurner" ___________april, 2013.

         #include <stdint.h>
         #include <TouchScreen.h>
         #include <TFT.h>

         const int speaker=53;

         #define NOTE_FS3 185
         #define NOTE_GS3 208
         #define NOTE_AS3 233
         #define NOTE_CS4 277
         #define NOTE_DS4 311
         #define NOTE_FS4 370
         #define NOTE_GS4 415
         #define NOTE_AS4 466
         #define NOTE_CS5 554
         #define NOTE_DS5 622
         #define NOTE_FS5 740
         #define NOTE_GS5 831
         #define NOTE_AS5 932
         #define NOTE_CS6 1109
       
      static unsigned int TS_MINX, TS_MAXX, TS_MINY, TS_MAXY;
         static unsigned int MapX1, MapX2, MapY1, MapY2;
         TouchScreen ts = TouchScreen(17, A2, A1, 14, 300);
       
       int duration=130;
         int wait=150;
     
       void setup()
        {
             Tft.init();
            initTouchScreenParameters();
          {
            for (int i=0; i<21; i++) {
            Tft.fillRectangle(0,i*16,240,15,YELLOW);
            }
            Tft.fillRectangle(0,11,300,22,BRIGHT_RED);
            Tft.fillRectangle(0,43,300,22,GREEN);
            Tft.fillRectangle(0,59,300,22,RED);
            Tft.fillRectangle(0,75,300,22,BLACK);
            Tft.fillRectangle(0,107,300,22,GREEN);
            Tft.fillRectangle(0,123,300,22,BLACK);
            Tft.fillRectangle(0,155,140,22,RED);
            Tft.fillRectangle(0,171,300,22,BLACK);
            Tft.fillRectangle(0,219,140,22,BLUE);
            Tft.fillRectangle(0,235,300,22,BLACK);
            Tft.fillRectangle(0,267,140,22,GRAY2);
            Tft.fillRectangle(0,283,300,22,BLACK);
            Tft.fillRectangle(0,299,140,22,CYAN);
          {
            Tft.drawString("~China ",60,20,1,BLACK);
            Tft.drawString("~China ",61,21,1,WHITE);
            Tft.drawString("  Flats~",106,20,1,BLACK);
            Tft.drawString("  Flats~",107,21,1,WHITE);
            Tft.drawString("YouXian",15,227,2,CYAN);
            Tft.drawString("YouXian",16,228,2,BLACK);
            Tft.drawString("priority",35,247,1,RED);
            Tft.drawString("NanDiYin (Bass)",12,308,1,BLUE);
            Tft.drawString("NanDiYin (Bass)",13,308,1,BLACK);
            Tft.drawString("ronghe      1",23,47,1,BLUE);
            Tft.drawString("ronghe      1",24,48,1,CYAN);
            Tft.drawString("ronghe      2",23,110,1,BLUE);
            Tft.drawString("ronghe      2",24,111,1,CYAN);
         }
           Tft.drawRectangle(1,150,138,170,BLUE);
           Tft.drawRectangle(2,151,136,171,BLACK);
           Tft.drawRectangle(2,149,137,169,RED);
         }
         }
         void loop()
         {
          Point p = ts.getPoint();
          if (p.z > ts.pressureThreshhold) {
          p.x = map(p.x, TS_MINX, TS_MAXX, MapX1, MapX2);
          p.y = map(p.y, TS_MINY, TS_MAXY, MapY1, MapY2);
         {
                    if (p.y>=1 && p.y<=42) tone(speaker,NOTE_CS6, duration);     
                    if (p.y>=43 && p.y<=58) tone(speaker,NOTE_AS5, duration);           
                    if (p.y>=59 && p.y<=74) tone(speaker,NOTE_GS5, duration);           
                    if (p.y>=75 && p.y<=93) tone(speaker,NOTE_FS5, duration);
                    if (p.y>=94 && p.y<=117) tone(speaker,NOTE_DS5, duration);           
                    if (p.y>=118 && p.y<=142) tone(speaker,NOTE_CS5, duration);         
                    if (p.y>=143 && p.y<=173) tone(speaker,NOTE_AS4, duration);       
                    if (p.y>=174 && p.y<=188) tone(speaker,NOTE_FS4, duration);       
                    if (p.y>=189 && p.y<=220) tone(speaker,NOTE_DS4, duration);         
                    if (p.y>=221 && p.y<=245) tone(speaker,NOTE_CS4, duration);         
                    if (p.y>=246 && p.y<=277) tone(speaker,NOTE_AS3, duration);           
                    if (p.y>=278 && p.y<=293) tone(speaker,NOTE_GS3, duration);
                    if (p.y>=294 && p.y<=340) tone(speaker,NOTE_FS3, duration);
                }
               {
                }
                wait=duration*1;
                delay(wait);
                noTone(speaker);
            }
            }
               void initTouchScreenParameters()
           {
               if(Tft.IC_CODE == 0x5408)
           {
               #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
               ts = TouchScreen(54, A1, A2, 57, 300);
         #else
               ts = TouchScreen(14, A1, A2, 17, 300);
         #endif
               TS_MINX = 120;
               TS_MAXX = 910;
               TS_MINY = 120;
               TS_MAXY = 950;
               MapX1 = 239;
               MapX2 = 0;
               MapY1 = 0;
               MapY2 = 319;
            }
            else
            {
         #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
              ts = TouchScreen(57, A2, A1, 54, 300);
         #else
                ts = TouchScreen(17, A2, A1, 14, 300);
         #endif
                TS_MINX = 140;
                TS_MAXX = 900;
                TS_MINY = 120;
                TS_MAXY = 940;
                MapX1 = 239;
                MapX2 = 0;
                MapY1 = 319;
                MapY2 = 0;
            }
            }
AMSAT terrestrial loc - (grid square) EM-12

wings are for fairies, and runways are for fashion models!
User avatar
CircuitBurner
 
Posts: 21
Joined: Mon Apr 15, 2013 2:18 am
Location: grand prairie, texas

Re: Arduino magic chinese music / ringtone gen

by adafruit_support_bill on Thu May 23, 2013 6:30 am

This has to be the silliest and most randomly created thing ive ever built

Those are always the best ones :D
Thanks for posting.
User avatar
adafruit_support_bill
 
Posts: 30847
Joined: Sat Feb 07, 2009 10:11 am

Re: Arduino magic chinese music / ringtone gen

by CircuitBurner on Thu May 23, 2013 2:51 pm

Roger that!
AMSAT terrestrial loc - (grid square) EM-12

wings are for fairies, and runways are for fashion models!
User avatar
CircuitBurner
 
Posts: 21
Joined: Mon Apr 15, 2013 2:18 am
Location: grand prairie, texas