19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
printf("setup wiringPi failed !");
return 1;
}
pinMode(Z_Pin,INPUT); //set Z_Pin as input pin and pull-up mode
pullUpDnControl(Z_Pin,PUD_UP);
pcf8591Setup(pinbase,address); //initialize PCF8591
while(1){
val_Z = digitalRead(Z_Pin); //read digital quality of axis Z
val_Y = analogRead(A0); //read analog quality of axis X and Y
val_X = analogRead(A1);
printf("val_X: %d ,\tval_Y: %d ,\tval_Z: %d \n",val_X,val_Y,val_Z);
delay(100);
}
return 0;
}
In the code, configure Z_Pin to pull-up input mode. In while cycle of main function, use analogRead () to
read the value of axis X and Y and use digitalRead () to read the value of axis Z, then print them out.
while(1){
val_Z = digitalRead(Z_Pin); //read digital quality of axis Z
val_Y = analogRead(A0); //read analog quality of axis X and Y
val_X = analogRead(A1);
printf("val_X: %d ,\tval_Y: %d ,\tval_Z: %d \n",val_X,val_Y,val_Z);
delay(100);
}