Друзья, помогите разобраться с кодом

Всем привет. Возникла проблема на вот такой кусок кода:

#include "Volume.h"
#define buzzer_pin 6
#define reverse 0
#define analog_value 1000
#define analog_invert 0
const int Apins[] = {0, 1, 2, 3};
const int frequencies[] = {100, 200, 400, 800};
bool flag = false;




void setup() {
  Serial.begin(9600);
  vol.begin();
  pinMode(buzzer_pin, OUTPUT);
  pinMode(13, OUTPUT);
}

void loop() {
  int bb = 0;
  flag = false;
  for (size_t i = 0; i < 4; i++) {
    if (analogRead(Apins[i]) < analog_value) {
      bb++;
      Serial.println("Pin " + String(i) + " is active");
      tone(buzzer_pin, frequencies[i]);
      digitalWrite(13, HIGH);
      flag = true;
      while (analogRead(Apins[i]) < analog_value) delay(1);
      noTone(buzzer_pin);
      digitalWrite(13, LOW);
      vol.tone(880, 255 ); // 100% Volume
      vol.fadeOut(5000);  // Start a 5 second fade out
      vol.delay(10000);    // Wait for this fade to finish
      
    }
      
  }
  if (bb == 0) {
    noTone(buzzer_pin);
    digitalWrite(13, LOW);
  }
}

Выдает ошибку: ‘vol’ was not declared in this scope
При добавлении строки “Volume vol;” выдает:
Arduino: 1.8.13 (Windows 10), Плата:“Arduino Uno”

C:\Users\админ\Desktop\sketch_mar20a\Арфа2.ino:1:0: warning: “buzzer_pin” redefined

C:\Users\админ\Desktop\sketch_mar20a\sketch_mar20a.ino:2:0: note: this is the location of the previous definition

C:\Users\админ\Desktop\sketch_mar20a\Арфа2.ino:5:17: error: redefinition of ‘const int Apins []’

C:\Users\админ\Desktop\sketch_mar20a\sketch_mar20a.ino:6:11: note: ‘const int Apins [4]’ previously defined here

C:\Users\админ\Desktop\sketch_mar20a\Арфа2.ino:6:23: error: redefinition of ‘const int frequencies []’

C:\Users\админ\Desktop\sketch_mar20a\sketch_mar20a.ino:7:11: note: ‘const int frequencies [4]’ previously defined here

C:\Users\админ\Desktop\sketch_mar20a\Арфа2.ino:7:6: error: redefinition of ‘bool flag’

C:\Users\админ\Desktop\sketch_mar20a\sketch_mar20a.ino:8:6: note: ‘bool flag’ previously defined here

C:\Users\админ\Desktop\sketch_mar20a\Арфа2.ino: In function ‘void setup()’:

C:\Users\админ\Desktop\sketch_mar20a\Арфа2.ino:9:6: error: redefinition of ‘void setup()’

C:\Users\админ\Desktop\sketch_mar20a\sketch_mar20a.ino:13:6: note: ‘void setup()’ previously defined here

C:\Users\админ\Desktop\sketch_mar20a\Арфа2.ino: In function ‘void loop()’:

C:\Users\админ\Desktop\sketch_mar20a\Арфа2.ino:15:6: error: redefinition of ‘void loop()’

C:\Users\админ\Desktop\sketch_mar20a\sketch_mar20a.ino:20:6: note: ‘void loop()’ previously defined here

C:\Users\админ\Desktop\sketch_mar20a\Арфа2.ino:28:29: error: ‘mv’ was not declared in this scope

exit status 1

Ошибка компиляции для платы Arduino Uno.

Использовал данную библиотеку GitHub - connornishijima/arduino-volume1: Arduino tone() just got 8-bit volume control - with no extra components!

Вставьте код по правилам. Прямо в окне ввода текста сообщения есть инструкция как это легко и просто сделать
А также тут Вставка программного кода

Где текст ошибки ?

exit status 1
Ошибка компиляции для платы Arduino Uno.

vol.tone(880, 255 ); // 100% Volume
vol.fadeOut(5000); // Start a 5 second fade out
vol.delay(10000); // Wait for this fade to finish

@ФФФ , код надо вставлять ПОЛ-НОСТЬ-Ю.
По этому огрызку ничего сказать нельзя.

#include "Volume.h"
#define buzzer_pin 6
#define reverse 0
#define analog_value 1000
#define analog_invert 0
const int Apins[] = {0, 1, 2, 3};
const int frequencies[] = {100, 200, 400, 800};
bool flag = false;




void setup() {
  Serial.begin(9600);
  vol.begin();
  pinMode(buzzer_pin, OUTPUT);
  pinMode(13, OUTPUT);
}

void loop() {
  int bb = 0;
  flag = false;
  for (size_t i = 0; i < 4; i++) {
    if (analogRead(Apins[i]) < analog_value) {
      bb++;
      Serial.println("Pin " + String(i) + " is active");
      tone(buzzer_pin, frequencies[i]);
      digitalWrite(13, HIGH);
      flag = true;
      while (analogRead(Apins[i]) < analog_value) delay(1);
      noTone(buzzer_pin);
      digitalWrite(13, LOW);
      vol.tone(880, 255 ); // 100% Volume
      vol.fadeOut(5000);  // Start a 5 second fade out
      vol.delay(10000);    // Wait for this fade to finish
      
    }
      
  }
  if (bb == 0) {
    noTone(buzzer_pin);
    digitalWrite(13, LOW);
  }
}

и теперь текст ошибки тоже ПОЛНОСТЬЮ

C:\Users\админ\Desktop\sketch_mar20a\Арфа2.ino:1:0: warning: “buzzer_pin” redefined

C:\Users\админ\Desktop\sketch_mar20a\sketch_mar20a.ino:2:0: note: this is the location of the previous definition

C:\Users\админ\Desktop\sketch_mar20a\Арфа2.ino:5:17: error: redefinition of ‘const int Apins []’

C:\Users\админ\Desktop\sketch_mar20a\sketch_mar20a.ino:6:11: note: ‘const int Apins [4]’ previously defined here

C:\Users\админ\Desktop\sketch_mar20a\Арфа2.ino:6:23: error: redefinition of ‘const int frequencies []’

C:\Users\админ\Desktop\sketch_mar20a\sketch_mar20a.ino:7:11: note: ‘const int frequencies [4]’ previously defined here

C:\Users\админ\Desktop\sketch_mar20a\Арфа2.ino:7:6: error: redefinition of ‘bool flag’

C:\Users\админ\Desktop\sketch_mar20a\sketch_mar20a.ino:8:6: note: ‘bool flag’ previously defined here

C:\Users\админ\Desktop\sketch_mar20a\Арфа2.ino: In function ‘void setup()’:

C:\Users\админ\Desktop\sketch_mar20a\Арфа2.ino:9:6: error: redefinition of ‘void setup()’

C:\Users\админ\Desktop\sketch_mar20a\sketch_mar20a.ino:13:6: note: ‘void setup()’ previously defined here

C:\Users\админ\Desktop\sketch_mar20a\Арфа2.ino: In function ‘void loop()’:

C:\Users\админ\Desktop\sketch_mar20a\Арфа2.ino:15:6: error: redefinition of ‘void loop()’

C:\Users\админ\Desktop\sketch_mar20a\sketch_mar20a.ino:20:6: note: ‘void loop()’ previously defined here

C:\Users\админ\Desktop\sketch_mar20a\Арфа2.ino:28:29: error: ‘mv’ was not declared in this scope

exit status 1

Ошибка компиляции для платы Arduino Uno.

У вас в одной директории два скетча с одинаковым или похожим кодом: sketch_mar20a.ino и Арфа2.ino
Удалите один из них

1 лайк

Действительно! Спасибо большое! Попросту где то мискликнул и вышла такая лабуда. Сам сижу в 1 час ночи, голова не варит. Еще раз спасибо.