Skip to content

Commit

Permalink
feat: examples
Browse files Browse the repository at this point in the history
  • Loading branch information
boutreet committed Jan 24, 2024
1 parent f9af575 commit a0953a3
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 6 deletions.
3 changes: 0 additions & 3 deletions examples/buzzer.py

This file was deleted.

4 changes: 4 additions & 0 deletions examples/buzzer_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""lets the buzzer work"""
from leaphymicropython.actuators.buzzer import set_buzzer

set_buzzer(1, 255, 1000)
7 changes: 7 additions & 0 deletions examples/dht22_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Reads the DHT22 sensor and returns temperature and humidity"""
from leaphymicropython.sensors.dht22 import DHT22

sensor = DHT22(1)
while True:
print(sensor.read_temperature())
print(sensor.read_humidity())
7 changes: 7 additions & 0 deletions examples/linesensor_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Reads the line sensor"""
from leaphymicropython.sensors.linesensor import read_line_sensor
from time import sleep

while True:
print(read_line_sensor(1))
sleep(1)
10 changes: 10 additions & 0 deletions examples/rbgled_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""Lets the rgb-led blink"""
from leaphymicropython.actuators.rgbled import RGBLed
from time import sleep

led = RGBLed(1, 2, 4)
while True:
led.set_color(255, 0, 0)
sleep(1)
led.set_color(0, 0, 0)
sleep(1)
4 changes: 4 additions & 0 deletions examples/servo_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Lets the servo rotate to 90 degrees"""
from leaphymicropython.actuators.servo import set_servo_angle

set_servo_angle(1, 90)
7 changes: 7 additions & 0 deletions examples/sonar_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Reads the distance"""
from leaphymicropython.sensors.sonar import read_distance
from time import sleep

while True:
print(read_distance(1))
sleep(1)
4 changes: 4 additions & 0 deletions examples/wifi_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Lets you connect to the wifi and prints a ip address"""
from leaphymicropython.utils.wifi import connect

connect("wifi name","wifi password")
5 changes: 3 additions & 2 deletions leaphymicropython/actuators/buzzer.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from leaphymicropython.utils.pins import set_pwm


def set_buzzer(pin: int, freq: int):
def set_buzzer(pin: int, value: int, freq: int):
"""
Sets the buzzer
:param pin: int, the pin of the buzzer
:param value: int, the value of the buzzer
:param freq: int, the frequency of the buzzer
"""
if freq < 0 or freq > 255:
raise ValueError("Buzzer values must be in between 0 and 255")
set_pwm(pin, 255, freq)
set_pwm(pin, value, freq)
2 changes: 1 addition & 1 deletion leaphymicropython/actuators/servo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from leaphymicropython.utils.boards_config import pin_to_gpio


def servo_angle(pin: int, angle: int) -> None:
def set_servo_angle(pin: int, angle: int) -> None:
"""
Puts the servo on an angle
:param pin: The pin number to which the servo motor is connected
Expand Down

0 comments on commit a0953a3

Please sign in to comment.