Homework 04 – New Circuit – Matt Schneider

5 Nov

Potentiometer controls arm that, when passing over a motion sensor, changes the pitch of the speaker. 

#include <Servo.h>
Servo microservo;
int potentiometer=0;
int value;

void setup() {
microservo.attach(9); //set microservo to slot 9
Serial.begin(9600); //set up conncection

}

void loop() {
int sensorReading=analogRead(A1); //set motion sensor to slot A1
int thisPitch=map(sensorReading,250,520,50,800);
tone(10,thisPitch,10);
Serial.println(sensorReading);
delay(1);
value = analogRead(potentiometer);
value= map(value,0,1024,0,179);
microservo.write(value);
delay(15);
}

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s