From a0f39067ee873e4cda7f7654031970a26e48d9ae Mon Sep 17 00:00:00 2001 From: norpol <hidden@tld.invalid> Date: Tue, 10 Sep 2019 18:52:50 +0200 Subject: [PATCH] Add smooth vibrate --- pycardium/modules/py/meson.build | 1 + pycardium/modules/py/smooth_vibrate.py | 51 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 pycardium/modules/py/smooth_vibrate.py diff --git a/pycardium/modules/py/meson.build b/pycardium/modules/py/meson.build index d2669a19..fa858b7d 100644 --- a/pycardium/modules/py/meson.build +++ b/pycardium/modules/py/meson.build @@ -9,6 +9,7 @@ python_modules = files( 'pride.py', 'ledfx.py', 'simple_menu.py', + 'smooth_vibrate.py', # MicroPython Standard-Library 'col_defaultdict.py', diff --git a/pycardium/modules/py/smooth_vibrate.py b/pycardium/modules/py/smooth_vibrate.py new file mode 100644 index 00000000..7aa28119 --- /dev/null +++ b/pycardium/modules/py/smooth_vibrate.py @@ -0,0 +1,51 @@ +import vibra +import utime + + +def vi(dur, sle): + """ + helper for repeater() + see repeater() params + """ + vibra.vibrate(dur) + utime.sleep_ms(sle) + + +def repeater(times, dur, sle): + """ + trigger vibration motor with three values + times => how often we should triger + dur => how long should we trigger for each iteration + sle => how long should we wait in between + + combination out of this creates a fake PWM + that enables easy and smooth vibrations + """ + for i in range(times): + vi(dur, sle) + + +def simple(): + """ + simple() is a short way of vibration + for example for button push/change status suitable + """ + repeater(5, 5, 10) + + +def select(): + """ + select() is a little longer, but smoother + good for communicating something got selected + """ + repeater(10, 5, 20) + + +def pattern(n=None): + """ + very distinctive but long pattern + feels like duk-duk-duk + n = 2 and n = 1 feels the same + """ + n = n or 3 + repeater(n, 20, 100) -- GitLab