Image

Homework 04-Complex Circuit-Jake Brzezicki

5 Nov

Homework 04-Complex Circuit-Jake Brzezicki

int LED = 13;//sets led to 13
int Button = 7;//sets button to 7
int previous_val = 0;
int val = 0;
int state = 0;
void setup() {
Serial.begin(9600);
pinMode(LED, OUTPUT);
pinMode(Button, INPUT);
}

void loop() {
int sensorReading =analogRead(A0);//photosensor goes to A0
Serial.println(sensorReading);
int thisPitch =map(sensorReading, 30, 865, 120, 800);//sensor range
tone(9, thisPitch, 10);
delay(1);

val = digitalRead(Button);

if ((val == HIGH) && (previous_val == LOW)) {
state = 1 – state;
delay(10);
}
previous_val = val;

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