New to Arduino, Need Help Coding

Hello! I’m brand new to the Arduino, and I know nothing about C++. I’m trying to build something like a Theremin (http://en.wikipedia.org/wiki/Theremin). What I have hooked up is a Light sensor, a buzzer, and the main board. I’m not sure if its hooked up right because they both need the - output from the main baord so i’m just splitting it.

I’ve combined two sketches in an attempt to make the buzzer play different sounds when the light sensor gives in different data, as it is stored as a number. Here’s my

int ledPin = 13; // LED is connected to digital pin 13 
int sensorPin = 0; // light sensor is connected to analog pin 0 
int sensorValue; // variable to store the value coming from the sensor 
int speakerPin = 9; // speaker connected to digital pin 9 

      
void setup()    
{   
         pinMode(ledPin, OUTPUT); // sets the ledPin to be an output 
         Serial.begin(9600); //initialize the serial port 
         digitalWrite(ledPin, HIGH); // turn the LED on 
         pinMode(speakerPin, OUTPUT); // sets the speakerPin to be an output 
}    
      
void loop()  // run over and over again  
{    
          sensorValue = analogRead(sensorPin); // read the value from the sensor 
          Serial.println(sensorValue); // send that value to the computer 
          delay(1000); // delay for 1/10 of a second 
}     
  
void beep (unsigned char speakerPin, int frequencyInHertz, long timeInMilliseconds)     // the sound producing function  
{    
          int x;   
          long delayAmount = (long)(1000000/frequencyInHertz); 
          long loopTime = (long)((timeInMilliseconds*1000)/(delayAmount*2)); 
          for (x=0;x<loopTime;x++)   
          {   
              digitalWrite(speakerPin,HIGH); 
              delayMicroseconds(delayAmount); 
              digitalWrite(speakerPin,LOW); 
              delayMicroseconds(delayAmount); 
          }   

}     
     
void scale () 
{    
          digitalWrite(ledPin,HIGH); //turn on the LED 
          beep(speakerPin,sensorValue,500); //C: play the note C (C7 from the chart linked to above) for 500ms 
          digitalWrite(ledPin,LOW); //turn off the LED 
}

I’ve combined two tutorials I found here: http://web.media.mit.edu/~leah/LilyPad/index.html.

Can anyone help me figure this out?

You never call “beep” or “scale”.
There should be a call to them from “loop”

The Ardunio Lily Pad code code is C++ correct? The only language I know is Turing. :(

If I make a variable, say x, that the sensor value equals, can I also use it for the note to be played? Or is what I'm trying to do impossible?

The only language I know is Turing.

Sorry, I speak only C/C++ and occam. ;D

If I make a variable, say x, that the sensor value equals, can I also use it for the note to be played?

As always, it depends. If both parts of the code are in the scope of the variable, then yes.

Certainly, in your example, it should work, but as I said, you never explicitly call "scale", from "loop". That's the only way "scale" is going to get executed.

I don't want it to seem like I want you to do it for me, but can you give me some help on the program? C++ is strange to me, Turing is so simple compared to it, but i bet once i learn C++ it'll be easier.

Also, this is a stupid question, but if I hook up the Arduino like in my picture will it still work? With the two things hooked up to the negative.

http://img39.imageshack.us/img39/6394/sche.jpg

but if I hook up the Arduino like in my picture will it still work? With the two things hooked up to the negative.

Yes that hook-up will work. However there are three ground pins avalible on the Arduino pin connectors, look them over. Also make sure your buzzer doesn't require more then 40ma of current when on.

Lefty