PLEASE HELP! Retrieving frequencies from EEPROM

Hi there,

I am trying to playback frequencies stored in EEPROM, however there is a low frequency constant background noise in the playback. Is this a software or hardware problem?

Thanks in advance.

Here is my code:

#include <EEPROM.h> 
#include "pitches.h"
#define speaker A5
#define record_button 3
#define play_button 5
#define record_led 2
#define play_led 4
#define melody_button A0

int customVar;
int eeAddress = 0;
int eeAddressplay = 0;

const int inPot = A1; //potentiometer to change octaves (8 octaves in total)
byte octave; 
byte tone_out; // specifies elements in melody array
int tone_key; // frequency of key
boolean silence; // silence variable is either true or false

int maxNumber = 500;
byte time = 20; //increase, teach about sampling, break data into discrete time segments, memory

byte buttons[] = {6,7,8,9,10,11,12,13};
int saveSounds[500];
int saveNumber = 0;

byte melody1[8] = { 
  NOTE_C1 , NOTE_D1, NOTE_E1, NOTE_F1, NOTE_G1, NOTE_A1, NOTE_B1, NOTE_C2};
byte melody2[8] = { 
  NOTE_C2 , NOTE_D2, NOTE_E2, NOTE_F2, NOTE_G2, NOTE_A2, NOTE_B2, NOTE_C3};
int melody3[8] = { 
  NOTE_C3 , NOTE_D3, NOTE_E3, NOTE_F3, NOTE_G3, NOTE_A3, NOTE_B3, NOTE_C4};
int melody4[8] = { 
  NOTE_C4 , NOTE_D4, NOTE_E4, NOTE_F4, NOTE_G4, NOTE_A4, NOTE_B4, NOTE_C5};
int melody5[8] = { 
  NOTE_C5 , NOTE_D5, NOTE_E5, NOTE_F5, NOTE_G5, NOTE_A5, NOTE_B5, NOTE_C6};
int melody6[8] = { 
  NOTE_C6 , NOTE_D6, NOTE_E6, NOTE_F6, NOTE_G6, NOTE_A6, NOTE_B6, NOTE_C7};
int melody7[8] = { 
  NOTE_C7 , NOTE_D7, NOTE_E7, NOTE_F7, NOTE_G7, NOTE_A7, NOTE_B7, NOTE_C8};

//PIANO FUNCTION
void freePlay() // piano function which plays 8 octaves (8 octaves in total, 8 keys per octave)
{
  octave = map(analogRead(inPot),0,1023,1,7); // analogRead: 0-5V input voltage maps to integer values 0-1023
                                              // integer values 0-1023 maps to 1-8  
  if (digitalRead(buttons[0]) == HIGH) {      
    tone_out = 0;                             // if the first button is pressed, tone_out = 0 and silence = false
    silence = false;                          // skips to if (silence == false) line
  } 
  else if (digitalRead(buttons[1]) == HIGH) {
    tone_out = 1;  
    silence = false;
  } 
  else if (digitalRead(buttons[2]) == HIGH) {
    tone_out = 2; 
    silence = false;
  } 
  else if (digitalRead(buttons[3]) == HIGH) {
    tone_out = 3;  
    silence = false;
  } 
  else if (digitalRead(buttons[4]) == HIGH) {
    tone_out = 4;  
    silence = false;
  } 
  else if (digitalRead(buttons[5]) == HIGH) {
    tone_out = 5; 
    silence = false;
  } 
  else if (digitalRead(buttons[6]) == HIGH) {
    tone_out = 6; 
    silence = false;
  } 
  else if (digitalRead(buttons[7]) == HIGH) {
    tone_out = 7;
    silence = false;
  } 
  else {
    silence = true; // if none of the if/elseif statements are true, execute silence = true            
  }

  if (silence == false)
  {
    switch(octave) // depending on which octave is selected (1-8), the corresponding switch case statement is executed
    {
    case 1: 
      tone_key = melody1[tone_out]; break;
    case 2: 
      tone_key = melody2[tone_out]; break;
    case 3: 
      tone_key = melody3[tone_out]; break;
    case 4: 
      tone_key = melody4[tone_out]; break;
    case 5: 
      tone_key = melody5[tone_out]; break;
    case 6: 
      tone_key = melody6[tone_out]; break;
    case 7: 
      tone_key = melody7[tone_out]; break;
    }
    tone(speaker,tone_key); // Arduino inbuilt tone function generates a square wave of the specified frequency  
  }                         // at 50% duty cycle on the speaker pin
  else {
   noTone(speaker); // wave continues until a call to noTone()      
   delay (5); } // 5 millisecond delay
}

//SETUP FUNCTION
void setup() // setup Arduino pins as input or output
{ 
 for(int i = 0; i < 8; i++)
 {
  pinMode(buttons[i], INPUT); 
 } 
 pinMode(speaker, OUTPUT); 
 pinMode(melody_button, INPUT);
 pinMode(record_led, OUTPUT);
 pinMode(play_led, OUTPUT);
 pinMode(inPot, INPUT);
 Serial.begin(9600);
}

//MAIN CODE
void loop() {
  freePlay(); 
  //RECORD 
  if (digitalRead(record_button) == HIGH) {
    digitalWrite(record_led, HIGH);
    for(int i = 0; i < maxNumber ; i++) {
      octave = map(analogRead(inPot),0,1023,1,7);                                           
      if (digitalRead(buttons[0]) == HIGH) {      
        tone_out = 0;                             
        silence = false;                           
      } 
      else if (digitalRead(buttons[1]) == HIGH) {
        tone_out = 1;  
        silence = false;
      } 
      else if (digitalRead(buttons[2]) == HIGH) {
        tone_out = 2; 
        silence = false;
      } 
      else if (digitalRead(buttons[3]) == HIGH) {
        tone_out = 3;  
        silence = false;
      } 
      else if (digitalRead(buttons[4]) == HIGH) {
        tone_out = 4;  
        silence = false;
      } 
      else if (digitalRead(buttons[5]) == HIGH) {
        tone_out = 5; 
        silence = false;
      } 
      else if (digitalRead(buttons[6]) == HIGH) {
        tone_out = 6; 
        silence = false;
      } 
      else if (digitalRead(buttons[7]) == HIGH) {
        tone_out = 7;
        silence = false;
      } 
      else {
        silence = true;
        tone_key = 0;
      }
      if (silence == false) {
        switch(octave) { 
          case 1: tone_key = melody1[tone_out]; break;
          case 2: tone_key = melody2[tone_out]; break;
          case 3: tone_key = melody3[tone_out]; break;
          case 4: tone_key = melody4[tone_out]; break;
          case 5: tone_key = melody5[tone_out]; break;
          case 6: tone_key = melody6[tone_out]; break;
          case 7: tone_key = melody7[tone_out]; break;
        }
        tone(speaker,tone_key); 
        delay(time);
      }                         
      else {           
        noTone(speaker);
        tone_key = 0; 
        delay (time);
      } 
      saveSounds[saveNumber] = tone_key;
      saveNumber++;
      if (digitalRead(play_button) == HIGH) {
        break;
      }
    }
    digitalWrite(record_led, LOW);
    tone(speaker, 700);
    delay(200);
    noTone(speaker);
    for (int i = 0; i<500; i++) {
      EEPROM.put(eeAddress,saveSounds[i]);
      eeAddress = eeAddress + 2;
    }   
  }
  //PLAYBACK
  if(digitalRead(play_button) == HIGH) {
    digitalWrite(play_led, HIGH);
    for(int i = 0; i < maxNumber; i++) {
      EEPROM.get(eeAddressplay,customVar);
      tone(speaker,customVar);
      eeAddressplay = eeAddressplay + 2;
      delay(time);
      Serial.print(customVar); 
    }
    noTone(speaker);
    digitalWrite(play_led,LOW);
  } 
}

you could try posting the question yet another time

http://forum.arduino.cc/index.php?topic=477591.msg3262440#msg3262440

BulldogLowell:
you could try posting the question yet another time

EEPROM - constant buzzing from piezo transducer - Programming Questions - Arduino Forum

He re-posted because he has no understanding of the answer that was given. LOL.