VE Lua Documentation

Press F to search!

pwm

Definition


-- @/lua/vehicle/electricsCustomValueParser.lua:35

function pwm(input, frequency, dutyCycle, timeOffset)
  -- Calculate the sine wave normalized to [0, 1] with a given frequency and phase (time) offset
  local sineWave = (sin(2 * pi * frequency * pwmTime + (timeOffset or 0)) + 1) / 2
  --Generate a pwm signal based on the duty cycle
  return (sineWave > (1 - dutyCycle)) and input or 0
end

Callers