Now I have Arduino uno R3 , and ADXL 330 3-axis accelerometer .
I can read 3-axis value ( ex: 230 240 299 ) .
The following are my questions :
1 . How many bits or bytes do 3-axis value have ?
2 . How could I let the code read 1 second and stop 2 seconds , use timer or interrupt ?
( i .e : read 1 second 3-axis value , after stop 2 seconds , continuous read 1 second 3-axis , and loop... )
The attach is my read 3-axis value code , how could I modify the code ?
If anyone have something problem on the topic , please tell me , thanks .
kobe1117:
I can read 3-axis value ( ex: 230 240 299 ) .
The following are my questions :
1 . How many bits or bytes do 3-axis value have ?
One byte, or 8 bits, can store an unsigned number from 0 to 255. However, as it appears each axis is an integer value from 0 359 you will need at least 9 bits. So the easiest ways to store the data would be either an int type variable for each axis, or an array of three int variables. There are more space efficient methods, but they will make your code more complex and shouldn't be needed unless you are really low on storage space.
kobe1117:
2 . How could I let the code read 1 second and stop 2 seconds , use timer or interrupt ?
( i .e : read 1 second 3-axis value , after stop 2 seconds , continuous read 1 second 3-axis , and loop... )
I'm still a little unclear exactly what you are trying to accomplish, but hardware interrupts (the type usually ment by "interrupt") are triggered by voltage changes on specific pins. They allow the microcontroller to react to the outside world very quickly, so if you wanted to get the axis data as soon as one changed an interrupt would be good for that. However, it appears you want to read the values for 1 second with an interval of 2 seconds. Therefore, if you want the IC read from a device to follow any kind of predetermined schedule you should use some sort of timer.
The exact code is going to depend on how you are communicating with the accelerometer. Does the Arduino have to send a signal to the ADXL 330 to tell it to send the axis data, or is it continously outputing the data and you just want to use it at specific intervals? In either case you will probably want to either use modified BlinkWithoutDelay code (this can be found in the Arduino IDE File>>Examples>>Digital>>BlinkWithoutDelay) or use one of the timer libraries.