diff --git a/README.md b/README.md index bdcf627..78cc6f5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![logo](https://static.creatordev.io/logo-md-s.svg) +![logo](https://avatars2.githubusercontent.com/u/18185398?s=200&v=4) # PyLetMeCreate @@ -57,3 +57,10 @@ thermo3.disable() # Release I2C i2c.release() ``` + +## This repository is no longer maintained. + +Issue reports and pull requests will not be attended. + +--- + diff --git a/letmecreate/click/__init__.py b/letmecreate/click/__init__.py index 560cfb4..a04815d 100644 --- a/letmecreate/click/__init__.py +++ b/letmecreate/click/__init__.py @@ -11,6 +11,7 @@ - CO - Color - Color2 + - DC motor - Eve - Fan - GYRO @@ -32,7 +33,7 @@ """ __all__ = ['seven_seg', 'led_matrix', 'accel', 'adc', 'air_quality', 'alcohol', - 'bargraph', 'co', 'color', 'color2', 'eve', 'fan', 'gyro', - 'ir_distance', 'ir_eclipse', 'joystick', 'light', 'lin_hall', 'lora', - 'motion', 'oled', 'proximity', 'relay', 'relay2', 'relay4', 'rtc', - 'thermo3', 'uni_hall'] + 'bargraph', 'co', 'color', 'color2', 'dc_motor', 'eve', 'fan', + 'gyro', 'ir_distance', 'ir_eclipse', 'joystick', 'light', + 'lin_hall', 'lora', 'motion', 'oled', 'proximity', 'relay', + 'relay2', 'relay4', 'rtc', 'thermo3', 'uni_hall'] diff --git a/letmecreate/click/dc_motor.py b/letmecreate/click/dc_motor.py new file mode 100644 index 0000000..10f9456 --- /dev/null +++ b/letmecreate/click/dc_motor.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python3 +"""Python binding of DC motor Click wrapper of LetMeCreate library.""" + +import ctypes + +_LIB = ctypes.CDLL('libletmecreate_click.so') + + +def init(mikrobus_index): + """Initialise the DC motor click. + + mikrobus_index: must be 0 (MIKROBUS_1) or 1 (MIKROBUS_2) + + Note: An exception is thrown if it fails to initialise the board. + """ + ret = _LIB.dc_motor_click_init(mikrobus_index) + if ret < 0: + raise Exception("dc motor click init failed") + + +def set_direction(mikrobus_index, direction): + """Change the direction of the motor. + + mikrobus_index: must be 0 (MIKROBUS_1) or 1 (MIKROBUS_2) + direction: must be 0 (reverse) or 1 (forward + + Note: An exception is thrown if it fails to change the direction. + """ + ret = _LIB.dc_motor_click_set_direction(mikrobus_index, direction) + if ret < 0: + raise Exception("dc motor click set direction failed") + + +def get_direction(mikrobus_index): + """Returns the direction of the motor. + + mikrobus_index: must be 0 (MIKROBUS_1) or 1 (MIKROBUS_2) + + Note: An exception is thrown if it fails to get the direction. + """ + direction = ctypes.c_uint8() + ret = _LIB.dc_motor_click_set_direction(mikrobus_index, + ctypes.byref(direction)) + if ret < 0: + raise Exception("dc motor click get direction failed") + return direction.value + + +def set_speed(mikrobus_index, speed): + """Change the speed of the motor. + + mikrobus_index: must be 0 (MIKROBUS_1) or 1 (MIKROBUS_2) + speed: floating point value in range 0..100 + + Note: An exception is thrown if it fails to change the speed. + """ + ret = _LIB.dc_motor_click_set_speed(mikrobus_index, speed) + if ret < 0: + raise Exception("dc motor click set speed failed") + + +def get_speed(mikrobus_index): + """Returns the speed of the motor. + + mikrobus_index: must be 0 (MIKROBUS_1) or 1 (MIKROBUS_2) + + Note: An exception is thrown if it fails to get the speed. + """ + speed = ctypes.c_float() + ret = _LIB.dc_motor_click_get_speed(mikrobus_index, ctypes.byref(speed)) + if ret < 0: + raise Exception("dc motor click get speed failed") + return speed.value + + +def release(mikrobus_index): + """Release the DC motor click. + + Stops the motor. + + Note: An exception is thrown if it fails to release + """ + ret = _LIB.dc_motor_click_release(mikrobus_index) + if ret < 0: + raise Exception("dc motor click release failed")