Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pitches.h"
- #define pinSwitch 6
- #define pinBuzzer 7
- #define pinKey1 2
- #define pinKey2 3
- #define pinKey3 4
- #define pinKey4 5
- int zm1, zm2, zm3, zm4;
- int wej1;
- int dzwieki[] = {NOTE_C2};
- int losowa;
- int i = 0;
- unsigned long czas;
- unsigned long czasStart;
- int wynik =0 ;
- int kod[20];
- int wcisniety = 0;
- int ton =0;
- int koniec = 0;
- void setup() {
- pinMode(pinSwitch, INPUT_PULLUP);
- pinMode(pinBuzzer, OUTPUT);
- pinMode(pinKey1, INPUT);
- pinMode(pinKey2, INPUT);
- pinMode(pinKey3, INPUT);
- pinMode(pinKey4, INPUT);
- Serial.begin(9600);
- generuj();
- }
- void loop() {
- wcisniety = 0;
- czasStart = millis();
- do {
- zm1 = digitalRead(pinKey1);
- if ( zm1 == 1) {
- ton = NOTE_C2;
- wcisniety = 1;
- }
- } while (wcisniety == 0);
- tone(pinBuzzer, ton);
- delay(300);
- noTone(pinBuzzer);
- delay(50);
- if (ton == kod[i]) {
- Serial.print(ton);
- Serial.println(" OK");
- i = i + 1;
- delay(1000);
- }
- else {
- Serial.print(ton);
- Serial.println(" NIE");
- koniecgry();
- }
- if (kod[i] == 0) {
- generuj();
- wynik += 1;
- i = 0;
- }
- }
- void tmobile() {
- tone(pinBuzzer, NOTE_C4);
- delay(120);
- noTone(pinBuzzer);
- delay(20);
- tone(pinBuzzer, NOTE_C4);
- delay(120);
- noTone(pinBuzzer);
- delay(20);
- tone(pinBuzzer, NOTE_C4);
- delay(120);
- noTone(pinBuzzer);
- delay(20);
- tone(pinBuzzer, NOTE_E4);
- delay(120);
- noTone(pinBuzzer);
- delay(20);
- tone(pinBuzzer, NOTE_C4);
- delay(120);
- noTone(pinBuzzer);
- delay(50);
- }
- void generuj()
- {
- losowa = random(4);
- kod[i] = dzwieki[losowa];
- wyswietl_kod();
- odtworz();
- }
- void odtworz()
- {
- int dc = sizeof(kod)/2;
- for (int j=0; j<dc; j++){
- if (kod[j] != 0 ) {
- tone(pinBuzzer, kod[j]);
- delay(500);
- noTone(pinBuzzer);
- delay(500);
- }
- }
- }
- void wyswietl_kod(){
- int dc = sizeof(kod)/2;
- for (int j=0; j<dc; j++){
- Serial.print(kod[j]);
- Serial.print(" ");
- }
- Serial.println("");
- }
- void koniecgry() {
- tmobile();
- Serial.print("Twój wynik: ");
- Serial.println(wynik);
- Serial.println("Chcesz zagrać jeszcze raz?");
- wej1 = 1;
- while ( wej1 == 1 ) {
- wej1 = digitalRead(pinSwitch);
- }
- tmobile();
- delay(1000);
- memset(kod, 0, 20 * sizeof(int));
- i = 0;
- wynik = 0;
- generuj();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement