Category:

Ardunio

Title:

RGB Led Piano with Ardunio Mega

Ardunio Mega ismore powerful microcontroller than UNO. Ardunio 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 Ardunio 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 Ardunio 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

  • Ardunio 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

Ardunio 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 buttonDokdurum = 0;
int buttonRedurum = 0;
int buttonMidurum = 0;
int buttonFadurum = 0;
int buttonSoldurum = 0;
int buttonLadurum = 0;
int buttonSidurum = 0;
int buttonDoidurum = 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() {


    buttonDokdurum = digitalRead(Dokbuton);
    buttonRedurum = digitalRead(Rebuton);
    buttonMidurum = digitalRead(Mibuton);
    buttonFadurum = digitalRead(Fabuton);
    buttonSoldurum = digitalRead(Solbuton);
    buttonLadurum = digitalRead(Labuton);
    buttonSidurum = digitalRead(Sibuton);
    buttonDoidurum = digitalRead(Doibuton);

    digitalWrite(buzzerpin,LOW);
      if (buttonDokdurum == 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 (buttonRedurum == 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 (buttonMidurum == 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 (buttonFadurum == 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 (buttonSoldurum == 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 (buttonLadurum == 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 (buttonSidurum == 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 (buttonDoidurum == HIGH) {
           tone(buzzerpin, doi, 100);
           analogWrite(DoiRed,255);  
           analogWrite(DoiGreen,0);
           analogWrite(DoiBlue,255);
       }
             else {
                      analogWrite(DoiRed,255);  
                      analogWrite(DoiGreen,255);
                      analogWrite(DoiBlue,255);
            }
 }

269 views
COMMENTS