mraa_pwm_context setupPWMO( int pinNumber ) { on = 0; mraa_pwm_context pwmo = mraa_pwm_init( pinNumber ); if ( ! pwmo ) { printf( " Failed initing pwmo\n" ); mraa_result_print( MRAA_ERROR_UNSPECIFIED ); return 0; } response = mraa_pwm_enable( pwmo, 0 ); // Initially off if (response != MRAA_SUCCESS) { // printf( " Failed setting pwmo enable to off during setup\n" ); mraa_result_print((mraa_result_t) response); return 0; } response = mraa_pwm_config_percent( pwmo, 100, 0.25 ); // Startup settings, 0.1 second, 50% duty cycle if (response != MRAA_SUCCESS) { // printf( " Failed setting pwmo period and duty cycle\n" ); mraa_result_print((mraa_result_t) response); return 0; } response = mraa_pwm_enable( pwmo, 1 ); // Now enable it if (response != MRAA_SUCCESS) { // printf( " Failed setting pwmo enable to on during setup\n" ); mraa_result_print((mraa_result_t) response); return 0; } // printf( " Inited pwmo for pin %d\n", pinNumber ); return pwmo; }
/** * Set the period and duty (percent) of a PWM object. * * @param period as represented in ms. * @param duty percentage i.e. 50% = 0.5f * @return Result of operation */ mraa_result_t config_percent(int period, float duty) { return mraa_pwm_config_percent(m_pwm, period, duty); }