Education Prize Logo
Science SPORE Prize
November 2011

NSF Logo
The Open Source Physics Project is supported by NSF DUE-0442581.

Arduino DC Motor controlled by EJS post and replies

Return to the Arduino DC Motor controlled by EJS thread
Login to post to this thread

Arduino DC Motor controlled by EJS - Mar 24 at 2:46PM
Mirka Kouka
5 Posts


I want to control the speed of a DC Motor using the arduino element of the EJS.

In the Initialization page I have the following command: arduino.setDigitalMode(9,3); which according to the documentation sets the mode of a digital pin 9 to PWM.

Then in the fixed relations page I have the command: arduino.writeDigital(9,speed); where speed is an integer variable with values between 0 and 255.

I get a compilation error by this second command "Some messages have been simplified; recompile with -Xdiags:verbose to get full output"

Does anyone know what's wrong with my code?

Thank you!

Replies to Arduino DC Motor controlled by EJS

Re: Arduino DC Motor controlled by EJS - Mar 26 4:19PM
Francisco Esquembre
222 Posts

writeDigital(int pinNumber, boolean state) is used for a digital output.
What you want is to generate a PWM output. Therefore, you need to use the command
writeDigitalValue(int pinNumber, int value), instead.


Re: Re: Arduino DC Motor controlled by EJS - Mar 27 1:52AM
Mirka Kouka
5 Posts


thank you very much for your help. It worked with your suggestion.

The confusion was because of the arduino documentation in ejs. It refers to a function writeDigital(int pinNumber, boolean state) and to another function writeDigital(int pinNumber, int value).

Thanks again!

The OSP Network:
Open Source Physics - Tracker - EJS Modeling
Physlet Physics
Physlet Quantum Physics