Go Down

Topic: Theramin Program (Read 711 times) previous topic - next topic

mstei

Dec 27, 2012, 03:49 am Last Edit: Dec 27, 2012, 04:13 am by Coding Badly Reason: 1
Hey all,
   I'm working on one of those radioshack DIYs for a theramin instrument. They provided the code, but i cant seem to get it working. Some of the problems may be linked to the tone library. (e.g. "void tone" errors) Others seem to be just missing bits and undeclared functions. I'm pretty new at this, so I'd REALLY appreciate if someone could help me get this up and running. Please and Thank You in advance! I'm posting the code below and attaching the tone library if anyone is willing to help. Thanks.




//Heres what I have so far:

Code: [Select]
#include <Tone.h>
Tone tone1;
//our array of note frequencies
int note[] = {   
NOTE_C3, NOTE_D3, NOTE_E3, NOTE_F3, NOTE_G3, NOTE_A3, NOTE_B3, 
NOTE_C4, NOTE_D4, NOTE_E4, NOTE_F4, NOTE_G4, NOTE_A4, NOTE_B4,
NOTE_C5, NOTE_D5, NOTE_E5, NOTE_F5, NOTE_G5, NOTE_A5, NOTE_B5,
NOTE_C6, NOTE_D6, NOTE_E6, NOTE_F6, NOTE_G6, NOTE_A6, NOTE_B6, NOTE_C7  };
int pingPin = 7;
int tonePin = 10;
int inches;
int pingDuration;
 
void setup()
{
  tone1.begin(tonePin);      //attach tone1 to tonePin
  Serial.begin(9600);
}
 
void loop()
{
  pingDuration = getPing();                      //read the PING)))
  inches = microsecondsToInches(pingDuration); //convert to inches
   
  Serial.print(inches);
  Serial.print("in, ");
  Serial.println();
  if (inches > 3 && inches < 34)             //only play if distance is 4 to 33 inches
  {
    tone1.play(note[29 - (inches - 4)]);
  }  else if(tone1.isPlaying())  {
    tone1.stop();
  }
  delay(100);
}
int getPing()
{
  //send a 10us pulse to wake up the sonar
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(10);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(pingPin, LOW);
   
  //get the raw value from the sonar, corresponding to the
  //actual time of travel of the ultrasound waves
  pinMode(pingPin, INPUT);
  return pulseIn(pingPin, HIGH);  //return this value
   
 
}
int microsecondsToInches(int microseconds)
{
  // return the duration divided by 74, the time in milliseconds
  // it takes sound to travel one inch out and back, then divided by two
  // since we only want the inches to the obstacle.
  return microseconds / 74 / 2;
   
}


Moderator edit: [code] [/code] tags added.

johnwasser

I suspect that tone library has not been updated for Arduino 1.0.  Often the only change needed is to replace "WProgram.h" with "Arduino.h".
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

fkeel

posting the error message you receive will help us help you.
http://embodimentlabs.tumblr.com/
http://paulstrohmeier.info/

mstei

Thanks for the quick replies. Any idea how I edit the tone library to make those changes?

also, the error messages:

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

PaulS

#4
Dec 27, 2012, 01:05 pm Last Edit: Dec 27, 2012, 01:08 pm by PaulS Reason: 1
Did you read reply #1? Did you do anything about it?

Why are you downloading another Tone library, when on comes with the core Arduino code?

notsoyyo

Hi,

Was this ever resolved? I am having a similar issue. The library is not recognized at all when I use your code (which is the sample code).At best, I get this error: sketch_jan04i:1: error: 'Tone' does not name a type
sketch_jan04i:4: error: 'NOTE_C3' was not declared in this scope




Thanks!!

Go Up