Category:

Arduino

Title:

RGB Led Piano with Arduino Mega

Arduino Mega has more powerful microcontroller than UNO. arduino Mega is more suitable for complex projects due to more pin counts and faster data transfer. As can be seen in this example, reasons such as many connection requirements can be directed to arduino Mega. In this example, it is aimed to give note and light led according to the button pressed.

Rgb ledli piyano

In this project, it was aimed to give different colors from RGB leds at the beginning of each button. But due to the lack of pwm pins in arduino Mega, digital pins were used. Therefore, the desired color diversity could not be obtained. As shown in the above pictures, 1 Rgb led was used for each note. With this sample project, it was aimed to give visual and color to the notes.

Materials

  • arduino Mega (Clone)
  • 2 x big breadboard
  • 24x 220 Ohm Ressistors(For RGB Leds)
  • 8x 10K Ohm Ressistors (For Buttons)
  • 8x button (For  8 notes)
  • Jumper cables

Project Scheme

arduino Rgb ledli piyano şeması

Source Code:

#define dok  264
#define re   297
#define mi   330
#define fa   352
#define sol  396
#define la   440
#define si   495
#define doi  528// thin do.



#define Dokbuton 2
#define Rebuton 3
#define Mibuton 4
#define Fabuton 5
#define Solbuton 6
#define Labuton 7
#define Sibuton 8
#define Doibuton 9
#define buzzerpin 10

#define DokRed 22
#define DokGreen 23
#define DokBlue 24
#define ReRed 25
#define ReGreen 26
#define ReBlue 27
#define MiRed 28
#define MiGreen 29
#define MiBlue 30
#define FaRed 31
#define FaGreen 32
#define FaBlue 33
#define SolRed 34
#define SolGreen 35
#define SolBlue 36
#define LaRed 37
#define LaGreen 38
#define LaBlue 39
#define SiRed 40
#define SiGreen 41
#define SiBlue 42
#define DoiRed 43
#define DoiGreen 44
#define DoiBlue 45

int buttonDokSt = 0;
int buttonRedSt = 0;
int buttonMiSt = 0;
int buttonFaSt = 0;
int buttonSolSt = 0;
int buttonLaSt = 0;
int buttonSiSt = 0;
int buttonDoiSt = 0;

void setup() 
{ 


    pinMode(Dokbuton, INPUT);
    pinMode(Rebuton, INPUT);
    pinMode(Mibuton , INPUT);
    pinMode(Fabuton, INPUT);
    pinMode(Solbuton, INPUT);
    pinMode(Labuton, INPUT);
    pinMode(Sibuton , INPUT);
    pinMode(Doibuton, INPUT);
   
    pinMode(buzzerpin, OUTPUT);
    pinMode(DokRed, OUTPUT);
    pinMode(MiRed, OUTPUT);
    pinMode(FaRed, OUTPUT);
    pinMode(SolRed, OUTPUT);
    pinMode(LaRed, OUTPUT);
    pinMode(SiRed, OUTPUT);
    pinMode(DoiRed, OUTPUT);
    pinMode(DokGreen, OUTPUT);
    pinMode(MiGreen, OUTPUT);
    pinMode(FaGreen, OUTPUT);
    pinMode(SolGreen, OUTPUT);
    pinMode(LaGreen, OUTPUT);
    pinMode(SiGreen, OUTPUT);
    pinMode(DoiGreen, OUTPUT);
    pinMode(DokBlue, OUTPUT);
    pinMode(MiBlue, OUTPUT);
    pinMode(FaBlue, OUTPUT);
    pinMode(SolBlue, OUTPUT);
    pinMode(LaBlue, OUTPUT);
    pinMode(SiBlue, OUTPUT);
    pinMode(DoiBlue, OUTPUT);

 }
void loop() {


    buttonDokSt = digitalRead(Dokbuton);
    buttonRedSt = digitalRead(Rebuton);
    buttonMiSt = digitalRead(Mibuton);
    buttonFaSt = digitalRead(Fabuton);
    buttonSolSt = digitalRead(Solbuton);
    buttonLaSt = digitalRead(Labuton);
    buttonSiSt = digitalRead(Sibuton);
    buttonDoiSt = digitalRead(Doibuton);

    digitalWrite(buzzerpin,LOW);
      if (buttonDokSt == HIGH) {

           tone(buzzerpin, dok, 100); 
           analogWrite(DokRed,0); 
           analogWrite(DokGreen,255);
           analogWrite(DokBlue,255);
       }
              else {
                  analogWrite(DokRed,255);  
                  analogWrite(DokGreen,255);
                  analogWrite(DokBlue,255);        
            }


       if (buttonRedSt == HIGH) {

           tone(buzzerpin, re, 100);
           analogWrite(ReRed,255);  
           analogWrite(ReGreen,0);
           analogWrite(ReBlue,255);
       }
              else {
                  analogWrite(ReRed,255);  
                  analogWrite(ReGreen,255);
                  analogWrite(ReBlue,255);       
            }

       if (buttonMiSt == HIGH) {

           tone(buzzerpin, mi, 100);
           analogWrite(MiRed,255);  
           analogWrite(MiGreen,255);
           analogWrite(MiBlue,0);
       }
              else {
                   analogWrite(MiRed,255);  
                   analogWrite(MiGreen,255);
                   analogWrite(MiBlue,255);
            }
            
       if (buttonFaSt == HIGH) {

           tone(buzzerpin, fa, 100);
           analogWrite(FaRed,0);  
           analogWrite(FaGreen,255);
           analogWrite(FaBlue,255);
       }
               else {
                    analogWrite(FaRed,255);  
                    analogWrite(FaGreen,255);
                    analogWrite(FaBlue,255);
            }
            
       if (buttonSolSt == HIGH) {
           tone(buzzerpin, sol, 100);
           analogWrite(SolRed,255);  
           analogWrite(SolGreen,0);
           analogWrite(SolBlue,255);
       }
         else {
                     analogWrite(SolRed,255);  
                     analogWrite(SolGreen,255);
                     analogWrite(SolBlue,255);
            }
            
       if (buttonLaSt == HIGH) {
           tone(buzzerpin, la, 100);
           analogWrite(LaRed,255);  
           analogWrite(LaGreen,255);
           analogWrite(LaBlue,0);
       }
          else {
                      analogWrite(LaRed,255);  
                      analogWrite(LaGreen,255);
                      analogWrite(LaBlue,255);
            }

       if (buttonSiSt == HIGH) {
           tone(buzzerpin, si, 100);
           analogWrite(SiRed,0);  
           analogWrite(SiGreen,255);
           analogWrite(SiBlue,255);
       }
            else {
                      analogWrite(SiRed,255);  
                      analogWrite(SiGreen,255);
                      analogWrite(SiBlue,255);
            }
       if (buttonDoiSt == HIGH) {
           tone(buzzerpin, doi, 100);
           analogWrite(DoiRed,255);  
           analogWrite(DoiGreen,0);
           analogWrite(DoiBlue,255);
       }
             else {
                      analogWrite(DoiRed,255);  
                      analogWrite(DoiGreen,255);
                      analogWrite(DoiBlue,255);
            }
 }

390 views
COMMENTS