Homework 04 – Combine Circuits – Alex Duden

5 Nov

The circuits I combined were:
1. Push button LED
2. Potentiometer with 2 LED lights
3. Potentiometer and light sensor with the noise sensor

ImageImageImage

code:

int LED = 13; //set LED to pin 13
int Button = 7; //set button to pin 7
int previous_value = 0; //previous value of “value” variable
int value = 0; //setting variable value
int state = 0;//
int blue = 5; //setting blue led variable
int green = 6; //setting green led variable
int pot = 0; //setting potentiometer

void setup() {
pinMode (LED, OUTPUT); //set 13 to output
pinMode (Button, INPUT); //button is set to 7 input
pinMode(blue, OUTPUT);//set 5 to output
pinMode(green, OUTPUT);//set 6 to output
Serial.begin(9600);//initialize serial connection
}

void loop(){
int sensorReading = analogRead(A1);//read the sensor:
Serial.println(sensorReading);//sensor reading sent to serial monitor
int thisPitch = map(sensorReading, 530, 890, 120, 800);
tone(9, thisPitch, 10);//play the pitch
delay(30);

pot = (analogRead (A0)); //signals to use the potentiometer
digitalWrite (green, HIGH); //turns the red light on “Hot”
delay (pot); //delays using the potentiometer
digitalWrite (green, LOW); //turns the red light off
delay (pot); //delays using the potentiometer
digitalWrite (blue, HIGH); //turns the blue light on “cross”
delay (pot); //delays using the potentiometer
digitalWrite (blue, LOW); //turns the blue light off
delay (pot); //delays using the potentiometer

value = digitalRead (Button); //set value to reading at pin 7

if ((value == HIGH) && (previous_value == LOW)) {
state = 1 – state;
delay (10);
}

previous_value = value;
if (state == 1) {
digitalWrite (LED, HIGH);
}else {
digitalWrite (LED, LOW);
}
}

 

 

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