why is this code wrong?

code:

<int x_rot_pin = 14; //declare var
int y_rot_pin=15; //same w/ different var
int z_accel_pin=16; //....
int ledpin=13;
//led light
void setup()
{
pinMode (x_rot_pin,INPUT); //sets pins as inputs and outputs
pinMode(y_rot_pin,INPUT);
pinMode(z_accel_pin,INPUT);
pinMode(ledpin,OUTPUT);
}

void loop () //cuz do is retarded..
{
do

{

int x = analogRead(x_rot_pin); // the microproscessor is told to read these pins

int y = analogRead(y_rot_pin); //
int z_accel = analogRead(z_accel_pin);
x = xx;
y = y
y;
int xy = x+y;
int t = sqrt(xy); //added two axial vectors to get a radius of tilt

}
while (t <= 45 && z_accel <= .5);

digitalWrite(ledpin,HIGH);
delay(5000);
digitalWrite(ledpin,LOW);
}>
btw carrots weren't in the code im a noob and i just keep getting bombarded with errors mostly while/main but i have no idea how to solve this pls help :frowning:

Well, for one, I can see a mismatched {} pair -- the { after "do" isn't matched.

i took your advice to added the bracket b4 while (blablabla) but now i get error in that while section; it says that the t variable hasn't defined after being defined in the line above? whats going on? if someone could maybe paste and compile it on their environment successfully they would be my hero. srsly no matter how mod it it keeps requesting the while statements before my math section?

The variables t and z_accel are local to the { block } inside the do{} while(). As such, they are not visible to the while expression. To fix this, syntactically, you could do

void loop ()
{ 
  [b]int t, z_accel;[/b]
  do 
  { 
    int x = analogRead(x_rot_pin);    // the microprocessor is told to read these pins 
    int y = analogRead(y_rot_pin);    //  
    [b]z_accel = analogRead(z_accel_pin); [/b]
    x = x*x; 
    y = y*y; 
    int xy = x+y; 
    [b]t = sqrt(xy);  //added two axial vectors to get a radius of tilt[/b]
    ...

Whether this is logically what you want, I can't say. :slight_smile:

Mikal