Homework 04 – Complex Circuit – Tyler Cook

5 Nov

20131104_132749_resized 20131104_132818_resized 20131104_132908_resized 20131104_132835_resized

This circuit has a potentiometer which controls the led, that has a light sensor near it to control the pitch of the speaker,


int led = 9;                                         // the pin that the LED is attached to
int brightness = 0;                         // how bright the LED is
int fadeAmount = 5;                     // how many points to fade the LED by
int pot = 0;                                       // analog pin used to connect the potentiometer
int val;                                               // variable to read the value from the analog pin

void setup() {

pinMode(led, OUTPUT);             // pin 9 to be an output:

void loop() {                                                 // loops the whole process
pot = (analogRead(0));                             //the pot is input at pin A0
analogWrite(led, pot);                              //set the brightness from the pot
int sensorReading =analogRead(A1);        //A1 is the light sensor input
Serial.println(sensorReading);                      //reads light input
int thisPitch =map(sensorReading, 570, 900, 120, 800);               //plays pitchs from sensor reading
tone(10, thisPitch, 10);                                                                            //pin is the speaker output


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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s