Description
Many galleries restraint people from taking photos with flashlights so I designed an alarm that'll set off if a flashsight went off. I used the photocell to detect the level of light and if it's above a certain value, speaker will sound in a two-note pattern and blue and red LED lights will be blinking continuously. They'll settle back to oirginal state after 50 cycles.
https://vimeo.com/77021192
Code
int ledPin = 9;
int bluePin = 3;
int speakerPin = 7;
int sensorPin = 0;
int val = 0;
// note names and their corresponding half-periods
byte names[] ={ 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C'};
int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956};
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(speakerPin, OUTPUT);
Serial.begin(9600);
Serial.println("ready");
digitalWrite(speakerPin, LOW);
digitalWrite(bluePin,HIGH);
}
void loop() {
val = analogRead(sensorPin);
delay(10);
Serial.println(val);
if (val > 900){
for( int i=0; i<50; i++ ) {
for( int i=0; i<50; i++ ) {
digitalWrite(ledPin, HIGH); // write to LED
digitalWrite(bluePin, LOW);
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tones[5]);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tones[5]);
}
delay(10);
for( int i=0; i<50; i++ ) {
digitalWrite(ledPin, LOW); // write to LED
digitalWrite(bluePin, HIGH);
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tones[1]);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tones[1]);
}
}
}
}
- Login to post comments