Arduino Laser Harp - NEED HELP

Hello all!

I am creating a simple arduino laser harp for a class project and am having trouble with the arduino code.

I followed a link on the website with instructions to complete the project and this is the code give to me to add to the arduino:

#include <Tone.h>

const boolean DEBUG = false;

const int CALIBRATION_PIN = A5;
const int SPEAKER_PIN = 8;
const int SENSOR_COUNT = 3;

typedef struct
{
int pin;
int note;
} sensor_type;

sensor_type sensor[SENSOR_COUNT];

Tone notePlayer;

void setup(void)
{
if (DEBUG) {
Serial.begin(9600);
}
sensor[0].pin = A0; // analog input 0, etc…
sensor[0].note = NOTE_C4;
sensor[1].pin = A1;
sensor[1].note = NOTE_D4;
sensor[2].pin = A2;
sensor[2].note = NOTE_E4;

notePlayer.begin(SPEAKER_PIN);
}

void loop(void)
{
int calibration = analogRead(CALIBRATION_PIN);
if (DEBUG) {
Serial.print(“cal: “);
Serial.print(calibration);
}
int activeSensor = -1;
for (int p = 0 ; p < SENSOR_COUNT ; p++) {
int sensor_value = analogRead(sensor[p].pin);
if (DEBUG) {
Serial.print(”\tsensor “);
Serial.print(p);
Serial.print(”: “);
Serial.print(sensor_value);
}
if ( sensor_value < calibration ) {
activeSensor = p;
if (DEBUG) Serial.print(”!”); // “!” indicates note being played
}
}
if (DEBUG) Serial.println();
if (activeSensor == -1) {
notePlayer.stop();
} else {
notePlayer.play(sensor[activeSensor].note);
}
if (DEBUG) delay(1000);
}

However, I am getting compiling errors. Here they are:

C:\Users\Ashley\Documents\Arduino\libraries\Tone\Tone.cpp: In member function ‘void Tone::begin(uint8_t)’:
C:\Users\Ashley\Documents\Arduino\libraries\Tone\Tone.cpp:121: error: ‘bitWrite’ was not declared in this scope
C:\Users\Ashley\Documents\Arduino\libraries\Tone\Tone.cpp:123: error: ‘digitalPinToPort’ was not declared in this scope
C:\Users\Ashley\Documents\Arduino\libraries\Tone\Tone.cpp:123: error: ‘portOutputRegister’ was not declared in this scope
C:\Users\Ashley\Documents\Arduino\libraries\Tone\Tone.cpp:124: error: ‘digitalPinToBitMask’ was not declared in this scope
C:\Users\Ashley\Documents\Arduino\libraries\Tone\Tone.cpp: In member function ‘void Tone::play(uint16_t, uint32_t)’:
C:\Users\Ashley\Documents\Arduino\libraries\Tone\Tone.cpp:198: error: ‘OUTPUT’ was not declared in this scope
C:\Users\Ashley\Documents\Arduino\libraries\Tone\Tone.cpp:198: error: ‘pinMode’ was not declared in this scope
C:\Users\Ashley\Documents\Arduino\libraries\Tone\Tone.cpp:294: error: ‘bitWrite’ was not declared in this scope
C:\Users\Ashley\Documents\Arduino\libraries\Tone\Tone.cpp: In member function ‘void Tone::stop()’:
C:\Users\Ashley\Documents\Arduino\libraries\Tone\Tone.cpp:361: error: ‘digitalWrite’ was not declared in this scope

Any help would be appreciated!

Thanks :slight_smile:

Hi, have you got the tone library in the library directory of the IDE program? It seems to be looking for it but can't find it.

Tom..... :)