When I try to compile anything using the Playtune library, I receive the following error message:
[....]/arduino/libraries/Playtune/Playtune.h:36:21: fatal error: arduino.h: No such file or directory
compilation terminated.
I did some research and determined that I should change "/avr/arduino.h" in the playtune files to "Arduino.h"--this solved the first error, but then I got another:
test.cpp:21:21: error: variable ‘score’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
I changed the following: byte PROGMEM score [] = { to const byte PROGMEM score [] = {, which solved the initial error, but once again a new problem arose:
test.cpp:192:27: error: invalid conversion from ‘const byte* {aka const unsigned char*}’ to ‘byte* {aka unsigned char*}’ [-fpermissive]
In file included from test.cpp:11:0:
/home/name/arduino/libraries/Playtune/Playtune.h:42:7: error: initializing argument 1 of ‘void Playtune::tune_playscore(byte*)’ [-fpermissive]
Having only a basic knowledge of C I have no real idea where to go from here... I assume the second error is referencing this:
class Playtune
{
public:
void tune_initchan (byte pin); // assign a timer to an output pin
void tune_playscore (byte *score); // start playing a polyphonic score
I tried adding "const" before the playscore function declaration, but that produces a new error:
/home/name/arduino/libraries/Playtune/Playtune.cpp:191:22: fatal error: playtune.h: No such file or directory
compilation terminated.
void tune_playscore (byte *score); // start playing a polyphonic score
to
void tune_playscore (const byte *score); // start playing a polyphonic score
Here is Playtune.h:
/**************************************************************************
*
* Playtune: An Arduino Tune Generator
* **********/
/*
* Change log
* 19 January 2011, L.Shustek, V1.0: Initial release.
* 10 June 2013, L. Shustek, V1.3
* - change to be compatible with Arduino IDE version 1.0.5
*/
#ifndef Playtune_h
#define Playtune_h
#include <Arduino.h>
class Playtune
{
public:
void tune_initchan (byte pin); // assign a timer to an output pin
void tune_playscore (byte *score); // start playing a polyphonic score
volatile static boolean tune_playing; // is the score still playing?
void tune_stopscore (void); // stop playing the score
void tune_delay (unsigned msec); // delay in milliseconds
void tune_stopchans (void); // stop all timers
};
#endif
PaulS:
What you need to do is cast away the const.
Do you mean that I should use the "const_cast" operator? I tried changing
void tune_playscore (byte *score); // start playing a polyphonic score
to
void tune_playscore (const_cast<byte*>(*score)); // start playing a polyphonic score
but I get the same error... Since Playtune.h is a C header file, does it support the const_cast operator? (which I thought was only in C++). Any further suggestions would be appreciated!!!
There is no reason to be diddling with the library. The tune_playscore() function expects a pointer to a byte array. You have a const pointer to a byte array. They are the same size. The function should not be diddling with the input pointer, so it should have declared that it doesn't by using const. It didn't, but that isn't essential.
const byte PROGMEM score[] = { // Some initializers... };
// Cast away the const-ness:
tune_playscore((byte *) score);
the original poster was talking about this library: Google Code Archive - Long-term storage for Google Code Project Hosting.
The project states it was updated to Arduino V1.0.x development environment in june 2013, but it seems things changed again since then. First now the include requires "Arduino.h", not "arduino.h" in lower case. Then I got the same errors. I tried to add this line after the initialisation (before the void setup()), but it's the same
tune_playscore((byte *) score);
test_nano.pde:174:15: error: expected constructor, destructor, or type conversion before ‘(’ token
test_nano.pde: In function ‘void loop()’:
test_nano.pde:192:27: error: invalid conversion from ‘const byte* {aka const unsigned char*}’ to ‘byte* {aka unsigned char*}’ [-fpermissive]
In file included from test_nano.pde:11:0:
/home/farvardin/arduino/libraries/playtune/Playtune.h:42:7: error: initializing argument 1 of ‘void Playtune::tune_playscore(byte*)’ [-fpermissive]
void tune_playscore (byte *score); // start playing a polyphonic score