Загрузка данных


#define PR A0
#define BUZZER 10
#define LED 3

int notes[] = {
  262, 277, 294, 311,
  330, 349, 370, 392,
  415, 440, 466, 494
};

int oldNote = -1;

void setup() {
  Serial.begin(9600);

  pinMode(PR, INPUT);
  pinMode(BUZZER, OUTPUT);
  pinMode(LED, OUTPUT);
}

void loop() {
  int prValue = analogRead(PR);

  int note = map(prValue, 0, 1016, 0, 12);

  if (note > 11) {
    note = 11;
  }

  if (note != oldNote) {
    tone(BUZZER, notes[note]);

    Serial.print(notes[note]);
    Serial.println(" Hz");

    oldNote = note;
  }

  if (note >= 9) {
    digitalWrite(LED, HIGH);
  } else {
    digitalWrite(LED, LOW);
  }

  delay(30);
}