AppShed / ioio-cordova-plugin

Cordova plugin to a access a IOIO
MIT License
2 stars 3 forks source link

Pulse Width Duty Cycle #2

Open randynwalsh opened 9 years ago

randynwalsh commented 9 years ago

Can any tell me if this code supports the ability to set the duty cycle on a pulse modulation? I'd like to be able to control some servos.

Thank you in advance!

Randy

w-zx commented 8 years ago

Hi, Randy. I'm trying to use this plugin to control some LEDs. Have you found the way to control the pwm duty cycle?

randynwalsh commented 8 years ago

No, unfortunately not. I used an Arduino instead. On Apr 6, 2016 2:00 AM, "Tsehsuan Wang" notifications@github.com wrote:

Hi, Randy. I'm trying to use this plugin to control some LEDs. Have you found the way to control the pwm duty cycle?

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/AppShed/ioio-cordova-plugin/issues/2#issuecomment-206196752

w-zx commented 8 years ago

I took a look at the code, and I found this in src/com/appshed/ioioplugin/services/IOIOCOmmunicationService.java line 117:

@Override
protected void setup() throws ConnectionLostException,InterruptedException {
    led_ = ioio_.openDigitalOutput(IOIO.LED_PIN);
    for(Integer pinPort:pins.keySet()){
        Pin pin = pins.get(pinPort);
        if(pin instanceof PinPwmOutput){ // PinPwmOutput
            PinPwmOutput pinPwmOutput = (PinPwmOutput)pin;
            pinPwmOutput.pwmOutput = ioio_.openPwmOutput(pinPort, PWN_MAX_FREQ);
...

and this in line 151:

Pin pin = pins.get(pinPort);
    if(pins.get(pinPort) instanceof PinPwmOutput){ // PinPwmOutput
    PinPwmOutput pinPwmOutput = (PinPwmOutput)pins.get(pinPort);
    pinPwmOutput.pwmOutput.setPulseWidth(pinPwmOutput.freq);
    try {
        parameters.put(pinPwmOutput.getJson());
} catch (Exception e) {}

It seems that the author set up the pwmOutput with the PWN_MAX_FREQ(which is 10000), and the functionsetPwnOutputis to set the plusewidth. But the problem is that I currently don't have an IOIO to test this function because I have to wait a few more days to get one. So is setPwnOutput only set the frequency of the pwn output?