Skip to content

Commit 147d70e

Browse files
authored
Add accelerometer control for servo movement
Implement accelerometer and servo control logic.
1 parent 0ce58f8 commit 147d70e

File tree

1 file changed

+42
-0
lines changed
  • Crickits/Feather_Crickit_Accelerometer

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# SPDX-FileCopyrightText: 2018 Dave Astels for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import time
6+
import busio
7+
import board
8+
from adafruit_seesaw.seesaw import Seesaw
9+
from adafruit_seesaw.pwmout import PWMOut
10+
from adafruit_motor import servo
11+
import adafruit_lsm9ds0
12+
13+
# Setup hardware
14+
i2c = busio.I2C(board.SCL, board.SDA)
15+
16+
sensor = adafruit_lsm9ds0.LSM9DS0_I2C(i2c)
17+
seesaw = Seesaw(i2c)
18+
19+
# Create servo objects
20+
pwm1 = PWMOut(seesaw, 17)
21+
pwm1.frequency = 50
22+
servo1 = servo.Servo(pwm1, min_pulse=500, max_pulse=2500)
23+
24+
# Center the servo
25+
servo1.angle = 90
26+
27+
while True:
28+
# Read the accel
29+
x, y, z = sensor.acceleration
30+
31+
# Clip the value
32+
if y < -10:
33+
y = -10
34+
if y > 10:
35+
y = 10
36+
37+
# print(((y / 10) + 1) * 90)
38+
39+
# Set the angle
40+
servo1.angle = ((-y / 10) + 1) * 90
41+
42+
time.sleep(0.1)

0 commit comments

Comments
 (0)