Home / Wiki / Blog / Project
Ode to Joy (rhythm) + LED show

Description: It will play a song (Ode to Joy), and there are 7 leds display cording to the rhythm, believe you'll like it.


Here we go:



Code:


[code]
/*
 * define a1 to b5 and  assign the frequency value
 */
int a1=523;   //alto Do
int a2=587;   //alto Re
int a3=659;   //alto Mi
int a4=698;   //alto Fa
int a5=784;   //alto So
int a6=880;   //alto La
int a7=988;   //alto Xi
int b5=392;   //bass So    
int PWMPin=9;
/*
 * we will support you a sheet which contains all of the frequency belong to notes in every tone.  
 */
void setup() {
  // put your setup code here, to run once:
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(PWMPin, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  /*
   * the following code tone(8, a3) means output pin 8, frequcy is a3
   * delay(375) means delay the frequcey for 375ms, all of the code you can modifate
   * the numbered musical notation of ODe to Joy:
   * 3345|5432|1123|3·22-|
   * 3345|5432|1123|2·11-|
   * 2231|23431|23432|125-|
   * 3345|5432|1123|2·11-|
   */

  tone(8, a3);digitalWrite(3, HIGH); delay(375);digitalWrite(3, LOW); tone(8, a3);digitalWrite(3, HIGH); delay(375);digitalWrite(3, LOW); tone(8, a4);digitalWrite(4, HIGH); delay(375);digitalWrite(4, LOW); tone(8, a5);digitalWrite(5, HIGH); delay(375);digitalWrite(5, LOW);
  tone(8, a5);digitalWrite(5, HIGH); delay(375);digitalWrite(5, LOW); tone(8, a4);digitalWrite(4, HIGH);delay(375);digitalWrite(4, LOW); tone(8, a3);digitalWrite(3, HIGH); delay(375);digitalWrite(3, LOW); tone(8, a2);digitalWrite(2, HIGH); delay(375);digitalWrite(2, LOW);
  tone(8, a1);digitalWrite(1, HIGH); delay(375);digitalWrite(1, LOW); tone(8, a1);digitalWrite(1, HIGH); delay(375);digitalWrite(1, LOW); tone(8, a2);digitalWrite(2, HIGH); delay(375);digitalWrite(2, LOW); tone(8, a3);digitalWrite(3, HIGH); delay(375); digitalWrite(3, LOW);
  tone(8, a3);digitalWrite(3, HIGH); delay(562);digitalWrite(3, LOW); tone(8, a2);digitalWrite(2, HIGH); delay(187.5);digitalWrite(2, LOW); tone(8, a2);digitalWrite(2, HIGH); delay(375);digitalWrite(2, LOW); noTone(8); delay(100); tone(8, a2);digitalWrite(2, HIGH); delay(375);digitalWrite(2, LOW);

  tone(8, a3);digitalWrite(3, HIGH); delay(375);digitalWrite(3, LOW); tone(8, a3);digitalWrite(3, HIGH); delay(375);digitalWrite(3, LOW); tone(8, a4);digitalWrite(4, HIGH); delay(375);digitalWrite(4, LOW); tone(8, a5);digitalWrite(5, HIGH); delay(375);digitalWrite(5, LOW);
  tone(8, a5);digitalWrite(5, HIGH); delay(375);digitalWrite(5, LOW); tone(8, a4);digitalWrite(4, HIGH); delay(375);digitalWrite(4, LOW); tone(8, a3);digitalWrite(3, HIGH); delay(375);digitalWrite(3, LOW); tone(8, a2);digitalWrite(2, HIGH); delay(375);digitalWrite(2, LOW);
  tone(8, a1);digitalWrite(1, HIGH); delay(375);digitalWrite(1, LOW); tone(8, a1);digitalWrite(1, HIGH); delay(375);digitalWrite(1, LOW); tone(8, a2);digitalWrite(2, HIGH); delay(375);digitalWrite(2, LOW); tone(8, a3);digitalWrite(3, HIGH); delay(375);digitalWrite(3, LOW);
  tone(8, a2);digitalWrite(2, HIGH); delay(562);digitalWrite(2, LOW); tone(8, a1);digitalWrite(1, HIGH); delay(187.5);digitalWrite(1, LOW); tone(8, a1);digitalWrite(1, HIGH); delay(375);digitalWrite(1, LOW); noTone(8); delay(100); tone(8, a1);digitalWrite(1, HIGH); delay(375);digitalWrite(1, LOW);

  tone(8, a2);digitalWrite(2, HIGH); delay(375);digitalWrite(2, LOW); tone(8, a2);digitalWrite(2, HIGH); delay(375);digitalWrite(2, LOW); tone(8, a3);digitalWrite(3, HIGH); delay(375);digitalWrite(3, LOW); tone(8, a1);digitalWrite(1, HIGH); delay(375);digitalWrite(1, LOW);
  tone(8, a2);digitalWrite(2, HIGH); delay(375);digitalWrite(2, LOW); tone(8, a3);digitalWrite(3, HIGH); delay(187.5);digitalWrite(3, LOW); tone(8, a4);digitalWrite(4, HIGH); delay(187.5);digitalWrite(4, LOW); tone(8, a3);digitalWrite(3, HIGH); delay(375);digitalWrite(3, LOW); tone(8, a1);digitalWrite(1, HIGH); delay(375);digitalWrite(1, LOW);
  tone(8, a2);digitalWrite(2, HIGH); delay(375);digitalWrite(2, LOW); tone(8, a3);digitalWrite(3, HIGH); delay(187.5);digitalWrite(3, LOW); tone(8, a4);digitalWrite(4, HIGH); delay(187.5);digitalWrite(4, LOW); tone(8, a3);digitalWrite(3, HIGH); delay(375);digitalWrite(3, LOW); tone(8, a2);digitalWrite(2, HIGH); delay(375);digitalWrite(2, LOW);
  tone(8, a1);digitalWrite(1, HIGH); delay(562);digitalWrite(1, LOW); tone(8, a2);digitalWrite(2, HIGH); delay(62.5);digitalWrite(2, LOW); tone(8, b5);digitalWrite(5, HIGH); delay(375);digitalWrite(5, LOW); noTone(8); delay(100); tone(8, b5);digitalWrite(5, HIGH); delay(375); digitalWrite(5, LOW);  

  tone(8, a3);digitalWrite(3, HIGH); delay(375);digitalWrite(3, LOW); tone(8, a3);digitalWrite(3, HIGH); delay(375);digitalWrite(3, LOW); tone(8, a4);digitalWrite(4, HIGH); delay(375);digitalWrite(4, LOW); tone(8, a5);digitalWrite(5, HIGH); delay(375);digitalWrite(5, LOW);
  tone(8, a5);digitalWrite(5, HIGH); delay(375);digitalWrite(5, LOW); tone(8, a4);digitalWrite(4, HIGH); delay(375);digitalWrite(4, LOW); tone(8, a3);digitalWrite(3, HIGH); delay(375);digitalWrite(3, LOW); tone(8, a2);digitalWrite(2, HIGH); delay(375); digitalWrite(2, LOW);
  tone(8, a1);digitalWrite(1, HIGH); delay(375);digitalWrite(1, LOW); tone(8, a1);digitalWrite(1, HIGH); delay(375);digitalWrite(1, LOW); tone(8, a2);digitalWrite(2, HIGH); delay(375);digitalWrite(2, LOW); tone(8, a3);digitalWrite(3, HIGH); delay(375); digitalWrite(3, LOW);
  tone(8, a2);digitalWrite(2, HIGH); delay(562);digitalWrite(2, LOW); tone(8, a1);digitalWrite(1, HIGH); delay(187.5);digitalWrite(1, LOW); tone(8, a1);digitalWrite(1, HIGH); delay(375);digitalWrite(1, LOW); noTone(8); delay(100); tone(8, a1);digitalWrite(1, HIGH); delay(375);digitalWrite(1, LOW);
}
[/code]


Here's the display on YouTube:


https://www.youtube.com/watch?v=X5BA3rTyATg


Designed by: Davy


Warning: Unknown: The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in Unknown on line 0 Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct () in Unknown on line 0