int fsrPin = A0;
int switchPin = D0;
int speakerPin = A4;
int melody[] = {1908,2551,2551,2273,2551,0,2024,1908};
int noteDurations[] = {4,8,8,4,4,4,4,4};
int fsrReading = 0;
int ledPin = D1;
int ledBrightness = 0;
void setup(){
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(switchPin, INPUT_PULLUP);
pinMode(speakerPin, OUTPUT);
Particle.variable("force", &fsrReading, INT);
}
void loop() {
int buttonState = digitalRead(switchPin);
if (buttonState == HIGH ){
fsrReading = analogRead(fsrPin);
ledBrightness = map(fsrReading, 0, 4095, 0, 255);
analogWrite(ledPin, ledBrightness);
delay(100);
}
if (ledBrightness > 100) {
for(int thisNote = 0; thisNote < 8 ; thisNote++){
int noteDuration = 1000/noteDurations[thisNote];
tone(speakerPin,melody[thisNote],noteDuration);
int pauseBetweenNote = noteDuration*1.30;
delay(pauseBetweenNote);
noTone(speakerPin);}
}
}
void playNotes()
{
for (int thisNote = 0; thisNote < 8; thisNote++) {
int noteDuration = 1000/noteDurations[thisNote];
tone(speakerPin, melody[thisNote],noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
noTone(speakerPin);
}
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .