The MMM-Swipe
program is a MagicMirror addon module.
This module uses 2 HC-SR04 ultrasonic sensors to determing hand position to produce a "Swipe Left" or "Swipe Right"
This is a fork of MMM-Swipe by shbatm. Thank you to shbatm and mochman, who created the initial module, for their work.
- Uses
onoff
node module instead ofmmm-usonic
andmmm-gpio
- No SUDO required
- Sensors/detection can be started/stopped automatically with the
autoStart
configuration option, or can be started/stopped by sending a notification from another module: e.g.:this.sendNotification("SWIPE_CONTROL", "START")
. - Testing scripts included in the
usonic
folder if you want to play around with the sensors. Run them usingnode usonic/testingXXX.js
from the MMM-Swipe folder. Also includes a script to usepigpio
instead ofonoff
(still requires sudo).
NOTE: After my (Simon089) changed, AutoStart is not implemented anymore. I also never used the tests in the usonic
directory so I do not know if they still work, but I will leave them in here, if someone wants to use them.
- Different method to detect a swipe
- Some small displaying changes
- Make it compatible to MMM-Pages
- Wiring I kept shbatm's idea of using only one trigger pin, but I wired my sensors with only one 1k Ohm resistor per sensor (see image)
- Execute
git clone https://github.com/Simon089/MMM-Swipe.git
in yourmodules
folder cd
into it andnpm install
To use this module, add it to the modules array in the config/config.js
file:
modules: [
{
module: 'MMM-Swipe',
position: 'bottom_center',
config: {
// See 'Configuration options' for more information.
// trigger pin triggers both ultrasonic sensors
triggerPin: 23,
// both echo pins, use side the sensor is when you look at the mirror
echoLeftPin: 24,
echoRightPin: 26,
// everything < leftDistance/rightDistance is considered as a recognized object (e.g. your hand)
leftDistance: 50,
rightDistance: 50,
// everything > maxDistance is an invalid measurement
maxDistance: 200,
// writes the sensed distances on the mirror
calibrate: false,
// outputs measurements for a swipe in the console log
verbose: false,
}
}
]
This module will use sendNotification(notification, payload)
to change pages with the MMM-Pages module mentioned above.
notification = PAGE_INCREMENT
for a Swipe Right
and notification = PAGE_INCREMENT
for a Swipe Left
.
payload
will always be empty, since MMM-Pages ignores it for these two notifications.
The following properties can be configured:
Option | Description | Default Value |
---|---|---|
triggerPin | Trigger pin for both sensors. | 23 |
echoLeftPin | Left sensor's echo pin. | 24 |
echoRightPin | Right Sensor's Trigger pin. | 26 |
leftDistance | Distance in cm that will initiate the movement detection with the left sensor. | 50 |
rightDistance | Distance in cm that will initiate the movement detection with the right sensor. | 50 |
maxDistance | Distance in cm. Every measurement higher than this will be ignored. | 200 |
sampleInterval | Interval in ms for the sensors while no movement is detected. |
300 |
swipeSpeed | Duration in ms how long a swipe lasts |
800 |
calibrate | This will dispay the distances read by your sensors on the screen so you can use a leftDistance and rightDistance that works for you. |
false |
verbose | Will display swipe data to the console for testing the swipe detection. | false |