Skip to content

Instantly share code, notes, and snippets.

@faaaaabi
Created October 29, 2018 09:08
Show Gist options
  • Save faaaaabi/941e38326b24bd2b23c6979186386080 to your computer and use it in GitHub Desktop.
Save faaaaabi/941e38326b24bd2b23c6979186386080 to your computer and use it in GitHub Desktop.
Function for MicroPython on ESP32 which generates PWM signal on given pin. Based on: http://docs.micropython.org/en/latest/esp8266/quickref.html#pwm-pulse-width-modulation
def do_led_pulse(nPulses, pin):
import machine
import time, math
led = machine.PWM(machine.Pin(pin), freq=1000)
for j in range(pulses):
for i in range(20):
led.duty(int(math.sin(i / 10 * math.pi) * 500 + 500))
time.sleep_ms(50)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment