So I'm trying to get an analog sensor to work with a piezo on the Arduino uno. Basically I want a proximity sensor to tell a piezo to start singing a melody when someone gets near enough, and blare a noise when they get too close.
I'm trying the if/else statement, and looking at the toneMelody in the library.
The problem is, that I keep getting this error message. "NOTE_A2 was not declared in this scope"
I can't figure out why it keeps saying that. It's not the NOTE_A2 either cause it does that with all the notes. What am I doing wrong?
this is my code so far.
#include "pitches.h"
// notes in the melody:
int melody[] = {
NOTE_A2, NOTE_B3,0, NOTE_C1, NOTE_B3,NOTE_A2, NOTE_B3, NOTE_A1};
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
4, 8, 8, 4,8,8,8,4 };
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
if (sensorvalue > 300) {
for (int thisNote = 0; thisNote < 8; thisNote++) {
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000/noteDurations[thisNote];
tone(8, melody[thisNote],noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(8);
}
}