Changes

Jump to navigation Jump to search
no edit summary
Line 163: Line 163:  
In the main window, copy this code:  
 
In the main window, copy this code:  
   −
<code style="color: green;">codehere</code>
+
<code style="color: green;">
 +
 
 +
 
 +
 
 +
#include "pitches.h"
 +
#define TONE_PIN A2
 +
 
 +
//C major
 +
int notes[] = { NOTE_A3, NOTE_B3, NOTE_C4, NOTE_D4, NOTE_E4, NOTE_F4, NOTE_G4, NOTE_A4 };
 +
 
 +
//G major
 +
//int notes[] = { NOTE_A3, NOTE_B3, NOTE_C4, NOTE_D4, NOTE_E4, NOTE_FS4, NOTE_G4, NOTE_A4 };
 +
 
 +
//D major
 +
//int notes[] = { NOTE_A3, NOTE_B3, NOTE_CS4, NOTE_D4, NOTE_E4, NOTE_FS4, NOTE_G4, NOTE_A4 };
 +
 
 +
//A major
 +
//int notes[] = { NOTE_A3, NOTE_B3, NOTE_CS4, NOTE_D4, NOTE_E4, NOTE_FS4, NOTE_GS4, NOTE_A4 };
 +
 
 +
//E major
 +
//int notes[] = { NOTE_A3, NOTE_B3, NOTE_CS4, NOTE_DS4, NOTE_E4, NOTE_FS4, NOTE_GS4, NOTE_A4 };
 +
 
 +
//B major
 +
//int notes[] = { NOTE_AS3, NOTE_B3, NOTE_CS4, NOTE_DS4, NOTE_E4, NOTE_FS4, NOTE_GS4, NOTE_AS4 };
 +
 
 +
//A minor
 +
//int notes[] = { NOTE_GS3, NOTE_AS3, NOTE_C4, NOTE_CS4, NOTE_DS4, NOTE_F4, NOTE_G4, NOTE_GS4 };
 +
 
 +
//E minor
 +
//int notes[] = { NOTE_GS3, NOTE_AS3, NOTE_C4, NOTE_D4, NOTE_DS4, NOTE_F4, NOTE_G4, NOTE_GS4 };
 +
 
 +
//B minor
 +
//int notes[] = { NOTE_A3, NOTE_AS3, NOTE_C4, NOTE_D4, NOTE_DS4, NOTE_F4, NOTE_G4, NOTE_A4 };
 +
 
 +
 
 +
 
 +
int oldButton = 0;
 +
int newButton = 0;
 +
 
 +
void setup() {
 +
  // put your setup code here, to run once:
 +
 
 +
}
 +
 
 +
void loop() {
 +
  delay(10);
 +
 
 +
  newButton = readButtons();
 +
 
 +
  if(oldButton != newButton){
 +
    oldButton = newButton;
 +
 
 +
    if(newButton != 0){
 +
      tone(TONE_PIN, notes[newButton - 1]);
 +
    }else{
 +
      noTone(TONE_PIN);
 +
    }
 +
   
 +
  }
 +
 
 +
}
 +
 
 +
int readButtons() {
 +
  int button;
 +
  if        (digitalRead(2) == HIGH) { //button 1
 +
    button = 1;
 +
  } else if (digitalRead(3) == HIGH) { //button 2
 +
    button = 2;
 +
  } else if (digitalRead(4) == HIGH) { //button 3
 +
    button = 3;
 +
  } else if (digitalRead(5) == HIGH) { //button 4
 +
    button = 4;
 +
  } else if (digitalRead(6) == HIGH) { //button 5
 +
    button = 5;
 +
  } else if (digitalRead(7) == HIGH) { //button 6
 +
    button = 6;
 +
  } else if (digitalRead(8) == HIGH) { //button 7
 +
    button = 7;
 +
  } else if (digitalRead(9) == HIGH) { //button 8
 +
    button = 8;
 +
  } else {
 +
    button = 0;
 +
  }
 +
  return button;
 +
}
 +
 
 +
</code>
    
then, create a second tab, and name it ____
 
then, create a second tab, and name it ____
232

edits

Navigation menu