Created
January 11, 2012 02:12
-
-
Save ssov/1592539 to your computer and use it in GitHub Desktop.
何かアレ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int speaker=11; | |
#define Do 523 | |
#define Re 587 | |
#define Mi 659 | |
#define Fa 698 | |
#define So 783 | |
#define Ra 880 | |
#define Si 987 | |
#define DoU 1046 | |
#define ReU 1174 | |
int m[9] = {Do, Re, Mi, Fa, So, Ra, Si, DoU, ReU}; | |
void sound(int tone_delay) { | |
digitalWrite(speaker, HIGH); | |
delayMicroseconds((float)1000000/tone_delay/2); | |
digitalWrite(speaker, LOW); | |
delayMicroseconds((float)1000000/tone_delay/2); | |
} | |
void setup() | |
{ | |
pinMode(speaker, OUTPUT); | |
int i; | |
for (i=2; i<=9; i++) { | |
pinMode(i, INPUT); | |
digitalWrite(i, HIGH); | |
} | |
} | |
void loop() | |
{ | |
int i; | |
for (i=2; i<=9; i++) { | |
if(digitalRead(i) == LOW) sound(m[i-2]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment