HW4_BREATHLAMP_YU_ZHANG

 

Arduino2_bb

Arduino2_pcb

Arduino2_schem

 

 

 

BREATH LAMP

There are six pink leds on the arduino board, fading in and out, just like they’re breathing. ¬†It also has the sounds as well.

The fading lighting will affect the photoresistor, which will lead to the buzzer to make sound. When the photoresistor detected this fading lights, the buzzer will create the ramp sound.

Also, it will be affected by something above it, when I put my hands above it, the sound appears.

————————————————

CODE:

int prPin = 0;
int prReading;
int buzzerPin = 4;
long buzzerFreq;
int led = 9;
int brightness = 0;
int fadeAmount = 5;long BUZZ_FREQ_MAX = 10000;
long PR_MAX = 1023;

void setup() {
pinMode(buzzerPin, OUTPUT);
pinMode(led, OUTPUT);
}

void loop() {
prReading = analogRead(prPin);
buzzerFreq = (prReading * BUZZ_FREQ_MAX) / PR_MAX;

buzz(buzzerPin, buzzerFreq, 10);
analogWrite(led, brightness);

brightness = brightness + fadeAmount;

if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ;
}
delay(30);
}

void buzz(int targetPin, long frequency, long length) {
long delayValue = 1000000/frequency/2;
long numCycles = frequency * length/ 1000;
for (long i=0; i < numCycles; i++){
digitalWrite(targetPin,HIGH);
delayMicroseconds(delayValue);
digitalWrite(targetPin,LOW);
delayMicroseconds(delayValue);
}
}

Leave a Reply

Your email address will not be published.