Image

Homework 04- Combine Circuits – Casey Henrichs

5 Nov

Homework 04- Combine Circuits - Casey Henrichs

I tried uploading a video this week but youtube is not accepting it as an upload.
Here I used the thermin sound and button to flash an LED. Reaching for the button affects the light sensor and then an LED is set to blink with a delay.

(having difficulty with the blinking delay)

int LED = 13;
int Button = 6;
int previous_value = 0;
int value = 0;
int state = 0;
int blue = 5;

void setup () {
pinMode (LED, OUTPUT);
pinMode (LED, INPUT);
Serial.begin (9600);
pinMode (blue, OUTPUT);
}

void loop () {
digitalWrite (blue, HIGH);
delay (3);
digitalWrite (blue, LOW);
delay (5);
digitalWrite (blue, HIGH);
delay (2);
digitalWrite (blue, LOW);
delay (5);
digitalWrite (blue, HIGH);
delay (2);
digitalWrite (blue, LOW);
delay (5);
digitalWrite (blue, HIGH);
delay (2);
digitalWrite (blue, LOW);
delay (5);
value = digitalRead (Button);

if ((value ==HIGH) && (previous_value == LOW)) {
state = 1 – state;
delay (1);
}
{
int sensorReading = analogRead(A0); //read thesensor
Serial.println(sensorReading); //print the sensor reading to serial monitor, ln means it starts a new line at intervals
int thisPitch = map(sensorReading, 7, 90, 120, 800); //map the analog input range to desired output
tone (9, thisPitch, 10); // play the pitch
delay (1); // delay in between reads for stability
}

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