
-----------------------------------
Harblkipz
Sun May 31, 2009 5:22 pm

Arduino &amp; C++
-----------------------------------
Hey Compsci, I have an Arduino set and I want to build a mini optical light Theremin. I have a buzzer, light sensor, and the main board. The coding for the Arduino though is C++ (Hence why I'm here). I know nothing about C++ coding, all I know is Turing, I have a mixed up code that doesn't work, I was wondering if anyone could possibly fix the bugs in it. I got the code from to examples from this site: http://web.media.mit.edu/~leah/LilyPad/index.html  

Here's the [code]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