Home / Wiki / Blog / Project
Ode to Joy+ lightness

This is based on Catduino ( the same function as Arduino )


Descripe: it will play a song ( Ode to Joy ), the single LED will light and off cording to the tone.


Here we go:


[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 n1=36;  int n2=72;  int n3=108; int n4=144;  int n5=180;  int n6=216;  int n7=252;
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(8, OUTPUT);    //pin 8 was set as output pin
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-|
   */
 //  noTone;
   //analogWrite(PWMPin, 0);
 //delay(2000);
  tone(8, a3);analogWrite(PWMPin, n3); delay(375); tone(8, a3);analogWrite(PWMPin, n3); delay(375); tone(8, a4);analogWrite(PWMPin, n4); delay(375); tone(8, a5);analogWrite(PWMPin, n5); delay(375);
  tone(8, a5);analogWrite(PWMPin, n5); delay(375); tone(8, a4);analogWrite(PWMPin, n4); delay(375); tone(8, a3);analogWrite(PWMPin, n3); delay(375); tone(8, a2);analogWrite(PWMPin, n2); delay(375);
  tone(8, a1);analogWrite(PWMPin, n1); delay(375); tone(8, a1);analogWrite(PWMPin, n1); delay(375); tone(8, a2);analogWrite(PWMPin, n2); delay(375); tone(8, a3);analogWrite(PWMPin, n3); delay(375);
  tone(8, a3);analogWrite(PWMPin, n3); delay(562); tone(8, a2);analogWrite(PWMPin, n2); delay(187.5); tone(8, a2);analogWrite(PWMPin, n2); delay(375); noTone(8);analogWrite(PWMPin, 0); delay(100); tone(8, a2);analogWrite(PWMPin, n2); delay(375);

  tone(8, a3);analogWrite(PWMPin, n3); delay(375); tone(8, a3);analogWrite(PWMPin, n3); delay(375); tone(8, a4);analogWrite(PWMPin, n4); delay(375); tone(8, a5);analogWrite(PWMPin, n3); delay(375);
  tone(8, a5);analogWrite(PWMPin, n5); delay(375); tone(8, a4);analogWrite(PWMPin, n4); delay(375); tone(8, a3);analogWrite(PWMPin, n3); delay(375); tone(8, a2);analogWrite(PWMPin, n3); delay(375);
  tone(8, a1);analogWrite(PWMPin, n1); delay(375); tone(8, a1);analogWrite(PWMPin, n1); delay(375); tone(8, a2);analogWrite(PWMPin, n2); delay(375); tone(8, a3);analogWrite(PWMPin, n3); delay(375);
  tone(8, a2);analogWrite(PWMPin, n2); delay(562); tone(8, a1);analogWrite(PWMPin, n1); delay(187.5); tone(8, a1);analogWrite(PWMPin, n1); delay(375); noTone(8);analogWrite(PWMPin, 0); delay(100); tone(8, a1);analogWrite(PWMPin, n1); delay(375);

  tone(8, a2);analogWrite(PWMPin, n2); delay(375); tone(8, a2);analogWrite(PWMPin, n2); delay(375); tone(8, a3);analogWrite(PWMPin, n3); delay(375); tone(8, a1);analogWrite(PWMPin, n1); delay(375);
  tone(8, a2);analogWrite(PWMPin, n2); delay(375); tone(8, a3);analogWrite(PWMPin, n3); delay(187.5); tone(8, a4);analogWrite(PWMPin, n4); delay(187.5); tone(8, a3);analogWrite(PWMPin, n3); delay(375); tone(8, a1);analogWrite(PWMPin, n1); delay(375);
  tone(8, a2);analogWrite(PWMPin, n2); delay(375); tone(8, a3);analogWrite(PWMPin, n3); delay(187.5); tone(8, a4);analogWrite(PWMPin, n4); delay(187.5); tone(8, a3);analogWrite(PWMPin, n3); delay(375); tone(8, a2);analogWrite(PWMPin, n2); delay(375);
  tone(8, a1);analogWrite(PWMPin, n1); delay(562); tone(8, a2);analogWrite(PWMPin, n2); delay(62.5); tone(8, b5);analogWrite(PWMPin, n5); delay(375); noTone(8);analogWrite(PWMPin, 0); delay(100); tone(8, b5);analogWrite(PWMPin, n5); delay(375);   

  tone(8, a3);analogWrite(PWMPin, n3); delay(375); tone(8, a3);analogWrite(PWMPin, n3); delay(375); tone(8, a4);analogWrite(PWMPin, n4); delay(375); tone(8, a5);analogWrite(PWMPin, n5); delay(375);
  tone(8, a5);analogWrite(PWMPin, n5); delay(375); tone(8, a4);analogWrite(PWMPin, n4); delay(375); tone(8, a3);analogWrite(PWMPin, n3); delay(375); tone(8, a2);analogWrite(PWMPin, n2); delay(375);
  tone(8, a1);analogWrite(PWMPin, n1); delay(375); tone(8, a1);analogWrite(PWMPin, n1); delay(375); tone(8, a2);analogWrite(PWMPin, n2); delay(375); tone(8, a3);analogWrite(PWMPin, n3); delay(375);
  tone(8, a2);analogWrite(PWMPin, n2); delay(562); tone(8, a1);analogWrite(PWMPin, n1); delay(187.5); tone(8, a1);analogWrite(PWMPin, n1); delay(375); noTone(8);analogWrite(PWMPin, 0); delay(100); tone(8, a1);analogWrite(PWMPin, n1); delay(375);
}
[/code]


Designed by: Davy


Here's the display on YouTube:


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