Skip to content

Commit aa0c7b5

Browse files
authored
Create light-sensor-tower.py
1 parent cb5daf4 commit aa0c7b5

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from busio import I2C
2+
import analogio
3+
from adafruit_seesaw.seesaw import Seesaw
4+
from adafruit_seesaw.pwmout import PWMOut
5+
from adafruit_motor import motor
6+
import board
7+
import time
8+
9+
light = analogio.AnalogIn(board.LIGHT)
10+
11+
12+
print("Theramin-like turning")
13+
14+
# Create seesaw object
15+
i2c = I2C(board.SCL, board.SDA)
16+
seesaw = Seesaw(i2c)
17+
18+
# Create one motor on seesaw PWM pins 22 & 23
19+
motor_a = motor.DCMotor(PWMOut(seesaw, 22), PWMOut(seesaw, 23))
20+
motor_a.throttle = 0 # motor is stopped
21+
22+
def map_range(x, in_min, in_max, out_min, out_max):
23+
# Maps a number from one range to another.
24+
mapped = (x-in_min) * (out_max - out_min) / (in_max-in_min) + out_min
25+
if out_min <= out_max:
26+
return max(min(mapped, out_max), out_min)
27+
return min(max(mapped, out_max), out_min)
28+
29+
while True:
30+
print((light.value,))
31+
motor_a.throttle = map_range(light.value, 500, 8000, 1.0, 0)
32+
time.sleep(0.1)
33+

0 commit comments

Comments
 (0)