PComp Week4

I designed a simple system using Force-Sensitive Resistor. I connected the FSR with the length of delay: if I press the FSR, the music will go quicker, or it will go as usual.

Here’s the video of my project:

Firstly, I imported the reference form (pitches.h). I tested for several times and found out the tones I wanted (do, re, me, fa, so, la, si, do), then i arranged them a singing pace.

If the value of analogRead changes, the length of delay will change as well, so the music will go faster.

Here’s my code:

#define speakerPin 9
#define forceSensor A5
#include “pitches.h”

int myNotes[] {523,587,659,698,784,880,988,1047};

void setup() {
// put your setup code here, to run once:
pinMode(A5,INPUT);
pinMode(9,OUTPUT);
tone(speakerPin, 2000, 5000);
Serial.begin(9600);

}

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

int forceSensor = analogRead(A5);
Serial.println(forceSensor);
delay(1023-forceSensor);

for (int i = 0; i<8; i=i+1){
tone(speakerPin, myNotes[i], 500);
delay(analogRead(forceSensor));

}

 

Leave a Reply

Your email address will not be published. Required fields are marked *