This is an old revision of the document!
• Cititor de amprente • Senzor • Buzzer • Placa Arduino • Servomotor
Cod:
Ultrasonic ultrasonic(A2, 12); A2- trigger, 12- echo Servo myservo; create servo object to control a servo SoftwareSerial mySerial(2, 3); RX and TX for fingerprint Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); int val; variable to read the value from the analog pin int fingerprintID = 0; const int buttonPinAlarm = A1; Button connected to analog pin A1; ring button const int buttonPinPass = A0; Button connected to analog pin A1; open/close door button const int ledPin = 5; LED connected to digital pin 5 int previousButtonState, presentButtonState, ledState; the pin for buzzer int buzzer = 11;
for (int thisNote = 0; thisNote < notes * 2; thisNote = thisNote + 2) {
// stop pressing the button
if(digitalRead(buttonPinAlarm) == LOW){
return;
}
// calculates the duration of each note
divider = pgm_read_word_near(melody+thisNote + 1);
if (divider > 0) {
// regular note, just proceed
noteDuration = (wholenote) / divider;
} else if (divider < 0) {
// dotted notes are represented with negative durations!!
noteDuration = (wholenote) / abs(divider);
noteDuration *= 1.5; // increases the duration in half for dotted notes
}
// we only play the note for 90% of the duration, leaving 10% as a pause tone(buzzer, pgm_read_word_near(melody+thisNote), noteDuration * 0.9);
// Wait for the specief duration before playing the next note. delay(noteDuration);
// stop the waveform generation before the next note. noTone(buzzer); }
}
myservo.attach(6); // attaches the servo on pin 9 to the servo object Serial.begin(9600); finger.begin(57600);
pinMode(buttonPinAlarm, INPUT); // Set button pin as input pinMode(ledPin, OUTPUT); // ledPin output pinMode(buttonPinPass, INPUT); previousButtonState = 0; presentButtonState = 0; ledState = LOW; delay(50);
while (!finger.verifyPassword()) {
Serial.println("Did not find fingerprint sensor :(");
delay(300);
} Serial.println(“Found fingerprint sensor!”);
myservo.write(180);
}