Last active
August 29, 2015 14:07
-
-
Save sj82516/63753da1808c839253eb to your computer and use it in GitHub Desktop.
Arduino_digitalPiano
This file contains 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
//set up pin | |
const int buttonPin = 2; | |
const int hornPin = 3; | |
const int ohm=5; | |
//data | |
int music[5]={0,0,0,0,0}; | |
int point=0; | |
int sensor=0; | |
boolean buttonState=LOW; | |
long lastDebounceTime = 0; | |
long currentTime = 0; | |
long click1 = 50; | |
long click2 = 5000; | |
void setup(){ | |
Serial.begin(9600); | |
pinMode(buttonPin,INPUT); | |
pinMode(hornPin,OUTPUT); | |
} | |
void loop(){ | |
int reading=digitalRead(buttonPin); | |
if(reading ==HIGH && buttonState==LOW){ | |
lastDebounceTime = millis(); | |
buttonState2=reading; | |
buttonState=HIGH; | |
}else if(reading==LOW && buttonState==HIGH){ | |
currentTime=millis()-lastDebounceTime; | |
buttonState=LOW; | |
} | |
if(currentTime>click1 && currentTime<click2){ | |
int sensor = analogRead(ohm); | |
sensor = sensor/4; | |
analogWrite(hornPin,sensor); | |
delay(50); | |
music[point]=sensor; | |
point=(point%5)+1; | |
currentTime=0; | |
Serial.println("click1"); | |
}else if (currentTime>click2){ | |
for(int i=0;i<5;i++){ | |
analogWrite(hornPin,music[i]); | |
delay(1000); | |
} | |
currentTime=0; | |
Serial.println("click2"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment