Project: ArduinoPhotosensitiveAlarmIII

Final improvement about PhotosensitiveAlarm.

  1. Add a press switch to give a short snooze break
  2. Add 2 Potentiometers to control the speed and volume respectively

For press switch

Make the improvement of the circuit. The graph shows below:

circuit3

connect the circuit

Coding change

Define the switch Pin port at the beginning:

int turnPin=8;
int turnState=0;

add this code to the void setup(){} to set this pin port as input, then the system will read status from this port

pinMode(turnPin,INPUT);

When the press switch was pressed, it will get a short snooze break, therefore it should added a delay sentence during the music plays. I added into the playing function for each song( 5000 means the snooze period is 5 seconds).

if(turnState==HIGH){
 delay(5000);
 break;
 }

For potentiometers

one potentiometer control the volume by changing different resistor’s value, and another potentiometer control the speed of the music by getting different values to change the note duration.

First change the circuit, add these 2 potentiometers into the circuit.

And next, change the code, add these sentences into the playing function for each song

speedVol = analogRead(A2);
volume = analogRead(A4);

and replace below to make one potentiometer can control the speed.

//int noteDuration = 1000 / underworld_tempo[thisNote];
int noteDuration = speedVol / underworld_tempo[thisNote];

Testing them, the volume change didn’t work obviously but the speed control has a really good effects.

Publicités
Publié dans Uncategorized
Web2PDF