loading

Coding problems for Arduino...?

I am trying to set up an accelerometer with 3 LED lights that light up dependent on the Y axis reading... the following code I have but I am getting error messages relating to the "{" on some of my lines of code. Please please could someone enlighten me on whats going wrong or even if I have the right code!

/*  ADXL3xx    Reads an Analog Devices ADXL3xx accelerometer and communicates the  acceleration to the computer.  The pins used are designed to be easily  compatible with the breakout boards from Sparkfun, available from:  http://www.sparkfun.com/commerce/categories.php?c=80   http://www.arduino.cc/en/Tutorial/ADXL3xx  
The circuit: 
analog 0: accelerometer self test 
analog 1: z-axis 
analog 2: y-axis 
analog 3: x-axis 
nalog 4: ground 
analog 5: vcc   

created 2 Jul 2008  by David A. Mellis  modified 4 Sep 2010  by Tom Igoe   modified 21 Dec 2010   
This example code is in the public domain.

*/
// these constants describe the pins. They won't change:
const int groundpin = 18;             // analog input pin 18 -- ground const int powerpin = 19;              // analog input pin 19 -- voltage const int xpin = A3;                  // x-axis of the accelerometer const int ypin = A2;                  // y-axis const int zpin = A1;                  // z-axis (only on 3-axis models)  void setup()
const int ledPINKPin =  9;      // the number of the LED pin
const int ledBLUEPin = 10;
const int ledGREENPin = 11;
const int ypin = A2;                  // y-axis
{
                               // initialize the serial communications: 
Serial.begin(9600);                   // bluetooth baud rate  
 
pinMode(groundpin, OUTPUT);  
pinMode(powerpin, OUTPUT);  
digitalWrite(groundpin, LOW);   
digitalWrite(powerpin, HIGH);
 
 
// print the sensor values:  

//Serial.print("ypin: ");  
Serial.print(analogRead(ypin)); 
// print a tab between values:  
Serial.print("\t");  
//Serial.print("ypin: ");  

// delay before next reading:  
delay(2000);
}

if (analogRead(ypin) > 1000
then  
    // turn LED on:   
    digitalWrite(ledPINKPin, HIGH); 

  else {
    // turn LED off:
    digitalWrite(ledPINKPin, LOW);

{
if (analogRead(ypin) > 600
then  
    // turn LED on:   
    digitalWrite(ledGREENPin, HIGH); 
  }
  else {
    // turn LED off:
    digitalWrite(ledGREENPin, LOW);
   
if (analogRead(ypin) > 40
then  
    // turn LED on:   
    digitalWrite(ledBLUEPin, HIGH); 
  }
  else {
    // turn LED off:
    digitalWrite(ledBLUEPin, LOW);

First of all you have no void setup() or more importantly a void loop(). Until you get the void setup() and void loop() sorted out there will be too many errors to sort through.

But here are a couple i see right off. There may be many more but it will be hard to tell till you get the base elements in place.

Inside what should be the void setup() you have pinMode(powerpin, OUTPUT);. Yet you did not defined the powerpin variable when you where initiating your ground and LED pins.

You can't have the analogRead inside the Serial.print() command. You need to do the analogRead(ypin);, then Serial.print(ypin);
Ok i see the problem now. Your void setup is on the same line as a group of commented lines so the IDE doesn't see it. So is your powerpin line. Everything that should be the void setup line and above is all messed up. But you are still missing a void loop() line. Even if you don't want anything to loop you still need to put something like this at the end:
void loop()
{
}
Now i see all your if statements are messed up as well. In Arduino there is no If Then. For example your if statements should look like this:
if (analogRead(ypin) > 1000)
{
   // turn LED on: 
   digitalWrite(ledPINKPin, HIGH);
}
else {
  // turn LED off:
  digitalWrite(ledPINKPin, LOW);   
}
 
Your sketch should look like this:

/*  ADXL3xx    Reads an Analog Devices ADXL3xx accelerometer and communicates the  acceleration to the computer. 
The pins used are designed to be easily  compatible with the breakout boards from Sparkfun,
available from:  http://www.sparkfun.com/commerce/categories.php?c=80   http://www.arduino.cc/en/Tutorial/ADXL3xx 
The circuit:
analog 0: accelerometer self test
analog 1: z-axis
analog 2: y-axis
analog 3: x-axis
nalog 4: ground
analog 5: vcc  

created 2 Jul 2008  by David A. Mellis  modified 4 Sep 2010  by Tom Igoe   modified 21 Dec 2010  
This example code is in the public domain.

*/
// these constants describe the pins. They won't change:
const int groundpin = 18;             // analog input pin 18 -- ground
const int powerpin = 19;              // analog input pin 19 -- voltage
const int xpin = A3;                  // x-axis of the accelerometer
const int ypin = A2;                  // y-axis
const int zpin = A1;                  // z-axis (only on 3-axis models) 
const int ledPINKPin =  9;      // the number of the LED pin
const int ledBLUEPin = 10;
const int ledGREENPin = 11;


void setup()
{
                              // initialize the serial communications:
  Serial.begin(9600);                   // bluetooth baud rate 

  pinMode(groundpin, OUTPUT); 
  pinMode(powerpin, OUTPUT); 
  digitalWrite(groundpin, LOW);  
  digitalWrite(powerpin, HIGH);
}


void loop()
{
  // print the sensor values: 

  //Serial.print("ypin: "); 
  Serial.print(analogRead(ypin));
  // print a tab between values: 
  Serial.print("\t"); 
  //Serial.print("ypin: "); 

  // delay before next reading: 
  delay(2000);


  if (analogRead(ypin) > 1000)
  {
    // turn LED on:  
    digitalWrite(ledPINKPin, HIGH);
  }
  else
  {
    // turn LED off:
    digitalWrite(ledPINKPin, LOW);
  }
 
 
  if (analogRead(ypin) > 600)
  {
    // turn LED on:  
   digitalWrite(ledGREENPin, HIGH);
  } 
  else
  {
    // turn LED off:
    digitalWrite(ledGREENPin, LOW);
  }
  
  if (analogRead(ypin) > 40)
  {
    // turn LED on:  
    digitalWrite(ledBLUEPin, HIGH);
  }
  else
  {
    // turn LED off:
    digitalWrite(ledBLUEPin, LOW);
  }
}

Copy and paste that into the IDE and you'll be good to go as far as errors are concerned. Weather or not the code does what you want is another story.

Some of the annotation of comments looks very suspect for a start.
Are you sure you have posted the first 10 lines of the program correctly ?


Comments like this:

//Serial.print("ypin: ");
Serial.print(analogRead(ypin));

Are completely redundant.

What's bluetooth got to do with it ?