NewTone library

I am trying to use the NewTone library but every time I try to compile the code it says:
"exit status 1
Error compiling for board Arduino/Genuino Uno."

I have attached the NewTone library I downloaded.

#include <LiquidCrystal.h>
#include <IRremote.h>
#include <NewTone.h>
#include <avr/io.h>
#include <avr/wdt.h>

#define Reset_AVR() wdt_enable(WDTO_30MS); while(1) {} 


#define buzzer 6     

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int result;
int RECV_PIN=9;

IRrecv irrecv(RECV_PIN);

decode_results results;
  
void setup() {   
  Serial.begin(9600);               
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("-----Choose-----");
  lcd.setCursor(0,1);
  lcd.print("----A Song!!----");
  pinMode(buzzer, OUTPUT);
  irrecv.enableIRIn();
}  

void loop() {
  if (irrecv.decode(&results)) {
    result=results.value, HEX;
    Serial.println(result);
    if (result==12495) {
      ode();
    }
    else if (result==6375) {
      london();
    }
    else if (result==31365) {
      fur();
    }
    else if (result==4335) {
      pirate();
    }
    irrecv.resume();
  }
  delay(100);
} 

void fur() {
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Fur Elise");
  delay(1000);
  lcd.clear();
  nota_mi(150,200);
  nota_rez(150,200);
  nota_mi(150,200);
  nota_rez(150,200);
  nota_mi(150,200);
  nota_si(150,200);
  nota_rez(150,200);
  nota_do(150,200);
  nota_la(450,300);
  nota_do(150,200);
  nota_mi(150,200);
  nota_la(150,200);
  nota_si(450,300);
  nota_mi(150,200);
  nota_solz(150,200);
  nota_si(150,200);
  nota_do(450,300);
  nota_mi(150,200);
  nota_mi(150,200);
  nota_rez(150,200);
  nota_mi(150,200);
  nota_rez(150,200);
  nota_mi(150,200);
  nota_si(150,200);
  nota_rez(150,200);
  nota_do(150,200);
  nota_la(450,300);
  nota_do(150,200);
  nota_mi(150,200);
  nota_la(150,200);
  nota_sol(450,300);
  nota_mi(150,200);
  nota_do(150,200);
  nota_si(150,200);
  nota_la(600,800);
  nota_mi(150,200);
  nota_rez(150,200);
  nota_mi(150,200);
  nota_rez(150,200);
  nota_mi(150,200);
  nota_si(150,200);
  nota_rez(150,200);
  nota_do(150,200);
  nota_la(450,300);
  nota_do(150,200);
  nota_mi(150,200);
  nota_la(150,200);
  nota_si(450,300);
  nota_mi(150,200);
  nota_solz(150,200);
  nota_si(150,200);
  nota_do(450,300);
  lcd.clear();
  delay(100);
  Reset_AVR();
}

void london() {
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("London Bridge");
  lcd.setCursor(0,1);
  lcd.print("Is falling down");
  delay(1000);
  lcd.clear();
  nota_sol(450,600);
  nota_la(150,200);
  nota_sol(300,400);
  nota_fa(300,400);
  nota_mi(300,400);
  nota_fa(300,400);
  nota_sol(600,800);
  nota_re(300,400);
  nota_mi(300,400);
  nota_fa(600,800);
  nota_mi(300,400);
  nota_fa(300,400);
  nota_sol(600,800);
  nota_sol(450,600);
  nota_la(150,200);
  nota_sol(300,400);
  nota_fa(300,400);
  nota_mi(300,400);
  nota_fa(300,400);
  nota_sol(600,800);
  nota_re(600,800);
  nota_sol(600,800);
  nota_mi(300,400);
  nota_do(450,600);
  lcd.clear();
  delay(100);
  Reset_AVR();
}

void ode() {
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Ode to Joy");
  delay(1000);
  lcd.clear();
  nota_mi(300,400);
  nota_mi(300,400);
  nota_fa(300,400);
  nota_sol(300,400);
  nota_sol(300,400);
  nota_fa(300,400);
  nota_mi(300,400);
  nota_re(300,400);
  nota_do(300,400);
  nota_do(300,400);
  nota_re(300,400);
  nota_mi(300,400);
  nota_mi(450,600);
  nota_re(150,200);
  nota_re(600,800);
  nota_mi(300,400);
  nota_mi(300,400);
  nota_fa(300,400);
  nota_sol(300,400);
  nota_sol(300,400);
  nota_fa(300,400);
  nota_mi(300,400);
  nota_re(300,400);
  nota_do(300,400);
  nota_do(300,400);
  nota_re(300,400);
  nota_mi(300,400);
  nota_re(450,600);
  nota_do(150,200);
  nota_do(600,800);
  nota_re(300,400);
  nota_re(300,400);
  nota_mi(300,400);
  nota_do(300,400);
  nota_re(300,400);
  nota_mi(150,200);
  nota_fa(150,200);
  nota_mi(300,400);
  nota_do(300,400);
  nota_re(300,400);
  nota_mi(150,200);
  nota_fa(150,200);
  nota_mi(300,400);
  nota_re(300,400);
  nota_do(300,400);
  nota_re(300,400);
  nota_sol(600,800);
  nota_mi(300,400);
  nota_mi(300,400);
  nota_fa(300,400);
  nota_sol(300,400);
  nota_sol(300,400);
  nota_fa(300,400);
  nota_mi(300,400);
  nota_re(300,400);
  nota_do(300,400);
  nota_do(300,400);
  nota_re(300,400);
  nota_mi(300,400);
  nota_re(450,600);
  nota_do(150,200);
  nota_do(600,800);
  lcd.clear();
  delay(100);
  Reset_AVR();
}

void pirate() {
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("He's a Pirate");
  delay(1000);
  lcd.clear();
  nota_mi(150,200);
  nota_sol(150,200);
  nota_la(300,400);
  nota_la(300,400);
  nota_la(150,200);
  nota_si(150,200);
  nota_do(300,400);
  nota_do(300,400);
  nota_do(150,200);
  nota_re(150,200);
  nota_si(300,400);
  nota_si(300,400);
  nota_la(150,200);
  nota_sol(150,200);
  nota_sol(150,200);
  nota_la(450,600);
  nota_mi(150,200);
  nota_sol(150,200);
  nota_la(300,400);
  nota_la(300,400);
  nota_la(150,200);
  nota_si(150,200);
  nota_do(300,400);
  nota_do(300,400);
  nota_do(150,200);
  nota_re(150,200);
  nota_si(300,400);
  nota_si(300,400);
  nota_la(150,200);
  nota_sol(150,200);
  nota_la(300,400);
  delay(400);
  nota_mi(150,200);
  nota_sol(150,200);
  nota_la(300,400);
  nota_la(300,400);
  nota_la(150,200);
  nota_do(150,200);
  nota_re(300,400);
  nota_re(300,400);
  nota_re(150,200);
  nota_mi(150,200);
  nota_fa(300,400);
  nota_fa(300,400);
  nota_mi(150,200);
  nota_re(150,200);
  nota_mi(150,200);
  nota_la(450,600);
  nota_la(150,200);
  nota_si(150,200);
  nota_do(300,400);
  nota_do(300,400);
  nota_re(300,400);
  nota_mi(150,200);
  nota_la(450,600);
  nota_la(150,200);
  nota_do(150,200);  
  nota_si(300,400);
  nota_si(300,400);
  nota_do(150,200);
  nota_la(150,200);
  nota_si(900,1200);
  nota_si(300,400);
  nota_si(300,400);
  nota_do(150,200);
  nota_la(150,200);
  nota_si(900,1200);
  nota_si(300,400);
  nota_si(300,400);
  nota_la(150,200);
  nota_sol(150,200);
  nota_la(600,800);
  lcd.clear();
  delay(100);
  Reset_AVR();
}

void shut() {
  if (irrecv.decode(&results)) {
    result=results.value, HEX;
    Serial.println(result);
    if (result==-23971) {
      Reset_AVR();
    }
  }
  irrecv.resume();
}

void nota_do(int duration, int pause) {
  shut();
  lcd.setCursor(0, 0);
  lcd.print("Do    ");
  NewTone(11,262,duration); //DO
  delay(pause);
  }

void nota_doz(int duration, int pause) {
  shut();
  lcd.setCursor(0, 0);
  lcd.print("Do #  ");
  NewTone(11,277,duration); //DO
  delay(pause);
  }

void nota_re(int duration, int pause) {
  shut;
  lcd.setCursor(0, 0);
  lcd.print("Re    ");
  NewTone(11,294,duration); //RE
  delay(pause);
  }

void nota_rez(int duration, int pause) {
  shut;
  lcd.setCursor(0, 0);
  lcd.print("Re #  ");
  NewTone(11,311,duration); //RE
  delay(pause);
  }

void nota_mi(int duration, int pause) {
  shut();
  lcd.setCursor(0, 0);
  lcd.print("Mi    ");
  NewTone(11,330,duration); //MI
  delay(pause);
  }

void nota_fa(int duration, int pause) {
  shut();
  lcd.setCursor(0, 0);
  lcd.print("Fa    ");
  NewTone(11,349,duration); //FA
  delay(pause);
  }

void nota_faz(int duration, int pause) {
  shut();
  lcd.setCursor(0, 0);
  lcd.print("Fa #  ");
  NewTone(11,370,duration); //FA
  delay(pause);
  }


void nota_sol(int duration, int pause) {
  shut();
  lcd.setCursor(0, 0);
  lcd.print("Sol   ");
  NewTone(11,392,duration); //SOL
  delay(pause);
  }

void nota_solz(int duration, int pause) {
  shut();
  lcd.setCursor(0, 0);
  lcd.print("Sol # ");
  NewTone(11,415,duration); //SOL
  delay(pause);
  }

void nota_la(int duration, int pause) {
  shut();
  lcd.setCursor(0, 0);
  lcd.print("La    ");
  NewTone(11,440,duration); //LA
  delay(pause);
  } 

void nota_laz(int duration, int pause) {
  shut();
  lcd.setCursor(0, 0);
  lcd.print("La #  ");
  NewTone(11,466,duration); //LA
  delay(pause);
  }

void nota_si(int duration, int pause) {
  shut();
  lcd.setCursor(0, 0);
  lcd.print("Si    ");
  NewTone(11,494,duration); //SI
  delay(pause);
  }

NewTone_v1.0.zip (2.47 KB)

The HEX is there for the IR receiver and remote control in my project.

I also did not see the messages before here they are:
Arduino: 1.8.8 (Windows Store 1.8.19.0) (Windows 10), Board: "Arduino/Genuino Uno"

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\libraries\LiquidCrystal\src\LiquidCrystal.cpp: In function 'clear.constprop':

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\libraries\LiquidCrystal\src\LiquidCrystal.cpp:180:1: internal compiler error: Segmentation fault

}

^

Please submit a full bug report,

with preprocessed source if appropriate.

See http://gcc.gnu.org/bugs.html for instructions.

lto-wrapper.exe: fatal error: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\tools\avr/bin/avr-gcc returned 1 exit status

compilation terminated.

c:/program files/windowsapps/arduinollc.arduinoide_1.8.19.0_x86__mdqgnx93n4wtt/hardware/tools/avr/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld.exe: error: lto-wrapper failed

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino/Genuino Uno.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Oh Segmentation fault, where going to see loads of these as people upgrade their IDE, "especially in windows 10" firstly update any libraries that show error messages, secondly if its a old sketch, re-save it as a new one.

Deleting - uninstalling the 1.8.8 IDE and ALL its files except your sketches then installing an older version such as 1.6 is the only full fix.

Changing the board manager version for each platform does not fix it either.

Prior to uninstalling the IDE and all its files - cache, you can just keep click either compile - upload and it will eventually work

my segmentation fault error

Any lastly a little gem for you, Here's tone with no timers or libraries which works on any pin, which i got from an old work college, but your need to edit the beeper and alarm functions for you own tones as i just copied an pasted it from an old sketch.

// BEEPER
const int nc = 3830;   // 261 Hz
const int nd = 3400;   // 294 Hz
const int ne = 3038;   // 329 Hz
const int nf = 2864;   // 349 Hz
const int ng = 2550;   // 392 Hz
const int na = 2272;   // 440 Hz
const int nb = 2028;   // 493 Hz
const int nC = 1912;   // 523 Hz
const int nR = 0;      // Define a special note, 'R', to represent a rest
int melody1[] = {nc};
int beats1[]  = {64};
int MAX_COUNT1 = sizeof(melody1) / 2; // Melody length, for looping.
int melody2[] = {nC};
int beats2[]  = {32};
int MAX_COUNT2 = sizeof(melody2) / 2; // Melody length, for looping.
int melody3[] = {ng};
int beats3[]  = {2};
int MAX_COUNT3 = sizeof(melody3) / 2; // Melody length, for looping.
long tempo = 5000;  // Set overall tempo
int pause = 5000;  // Set length of pause between notes
int rest_count = 100; // Loop variable to increase Rest length
// Initialize tone variables
int tone_ = 0;
int beat = 0;
long duration  = 0;

void beeper() {
  if (!disableBeeper) {
    // Set up a counter to pull from melody[] and beats[]
    for (int i = 0; i < MAX_COUNT3; i++) {
      tone_ = melody3[i];
      beat = beats3[i];
      duration = beat * tempo; // Set up timing
      playTone();
      // A pause between notes...
      delayMicroseconds(pause);
    }
  }
}

void playTone(void) {
  long elapsed_time = 0;
  if (tone_ > 0) { // if this isn't a Rest beat, while the tone has
    //  played less long than 'duration', pulse speaker HIGH and LOW
    while (elapsed_time < duration) {
      digitalWrite(buzzer_pin, HIGH);
      delayMicroseconds(tone_ / 2);
      // DOWN
      digitalWrite(buzzer_pin, LOW);
      delayMicroseconds(tone_ / 2);
      // Keep track of how long we pulsed
      elapsed_time += (tone_);
    }
  }
  else { // Rest beat; loop times delay
    for (int j = 0; j < rest_count; j++) { // See NOTE on rest_count
      delayMicroseconds(duration);
    }
  }
}

void minorAlarm() {
  if (!disableBeeper) {
    // Set up a counter to pull from melody[] and beats[]
    for (int i = 0; i < MAX_COUNT1; i++) {
      tone_ = melody1[i];
      beat = beats1[i];
      duration = beat * tempo; // Set up timing
      playTone();
      // A pause between notes...
      delayMicroseconds(pause);
    }
  }
}

void majorAlarm() {
  if (!disableBeeper) {
    // Set up a counter to pull from melody[] and beats[]
    for (int i = 0; i < MAX_COUNT2; i++) {
      tone_ = melody2[i];
      beat = beats2[i];
      duration = beat * tempo; // Set up timing
      playTone();
      // A pause between notes...
      delayMicroseconds(pause);
    }
  }
}

Here's my stock segmentation fault reply:

This bug is specific to the 5.4.0-atmel3.6.1-arduino2 version of avr-gcc used by Arduino AVR Boards 1.6.22 and newer. It has been reported here:

Here's the traditional workaround:

  • Tools > Board > Boards Manager
  • Wait for downloads to finish.
  • When you move the mouse pointer over "Arduino AVR Boards", you will see a "Select version" dropdown menu appear. Select "1.6.21".
  • Click "Install".
  • Wait for installation to finish.
  • Click "Close".

Due to a bug, this workaround doesn't work with Arduino IDE 1.8.6, but it will work with any other version of the Arduino IDE.

If you have File > Preferences > Check for updates on startup checked, the Arduino IDE may occasionally notify you that a new version of Arduino AVR Boards is available, you'll need to refrain from updating back to the new Arduino AVR Boards version, otherwise you'll be back to seeing the segmentation fault error again.

Alternate workaround:
One of the Arduino developers recently worked on this and claims to have fixed it. There is a special beta testing hardware package you can install via the Arduino IDE's Boards Manager that has the fix:

  • (In the Arduino IDE) File > Preferences
  • In the "Additional Boards Manager URLs" field, enter: http://downloads.arduino.cc/packages/package_avr_7.3.0_index.json If you already have an additional Boards Manager URL in that field, you can separate multiple URLs with commas or click the button on the right side of the field to open a dialog that allows you to add each on its own line.
  • Click "OK"
  • Tools > Board > Boards Manager
  • Wait for the downloads to finish
  • Click on "Arduino AVR Boards by Arduino"
  • Click the "Update" button.
  • Wait for the update to finish.
  • Click "Close".

KawasakiZx10r:
Deleting - uninstalling the 1.8.8 IDE and ALL its files except your sketches then installing an older version such as 1.6 is the only full fix.

IF you do remove all the files, you would only need to go back to Arduino IDE 1.8.5. However, many people don't realize that the Arduino IDE's Boards Manager installs hardware packages to a hidden folder on their computer. If you have Arduino AVR Boards 1.6.22 or newer installed there, changing Arduino IDE versions won't matter.

KawasakiZx10r:
Changing the board manager version for each platform does not fix it either.

I've been closely tracking many reports of this bug from the very start (I was the first person to experience it, back during beta testing) and you're the first I've heard say that. For everyone else, using Boards Manager to roll back to Arduino AVR Boards 1.6.21 made the error go away and the IDE version was not a factor.

Thank you to everyone that responded! KawasakiZx10r you were very helpful and I was able to fix the errors and thank you for the tip on the Tones also very helpful and will use! :slight_smile: