I assembled the hardware exactly as described in the instructions and am using an iMac with OS X Lion 10.7.5
I have no experience with code. I thought this was a straight forward project and did not require any programming knowledge. If anyone can help, I would very much appreciate it.
Here is the code...
#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_G3;
sensor[1].pin = A1;
sensor[1].note = NOTE_D4;
sensor[2].pin = A2;
sensor[2].note = NOTE_A4;
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);
}
And this is the error message(s) I get:
RS_DIY_LaserHarpJr:17: error: 'Tone' does not name a type
RS_DIY_LaserHarpJr.ino: In function 'void setup()':
RS_DIY_LaserHarpJr:25: error: 'NOTE_G3' was not declared in this scope
RS_DIY_LaserHarpJr:27: error: 'NOTE_D4' was not declared in this scope
RS_DIY_LaserHarpJr:29: error: 'NOTE_A4' was not declared in this scope
RS_DIY_LaserHarpJr:31: error: 'notePlayer' was not declared in this scope
RS_DIY_LaserHarpJr.ino: In function 'void loop()':
RS_DIY_LaserHarpJr:57: error: 'notePlayer' was not declared in this scope
RS_DIY_LaserHarpJr:59: error: 'notePlayer' was not declared in this scope
First guess is that you haven't place the folder the files 'Tone.h' and 'Tone.cpp' came in into the correct place required for Libraries.
If you'll bring up the preferences you'll see a field named "Sketchbook Location". Going to that location and you'll find a folder labeled 'libraries'. Place the folder with the files 'Tone.h' and 'Tone.cpp' into that "libraries" folder.
Ok, I downloaded it again and put it in the libraries folder. When I do, it is displayed in the column to the right, but it is in the libraries folder.
Next I followed the instructions and it says, "Open the “LaserHarpJr.ino” file with your Arduino software and click the right-arrow button (next to the
check button). Some LEDs should blink on the Arduino board, and after a few moments, you should
see “Done Uploading” in the console area of the Arduino software. Your sketch should now be running!"
But when I do that, I get an "Error Compiling" message instead of "Done Uploading":
core.a(main.cpp.o): In function main': /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/main.cpp:11: undefined reference to setup'
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/main.cpp:14: undefined reference to `loop'
Screen Shot 2013-01-30 at 6.09.11 PMAs recommended, I put the RS_DIY_LaserHarpJr.ino into the RS_DIY_LaserHarpJr folder. I tried to name it RS_DIY_LaserHarpJr/ but the system didn't like the /.
I still got the "Error compiling" message.
I attached 2 screen-shots to be able to include all of the code and the error message.
I have all the equipment, but when I attempt to upload or verify the sketch, I get multiple errors.
Here is the sketch:
#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_G3;
sensor[1].pin = A1;
sensor[1].note = NOTE_D4;
sensor[2].pin = A2;
sensor[2].note = NOTE_A4;
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);
}
The errors I receive are as follows:
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp: In member function 'void Tone::begin(uint8_t)':
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:121: error: 'bitWrite' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:123: error: 'digitalPinToPort' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:123: error: 'portOutputRegister' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:124: error: 'digitalPinToBitMask' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp: In member function 'void Tone::play(uint16_t, uint32_t)':
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:198: error: 'OUTPUT' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:198: error: 'pinMode' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:294: error: 'bitWrite' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp: In member function 'void Tone::stop()':
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:361: error: 'digitalWrite' was not declared in this scope
How should I go about fixing these errors?
Any help would be greatly appreciated! Thank you very much.
I downloaded the 1.5.4 version, and am still receiving these errors:
Arduino: 1.5.4 (Windows NT (unknown)), Board: "Arduino Mega 2560 or Mega ADK"
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp: In member function 'void Tone::begin(uint8_t)':
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:121: error: 'bitWrite' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:123: error: 'digitalPinToPort' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:123: error: 'portOutputRegister' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:124: error: 'digitalPinToBitMask' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp: In member function 'void Tone::play(uint16_t, uint32_t)':
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:198: error: 'OUTPUT' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:198: error: 'pinMode' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:294: error: 'bitWrite' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp: In member function 'void Tone::stop()':
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:361: error: 'digitalWrite' was not declared in this scope
And here is the verbose version of the errors:
Arduino: 1.5.4 (Windows NT (unknown)), Board: "Arduino Mega 2560 or Mega ADK"
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp: In member function 'void Tone::begin(uint8_t)':
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:121: error: 'bitWrite' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:123: error: 'digitalPinToPort' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:123: error: 'portOutputRegister' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:124: error: 'digitalPinToBitMask' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp: In member function 'void Tone::play(uint16_t, uint32_t)':
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:198: error: 'OUTPUT' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:198: error: 'pinMode' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:294: error: 'bitWrite' was not declared in this scope
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp: In member function 'void Tone::stop()':
C:\Users\jdblair\Documents\Arduino\libraries\Tone\Tone.cpp:361: error: 'digitalWrite' was not declared in this scope