Hi i am building a laserharpjr, i am searching for some working sketch and i cannot find it anywhere i followed radioshacks design, built my own frame etc etc, now i need working code for my chip to work i am still refreshing my brain back to the old c++ so it's a bit tough for me, much easier to reverse engineer if you know what i mean, simply for learning purposes as i could never claim the laserharpjr as my own it is already claimed, this is all for learning purposes that is all, any help anyone to working sketch and a step by step path to putting it on the brain? 3/uno
Do you have a schematic? Hard to suggest code for an invisible project.
#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);
}
Found it on the forums but im stuck still
You've defined DEBUG as a const. Don't you want it to change to true sometimes?
Nowhere have you changed it to true, so none of your if(DEBUG) statements will ever run.
you have to spell it out for me... my brain works slow, but accurate
Relevant link:
http://forum.arduino.cc/index.php/topic,198662.0.html
Seems there are a number of steps the Radio Shack PDF glosses over.
ok ill follow that route till i hit another dead end, thanks brolaf i will stay in touch
Awsome it came out in white text no errors your the man! im getting the hang of it its all comin back to me now