Two accelerometers at once
Moskog
Posts: 554
Hello, I have a simple questions for you Prop-experts:
Im testing an accelerometer 2125 using this Object:
accel: "MXD2125 Simple"
Reading:
PUB Setup:
accel.start (X-outPin, Y-outPin)
This works great, but I need another accelerometer to be read at the same time.
Can I use the same Object or do I need to make another copy of MXD2125 Simple, so the whole thing will be like this:
OBJ
accel: "MXD2125 Simple"
accel2: "MXD2125 Simple2"
PUB Setup
accel.start (X-outPin, Y-outPin)
accel2.start (X-outPin2, Y-outPin2)
Is there a more simple way to do this?
Im testing an accelerometer 2125 using this Object:
accel: "MXD2125 Simple"
Reading:
PUB Setup:
accel.start (X-outPin, Y-outPin)
This works great, but I need another accelerometer to be read at the same time.
Can I use the same Object or do I need to make another copy of MXD2125 Simple, so the whole thing will be like this:
OBJ
accel: "MXD2125 Simple"
accel2: "MXD2125 Simple2"
PUB Setup
accel.start (X-outPin, Y-outPin)
accel2.start (X-outPin2, Y-outPin2)
Is there a more simple way to do this?
Comments
There is code in the ObEx which has problems to be started twice. I guess the graphics driver could be an example (maybe you can have several objects but they'd show the same graphics).
But usually objects can be "instanciated" more than once by the SAME SPIN filename. accel1, accel2 like you used it in your code is one way, using an object array is another one:
OBJ
acc[2]: "MXD2125 Simple"
Problems can occur if the object uses DAT variables that need to store different values per instance. And as in the TV driver if an object uses HUB-RAM to store different data but has a fixed HUB-RAM address.
Hope this helps.
Before reading the replies I was thinking about some modifications to the Object file to be able to handle to pairs of X- and Y-outputPins. In that case PUB Setup would start like this: accel.start ( X-outPin, Y-outPin, X2-outPin, Y2-outPin) I suppose that should work pretty well too.
I just connected the two accelerometers and programmed the Prop the way suggested by kf4ixm. It seems like that was the best solution because now I can read both of the 2125's easy and without any problems.
Thank you so much MaglO2, kf4ixm and JasonDorie for your replies!