Skip to content

Commit 4ed218a

Browse files
committed
Updating light sensor code.
1 parent aa26746 commit 4ed218a

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

Introducing_CircuitPlaygroundExpress/CircuitPlaygroundExpress_LightSensor.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
# CircuitPlaygroundExpress_LightSensor
2-
# reads the on-board light sensor and graphs the brightness with NeoPixels
1+
# Circuit Playground Light Sensor
2+
# Reads the on-board light sensor and graphs the brightness with NeoPixels
33

44
import time
5-
65
import board
76
import neopixel
8-
from analogio import AnalogIn
9-
from simpleio import map_range
7+
import analogio
8+
import simpleio
109

11-
pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, auto_write=0, brightness=.05)
10+
pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=.05, auto_write=False)
1211
pixels.fill((0, 0, 0))
1312
pixels.show()
1413

15-
analogin = AnalogIn(board.LIGHT)
14+
light = analogio.AnalogIn(board.LIGHT)
1615

1716
while True:
1817
# light value remapped to pixel position
19-
peak = map_range(analogin.value, 2000, 62000, 0, 9)
20-
print(analogin.value)
18+
peak = simpleio.map_range(light.value, 2000, 62000, 0, 9)
19+
print(light.value)
2120
print(int(peak))
2221

2322
for i in range(0, 9, 1):

0 commit comments

Comments
 (0)