Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Deklaracje pinów dla brzęczyka i przycisków oraz stanów przycisków
- int buzzerPin = 8;
- int buttonPin1 = 2;
- int buttonPin2 = 3;
- int buttonPin3 = 4;
- int buttonPin4 = 5;
- int buttonPin5 = 6;
- int buttonPin6 = 7;
- int buttonState1 = 0;
- int buttonState2 = 0;
- int buttonState3 = 0;
- int buttonState4 = 0;
- int buttonState5 = 0;
- int buttonState6 = 0;
- // Tablica z częstotliwościami dźwięków do odtwarzania na brzęczyku
- int notes[] = {262, 294, 330, 349, 392, 440};
- void setup() {
- // Konfiguracja pinów jako wejścia z wewnętrznym pull-up
- pinMode(buttonPin1, INPUT_PULLUP);
- pinMode(buttonPin2, INPUT_PULLUP);
- pinMode(buttonPin3, INPUT_PULLUP);
- pinMode(buttonPin4, INPUT_PULLUP);
- pinMode(buttonPin5, INPUT_PULLUP);
- pinMode(buttonPin6, INPUT_PULLUP);
- // Konfiguracja pinu brzęczyka oraz pinów diod LED
- pinMode(buzzerPin, OUTPUT);
- pinMode(LED1, OUTPUT);
- pinMode(LED2, OUTPUT);
- pinMode(LED3, OUTPUT);
- pinMode(LED4, OUTPUT);
- pinMode(LED5, OUTPUT);
- pinMode(LED6, OUTPUT);
- }
- void loop() {
- // Odczyt stanu przycisków
- buttonState1 = digitalRead(buttonPin1);
- buttonState2 = digitalRead(buttonPin2);
- buttonState3 = digitalRead(buttonPin3);
- buttonState4 = digitalRead(buttonPin4);
- buttonState5 = digitalRead(buttonPin5);
- buttonState6 = digitalRead(buttonPin6);
- // Obsługa przycisków i brzęczyka
- if (buttonState1 == LOW) {
- // Włącz diodę LED i odtwórz pierwszą nutę
- digitalWrite(LED1, HIGH);
- tone(buzzerPin, notes[0], 100);
- delay(100);
- noTone(buzzerPin);
- // Wyłącz diodę LED
- digitalWrite(LED1, LOW);
- }
- else if (buttonState2 == LOW) {
- // Analogicznie dla drugiego przycisku i nuty
- digitalWrite(LED2, HIGH);
- tone(buzzerPin, notes[1], 100);
- delay(100);
- noTone(buzzerPin);
- digitalWrite(LED2, LOW);
- }
- // Analogicznie dla pozostałych przycisków i nut
- else if (buttonState3 == LOW) {
- digitalWrite(LED3, HIGH);
- tone(buzzerPin, notes[2], 100);
- delay(100);
- noTone(buzzerPin);
- digitalWrite(LED3, LOW);
- }
- else if (buttonState4 == LOW) {
- digitalWrite(LED4, HIGH);
- tone(buzzerPin, notes[3], 100);
- delay(100);
- noTone(buzzerPin);
- digitalWrite(LED4, LOW);
- }
- else if (buttonState5 == LOW) {
- digitalWrite(LED5, HIGH);
- tone(buzzerPin, notes[4], 100);
- delay(100);
- noTone(buzzerPin);
- digitalWrite(LED5, LOW);
- }
- else if (buttonState6 == LOW) {
- digitalWrite(LED6, HIGH);
- tone(buzzerPin, notes[5], 100);
- delay(100);
- noTone(buzzerPin);
- digitalWrite(LED6, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment