Pages: [1]   Go Down
Author Topic: Theramin Program  (Read 628 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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.

* Tone.cpp (11.5 KB - downloaded 7 times.)
* Tone.h (3.23 KB - downloaded 7 times.)
« Last Edit: December 26, 2012, 10:13:17 pm by Coding Badly » Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8646
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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".
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
God Member
*****
Karma: 2
Posts: 711
a, b = b, a+b
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

posting the error message you receive will help us help you.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
« Last Edit: December 27, 2012, 07:08:52 am by PaulS » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!!
Logged

Pages: [1]   Go Up
Jump to: