APS Excellence in Physics Education Award
November 2019

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
Mirka Kouka
5 Posts

Hello,

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 -
Francisco Esquembre
237 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.

Paco



Re: Re: Arduino DC Motor controlled by EJS -
Mirka Kouka
5 Posts

Paco,

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!



OSP Projects:
Open Source Physics - EJS Modeling
Tracker
Physlet Physics
Physlet Quantum Physics
STP Book