JavaScript EjsS code examples on using Accelerometer Model Element
Afrânio Coelho
2 Posts
Hello,
We have an undergraduate project for creating an Ejss model by using the Accelerometer model element. We wonder to buid a model that allows high school students to do experimental activities at home with their smartphones. For instance, they could use a smartphone as a pendulum bob to study harmonic oscillations or as a body in a free fall. So, have anyone ever made an ejss model that includes the Accelerometer model element? Could you send us the code in order to read and analyse it as an example?
Re: JavaScript EjsS code examples on using Accelerometer Model Element -
Wolfgang
192 Posts
Afrânio-- We do not yet have a model element to read phone sensors, such as the accelerometer, in EjsS. You must write your own code, or import an external JavaScript library, to do this.
Re: Re: JavaScript EjsS code examples on using Accelerometer Model Element -
Afrânio Coelho
2 Posts
Dear Prof. Wolfgang,
As a matter of fact, we could not build a simulation for EjsS by using the so called Accelerometer Element. You are right, we need to develop such an interface in order to integrate it with EjsS. Unfortunately, as you can read from the other colleagues on this thread, the model suggested by Prof. Esquembre did not work.
I strongly suggest the OSP/EjsS community to colaborate in writing such a code interface. That could allow to build interesting EjsS simulations that could contribute to a active physics learning, even outside the school environment.
Re: Re: Re: Re: JavaScript EjsS code examples on using Accelerometer Model Element -
Wolfgang
192 Posts
The accelerometer example that Paco posted works on my Apple iPhone 5 when the example is run in the EjsS Reader available from the Apple iTunes store. As Paco points out, you must use the Reader because a browser cannot access the local hardware due to security restrictions.
The compiled app is attached to this post. I do not have access to an Android device and would be most appreciative if someone would test this model in the Android Reader.
Re: JavaScript EjsS code examples on using Accelerometer Model Element -
Francisco Esquembre
237 Posts
Afrânio,
Attached is an example that illustrates the use of the Accelerometer model element. HOWEVER, for this to work correctly, you must run the simulation using the EjsSApp (which you can get from iTunes or Google Play stores, the Free version would do). The app provides access to the hardware and passes it to our model element.
Trying to run the simulation as a regular web page will not work, since HTML pages cannot access the hardware for security reasons.
Re: JavaScript EjsS code examples on using Accelerometer Model Element -
Hedler Barreto
2 Posts
Dear teacher Esquembre , I could not run the model . The graph of the accelerometer does not works. it seems that the model can not access the accelerometer. I run model with Ejss Reader pro. Please check. Thanks!
Re: JavaScript EjsS code examples on using Accelerometer Model Element -
Wolfgang
192 Posts
The Accelerometer example works in the iOS EJS Reader app on both iPads and iPhones. As shown in the attached screen shot, the app displays an arrow that indicates the direction of the acceleration and the vector components of the acceleration. Please make sure that you are running the Reader version 3.01.06 or above.