How to set sampling rate?

I need to record vibration data (I need to plot vibration signal in future) with Arduino Due and I am new. I used one axis accelerometer sensor (ADXL001) that attach the output of sensor (Xout) to pin A3, and used +3.3 V and ground on Due board. I need to record data with sampling rate 10kHz and bit resolution 12 bit. So, I write code as below

int Pin=A3; //Input Pin
int Volt= 3.3; // 3.3 Power Supply on Arduino Due 
float volts; 

void setup() {
  
  Serial.begin(9600); 
}

void loop() {

  analogReadResolution(12); // set bit resolution
  int val=analogRead(analogPin);
  float volts;=(val/4095.0)*arefVolt;
  Serial.print(val);
  Serial.print(",");
  Serial.print(volts);
  delay(1); // *****

}

1.My question is, can i set sampling rate with delay code (like in ***** line) or have another way to set it?

2.When vibrating/shaking the sensor, why the results in serial monitor look like not any changes?

Thanks

Try to use interrupt , in an interrupt the code will stop automitcally and read or do what you want it to do without any delays etc, search about interrupts if you get stuck feel free to ask me

Chandni_M:
1.My question is, can i set sampling rate with delay code (like in ***** line) or have another way to set it?

I'd say, you can do NOTHING that is required to do that job, just by looking at this line of code:

int Volt= 3.3; // 3.3 Power Supply on Arduino Due

Perhaps you better start learning some basics of programming first, i.e. about different numerical data types.