Is this right or am I Goofing

Thanks for all help received

(Here’'s the code what was causing problems - Moderator)
my full code is

#include <SPI.h>
#include <avr/pgmspace.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(9, 8, 7, 6, 5, 4);


// Registers
#define REG_Product_ID                           0x00
#define REG_Revision_ID                          0x01
#define REG_Motion                               0x02
#define REG_Delta_X_L                            0x03
#define REG_Delta_X_H                            0x04
#define REG_Delta_Y_L                            0x05
#define REG_Delta_Y_H                            0x06
#define REG_SQUAL                                0x07
#define REG_Pixel_Sum                            0x08
#define REG_Maximum_Pixel                        0x09
#define REG_Minimum_Pixel                        0x0a
#define REG_Shutter_Lower                        0x0b
#define REG_Shutter_Upper                        0x0c
#define REG_Frame_Period_Lower                   0x0d
#define REG_Frame_Period_Upper                   0x0e
#define REG_Configuration_I                      0x0f
#define REG_Configuration_II                     0x10
#define REG_Frame_Capture                        0x12
#define REG_SROM_Enable                          0x13
#define REG_Run_Downshift                        0x14
#define REG_Rest1_Rate                           0x15
#define REG_Rest1_Downshift                      0x16
#define REG_Rest2_Rate                           0x17
#define REG_Rest2_Downshift                      0x18
#define REG_Rest3_Rate                           0x19
#define REG_Frame_Period_Max_Bound_Lower         0x1a
#define REG_Frame_Period_Max_Bound_Upper         0x1b
#define REG_Frame_Period_Min_Bound_Lower         0x1c
#define REG_Frame_Period_Min_Bound_Upper         0x1d
#define REG_Shutter_Max_Bound_Lower              0x1e
#define REG_Shutter_Max_Bound_Upper              0x1f
#define REG_LASER_CTRL0                          0x20
#define REG_Observation                          0x24
#define REG_Data_Out_Lower                       0x25
#define REG_Data_Out_Upper                       0x26
#define REG_SROM_ID                              0x2a
#define REG_Lift_Detection_Thr                   0x2e
#define REG_Configuration_V                      0x2f
#define REG_Configuration_IV                     0x39
#define REG_Power_Up_Reset                       0x3a
#define REG_Shutdown                             0x3b
#define REG_Inverse_Product_ID                   0x3f
#define REG_Motion_Burst                         0x50
#define REG_SROM_Load_Burst                      0x62
#define REG_Pixel_Burst                          0x64

byte initComplete=0;
byte testctr=0;
unsigned long currTime;
unsigned long timer;
volatile int xydat[2];
volatile byte movementflag=0;
const int ncs = 10;
int x_left = adns_read_reg(REG_Delta_X_L);       
int y_down = adns_read_reg(REG_Delta_Y_L);
int y_up = adns_read_reg(REG_Delta_Y_H);
int x_right = adns_read_reg(REG_Delta_X_H);
int x_count =0;
int y_count =0; 

extern const unsigned short firmware_length;
extern prog_uchar firmware_data[];

void setup() {
  Serial.begin(9600);
  
  lcd.begin(20, 4);
  lcd.clear();
  
  pinMode (ncs, OUTPUT);
  pinMode (A0, OUTPUT);
  pinMode (A1, OUTPUT); 
  pinMode (A2, OUTPUT); 
  pinMode (A3, OUTPUT); 
  
  attachInterrupt(0, UpdatePointer, FALLING);
  
  SPI.begin();
  SPI.setDataMode(SPI_MODE3);
  SPI.setBitOrder(MSBFIRST);
  SPI.setClockDivider(8);

  performStartup();  
  dispRegisters();
  delay(100);
  initComplete=9;

}

void adns_com_begin(){
  digitalWrite(ncs, LOW);
}

void adns_com_end(){
  digitalWrite(ncs, HIGH);
}

byte adns_read_reg(byte reg_addr){
  adns_com_begin();
  
  // send adress of the register, with MSBit = 0 to indicate it's a read
  SPI.transfer(reg_addr & 0x7f );
  delayMicroseconds(100); // tSRAD
  // read data
  byte data = SPI.transfer(0);
  
  delayMicroseconds(1); // tSCLK-NCS for read operation is 120ns
  adns_com_end();
  delayMicroseconds(19); //  tSRW/tSRR (=20us) minus tSCLK-NCS

  return data;
}

void adns_write_reg(byte reg_addr, byte data){
  adns_com_begin();
  
  //send adress of the register, with MSBit = 1 to indicate it's a write
  SPI.transfer(reg_addr | 0x80 );
  //sent data
  SPI.transfer(data);
  
  delayMicroseconds(20); // tSCLK-NCS for write operation
  adns_com_end();
  delayMicroseconds(100); // tSWW/tSWR (=120us) minus tSCLK-NCS. Could be shortened, but is looks like a safe lower bound 
}

void adns_upload_firmware(){
  // send the firmware to the chip, cf p.18 of the datasheet
  Serial.println("Uploading firmware...");
  // set the configuration_IV register in 3k firmware mode
  adns_write_reg(REG_Configuration_IV, 0x02); // bit 1 = 1 for 3k mode, other bits are reserved 
  
  // write 0x1d in SROM_enable reg for initializing
  adns_write_reg(REG_SROM_Enable, 0x1d); 
  
  // wait for more than one frame period
  delay(10); // assume that the frame rate is as low as 100fps... even if it should never be that low
  
  // write 0x18 to SROM_enable to start SROM download
  adns_write_reg(REG_SROM_Enable, 0x18); 
  
  // write the SROM file (=firmware data) 
  adns_com_begin();
  SPI.transfer(REG_SROM_Load_Burst | 0x80); // write burst destination adress
  delayMicroseconds(15);
  
  // send all bytes of the firmware
  unsigned char c;
  for(int i = 0; i < firmware_length; i++){ 
    c = (unsigned char)pgm_read_byte(firmware_data + i);
    SPI.transfer(c);
    delayMicroseconds(15);
  }
  adns_com_end();
  }


void performStartup(void){
  adns_com_end(); // ensure that the serial port is reset
  adns_com_begin(); // ensure that the serial port is reset
  adns_com_end(); // ensure that the serial port is reset
  adns_write_reg(REG_Power_Up_Reset, 0x5a); // force reset
  delay(50); // wait for it to reboot
  // read registers 0x02 to 0x06 (and discard the data)
  adns_read_reg(REG_Motion);
  adns_read_reg(REG_Delta_X_L);
  adns_read_reg(REG_Delta_X_H);
  adns_read_reg(REG_Delta_Y_L);
  adns_read_reg(REG_Delta_Y_H);
  // upload the firmware
  adns_upload_firmware();
  delay(10);
  //enable laser(bit 0 = 0b), in normal mode (bits 3,2,1 = 000b)
  // reading the actual value of the register is important because the real
  // default value is different from what is said in the datasheet, and if you
  // change the reserved bytes (like by writing 0x00...) it would not work.
  byte laser_ctrl0 = adns_read_reg(REG_LASER_CTRL0);
  adns_write_reg(REG_LASER_CTRL0, laser_ctrl0 & 0xf0 );
  
  delay(1);

  Serial.println("Optical Chip Initialized");
  }

void UpdatePointer(void){
  if(initComplete==9){

    digitalWrite(ncs,LOW);
    xydat[0] = (int)adns_read_reg(REG_Delta_X_L);
    xydat[1] = (int)adns_read_reg(REG_Delta_Y_L);
    digitalWrite(ncs,HIGH); 
    movementflag=1;
    }
  }

void dispRegisters(void){
  int oreg[7] = {
    0x00,0x3F,0x2A,0x02  };
  char* oregname[] = {
    "Product_ID","Inverse_Product_ID","SROM_Version","Motion"  };
  byte regres;

  digitalWrite(ncs,LOW);

  int rctr=0;
  for(rctr=0; rctr<4; rctr++){
    SPI.transfer(oreg[rctr]);
    delay(1);
    Serial.println("---");
    Serial.println(oregname[rctr]);
    Serial.println(oreg[rctr],HEX);
    regres = SPI.transfer(0);
    Serial.println(regres,BIN);  
    Serial.println(regres,HEX);  
    delay(1);
  }
  digitalWrite(ncs,HIGH);
}


int convTwosComp(int b){
  //Convert from 2's complement
  if(b & 0x80){
    b = -1 * ((b ^ 0xff) + 1);
    }
  return b;
  }
  
  
  int tdistance = 0;
  void loop() {
  if(movementflag){
    lcd.clear();
    tdistance = tdistance + convTwosComp(xydat[0]);
    Serial.println("Distance = " + String(tdistance));
    lcd.print(String(tdistance));
    movementflag=0;
    delay(3);
     if ( x_left ==0) {
    x_count = x_right ; 
  while (x_count !=0){
    digitalWrite(A0,High);
    digitalWrite (A0,Low);
     x_count = x_count -1 ;
  }}
  else if ( x_right ==0){    
    x_count = x_left ; 
    while (x_count !=0){
    digitalWrite(A1,High);
    digitalWrite (A1,Low);
     x_count = x_count -1 ;
    }
delay(3);
  }
  if ( y_up ==0) {
    y_count = y_down ; 
  while (y_count !=0){
    digitalWrite(A2,High);
    digitalWrite (A2,Low);
     y_count = y_count -1 ;
  }
  }
  else if ( y_down ==0){    
   y_count = y_up ; 
    while (y_count !=0){
    digitalWrite(A3,High);
    digitalWrite (A3,Low);
     y_count = y_count -1 ;
    }
  }
delay(3);
  
    }
  }

I would suggest you try to compile that code (and it's very clear you have NOT done that...), then you won't need anyone else to tell you if there's anything wrong with it....

Regards, Ray L.

The main problem I see in your code is that you put data types in the conditional part of some IF statements: if (int x_left ==0) {

Remove 'int'.

The variable is declared in UpdatePointer so it only exists inside that function. It looks like you intended those variables to be global so you could reference them in any function. To do that you have to move the declaration outside of the functions.

Dear " Ray L " the original code already did annoy me when it was attempting to be compiled , i tried every thing for days , until on this forum someone told me that the problem is the libraries and the version of compiler that is relatively my first Arduino code , and i am an last a semester Student engineer not mainly a programmer i indeed didn't try compile it at first , but that was because i was in harry , and my experience in the programming field is nearly zero , i knew that it would not compile any way , so i thought for to ask an advice from those who would see a mistake , just in case i was only asking for help from only those who are willing to give it ! sorry to annoy you !

Dear " johnwasser"
you were right that reduced the error
bust still an error saying :
sketch_feb23a.ino: In function ‘void loop()’:
sketch_feb23a:250: error: ‘High’ was not declared in this scope
sketch_feb23a:251: error: ‘Low’ was not declared in this scope
sketch_feb23a:257: error: ‘High’ was not declared in this scope
sketch_feb23a:258: error: ‘Low’ was not declared in this scope
sketch_feb23a:266: error: ‘High’ was not declared in this scope
sketch_feb23a:267: error: ‘Low’ was not declared in this scope
sketch_feb23a:274: error: ‘High’ was not declared in this scope
sketch_feb23a:275: error: ‘Low’ was not declared in this scope

is that because i am using analog pins as digital output ?

sketch_feb23a:250: error: ‘High’ was not declared in this scope
sketch_feb23a:251: error: ‘Low’ was not declared in this scope

They’re usually spelled “HIGH” and “LOW”

This could be a problem:

delayMicroseconds(1); // tSCLK-NCS for read operation is 120ns

Caveats and Known Issues

This function works very accurately in the range 3 microseconds and up. We cannot assure that delayMicroseconds will perform precisely for smaller delay-times.

These kinds of statements towards the end of the sketch:

    digitalWrite(A2,High);
    digitalWrite (A2,Low);

need to use HIGH and LOW, just as you did earlier in the sketch.

Dear " johnwasser “, " AWOL” and “CrossRoads”"

“High” &" Low " really appeared to be a fatal mistake

i changed the delay time to 3 microseconds

thanks " johnwasser " , “AWOL” , “CrossRoads” and even thank you “RayLivingston”

It compiled >Really appreciate it guys <
:grin: :grin: :grin: :grin: :grin: :grin:

You'll catch those kinds of errors on your own with some more coding practice. = and == will trip you up as well.

Wow, thanks to the OP for completely removing the OP.

I read a lot of these threads to learn for myself, and it's difficult when the original question is removed. NEVER do that. Makes any poster after that edit look like an idiot at times.

Next time, just add [Solved] to the thread title.

@AhmedUsama: Don’t EVER do that again.