Prototyping/2019-10-16: Difference between revisions

From XPUB & Lens-Based wiki
No edit summary
No edit summary
Line 18: Line 18:


https://upload.wikimedia.org/wikipedia/commons/a/ad/Piano_key_frequencies.png
https://upload.wikimedia.org/wikipedia/commons/a/ad/Piano_key_frequencies.png
== Simple Loop ==
<source lang="c">
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("hello");
 
  int counter = 0;
  Serial.print("YOUR Kounter is now ");
  Serial.println(counter);
 
  while (counter < 10) {
   
    // 3 variations on adding one to a variable
    // (only one)
    //counter = counter + 1;
    //counter+=1;
    //counter++;
    //++counter;
   
    Serial.println("tone 330, 10");
    tone(11, 330, 10);
   
    Serial.println("tone 440");
    tone(11, 440, 50);
    delay(1000);
    Serial.println("tone 220");
    tone(11, 220, 50);
    delay(1000);
    counter = counter + 1;
    Serial.println(counter);
  }
}
void loop() {
  // put your main code here, to run repeatedly:
}
</source>


== Play a scale ==
== Play a scale ==

Revision as of 14:19, 16 October 2019

Starting with a very simple program...

void setup() {
  tone(11, 220, 60);
  delay(100);
  tone(11, 440, 60);
  delay(100);
  tone(11, 880, 60);
  delay(1000);
}

void loop() {
}

How do frequencies relate to tones... See Piano key frequencies

Piano_key_frequencies.png

Simple Loop

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("hello");
  
  int counter = 0;
  Serial.print("YOUR Kounter is now ");
  Serial.println(counter);
  
  while (counter < 10) {
    
    // 3 variations on adding one to a variable
    // (only one)
    //counter = counter + 1;
    //counter+=1;
    //counter++;
    //++counter;
    
    Serial.println("tone 330, 10");
    tone(11, 330, 10);
    
    Serial.println("tone 440");
    tone(11, 440, 50);
    delay(1000);
    Serial.println("tone 220");
    tone(11, 220, 50);
    delay(1000);

    counter = counter + 1;
    Serial.println(counter);
  }
}

void loop() {
  // put your main code here, to run repeatedly:

}


Play a scale

Play with NOTE NAMES

Play a pattern