Wavefront icon Wavefront Wavefront grid planner computes collision-free, deterministic paths from start to goal using known occupancy maps for indoor robots. Try it →
Asked
Smoothing micro:bit PWM from Slide Script

Smoothing Micro:Bit PWM From Slide Script

I’m trying to do live brightness control of a small 12V LED strip segment from a BBC micro:bit connected to ARC over USB. I flashed the micro:bit firmware for ARC, added the Micro:bit board, and I’m driving the strip through a logic-level N-MOSFET on P1 (common ground between the 12V supply and the micro:bit). I’m using the Slide Script skill with Min=0, Max=255, and the variable name set to $led_level. In the On Value Changed script I’m simply doing:

# Slide Script On Value Changed
$level = $led_level
PWM(P1, $level)

If I set a single value from the EZ-Script Console, like PWM(P1, 180), the brightness is steady and looks fine. But when I drag the Slide Script slider, I see noticeable flicker and sometimes lag (it feels like commands queue up). Also, when I originally tried P0, I got audible chirps from the built-in speaker and weird ghosting on the 5x5 LED matrix; moving to P1 mostly fixed that, but the flicker while sliding remains. I’m assuming the rapid On Value Changed callbacks are spamming PWM updates.

A few specifics I’m unsure about: is the PWM() range truly 0-255 for the micro:bit in ARC, or should I be using 0-100? Is there a way to change PWM frequency on the micro:bit via ARC to reduce visible flicker, or is it fixed by the firmware? And is there a recommended way to debounce/throttle the Slide Script output (e.g., only send when the change exceeds a threshold or every X ms) without writing a separate background script?

How can I throttle or debounce Slide Script updates and ensure I’m using the correct PWM command/range so the micro:bit on P1 drives the LED strip smoothly without flicker or interference from the LED matrix/speaker?



Related Hardware (view all EZB hardware)
Connect BBC Micro:bit to Synthiam ARC via USB. Access GPIO, LEDs, buttons; upload Arduino firmware for I2C, SPI and analog sensors.
USB
Servos Varies
Camera
Audio
UART
I2C
ADC 3
Digital 16

Related Robot Skills (view all robot skills)
PWM Slider by Synthiam
Slider to set EZ-B digital PWM for motor speed or LED brightness; shows duty-cycle, stop button, and board/port selection.
Slide Script by Synthiam
Adjust a numeric variable via slider (0-1000) with customizable min/max, center button and scripts triggered on value change or bonus button press.

ARC Pro

Upgrade to ARC Pro

Join the ARC Pro community and gain access to a wealth of resources and support, ensuring your robot's success.

Author Avatar
PRO
Canada
Twitter YouTube GitHub
#1  

Yes - what you’re seeing is very likely slider spam, not a wiring issue.

Key points first

  • ARC PWM uses a 0-100 duty cycle range, not 0-255.
  • The Slide Script On Value Set Script can fire very quickly while you drag, which can cause visible flicker or lag if you send PWM on every tiny change.
  • On the micro:bit, some pins share functions with the 5x5 LED matrix and buttons, which is why P0 caused weird behavior. P1 is a much better choice.
  • ARC’s micro:bit firmware does not provide a user-accessible PWM frequency setting from the ARC PWM command. The PWM behavior is handled by the firmware/controller side.

Use the correct PWM range

If you’re using ARC’s PWM() / PWM.set() style control, the expected range is:

  • 0 to 100 = duty cycle percentage

So if your slider is currently set to 0-255, you should change it to 0-100 unless you intentionally want to scale it yourself.

Better setup for Slide Script

Set:

  • Min = 0
  • Max = 100
  • Variable = $led_level

Then use:

PWM(P1, $led_level)

If you really want the slider to stay 0-255 for UI reasons, map it before sending PWM:

var level = Math.round($led_level / 255 * 100);
PWM(P1, level);

Throttling the Slide Script updates

There isn’t a built-in debounce option in Slide Script settings, but you can throttle inside the script.

Simple threshold filter

Only send PWM if the change is significant:

var level = $led_level;
var last = getVar("$last_led_level", -1);

if (Math.abs(level - last) >= 3) {
  setVar("$last_led_level", level);
  PWM(P1, level);
}

Time-based throttle

Only update every 50 ms, for example:

var now = Utility.getTime();
var lastTime = getVar("$last_led_time", 0);

if ((now - lastTime) > 50) {
  setVar("$last_led_time", now);
  PWM(P1, $led_level);
}

If your environment doesn’t expose a simple time value the way you expect, the most reliable approach is usually:

  • add a small threshold, and/or
  • use a separate script that reads the variable at a fixed interval

Best practice for smooth brightness

For the smoothest result, I’d recommend:

  1. Set Slide Script range to 0-100
  2. Use P1 instead of P0
  3. Update only when value changes enough
    For example, every 2-5 steps
  4. Keep the LED strip powered from the 12V supply
  5. Make sure the MOSFET gate has a proper gate resistor/pull-down if needed

Why P0 caused extra weirdness

That makes sense on micro:bit because some pins are multiplexed with onboard features:

  • P0, P1, P2 are the most common beginner-friendly pads
  • Some other pins, and even some behavior on the board, can conflict with the display or buttons
  • P0 is especially known to be "busy" in some micro:bit use cases, so your move to P1 was the right call

About PWM frequency

For ARC’s micro:bit firmware, I wouldn’t expect a user-adjustable PWM frequency setting from the PWM command. If visible flicker remains after throttling, it’s usually due to:

  • command rate too high
  • LED strip power issues
  • MOSFET gate not switching cleanly
  • strip too long / current draw causing voltage sag

If you want, I can help you build a clean ARC setup using:

  • Slide Script for the value input
  • a small JavaScript throttle script
  • PWM.set(P1, value) with proper scaling

A couple quick questions so I can tailor the fix:

  1. Are you using the Slide Script skill’s On Value Set Script, or a separate script skill?
  2. Is your LED strip a single-color 12V analog strip segment, or an addressable strip?
  3. Do you want the slider to feel "live" as you drag, or is slightly delayed but smooth acceptable?

If you want, I can write you a ready-to-paste ARC JavaScript example that smooths the updates.

I am a customer support AI and still learning. Please verify important answers in our support documentation. For advanced AI features, use the AI Script Agent built into ARC.