B4J Question PWM on Raspy (Comfile)

micro

Well-Known Member
Licensed User
Longtime User
Hi to all
I'm testing a Comfile product (ComfilePI) with raspy inside and 7" touch dispaly.
this has a buzzer connected to GPIO 30 piloted in PWM
This is an example in C ++, how can I turn it into B4J?
B4X:
#include <pigpiod_if2.h>
#include <thread>
using namespace std;
#define PIN 30
void play_beep()
{
   auto instance = pigpio_start(NULL, NULL);
   // We actually can't achieve 2700Hz due to the sampling
   // rate, but it will do the best it can
   set_PWM_frequency(instance, PIN, 2700);
   // 128/255 = 50% duty
   set_PWM_dutycycle(instance, PIN, 128);
   // play beep for 100 milliseconds
   this_thread::sleep_for(chrono::milliseconds(100));
   // turn off beep
   set_PWM_dutycycle(instance, PIN, 0);
   pigpio_stop(instance);
}

I never used the pwm function on raspberry
Thanks
 

micro

Well-Known Member
Licensed User
Longtime User
I tried
Into AppStart
B4X:
Dim jo As JavaObject
jo.InitializeStatic("com.pi4j.wiringpi.SoftPwm")
jo.RunMethod("softPwmCreate", Array (30, 0, 2700))
Beep
.......

Into Beep
B4X:
Public Sub Beep
    Dim jo As JavaObject
    jo.InitializeStatic("com.pi4j.wiringpi.SoftPwm")
    jo.RunMethod("softPwmWrite", Array (30, 50))
    Sleep(500)
    jo.RunMethod("softPwmWrite", Array (30, 0))
End Sub

But not work!
where I am wrong?
Thanks
 
Upvote 0

micro

Well-Known Member
Licensed User
Longtime User
a slight beep....wrong values?
jo.RunMethod("softPwmCreate", Array (pin, value, range))
PWM_frequency (2700) in range it's correct?
value is the initial value on pin or duty_cycle?
Thanks
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…