Create time-light-temp.py

Initial commit
This commit is contained in:
Mike Barela 2018-08-02 09:00:14 -04:00 committed by GitHub
parent 0a9cf5c37c
commit f7fee72b40
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -0,0 +1,67 @@
# Circuit Playground Express Data Time/Light Intensity/Temp
# Log data to a spreadsheet on-screen
# Open Spreadsheet beforehand and position to start (A,1)
# Use slide switch to start and stop sensor readings
# Time values are seconds since board powered on (relative time)
import time
from digitalio import DigitalInOut, Direction, Pull
import analogio
import board
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
import adafruit_thermistor
# Switch to quickly enable/disable
switch = DigitalInOut(board.SLIDE_SWITCH)
switch.pull = Pull.UP
# light level
light = analogio.AnalogIn(board.LIGHT)
# temperature
thermistor = adafruit_thermistor.Thermistor(board.TEMPERATURE, 10000,
10000, 25, 3950)
# Set the keyboard object!
# Sleep for a bit to avoid a race condition on some systems
time.sleep(1)
kbd = Keyboard()
layout = KeyboardLayoutUS(kbd) # US is only current option...
led = DigitalInOut(board.D13) # Set up red LED "D13"
led.direction = Direction.OUTPUT
print("Time\tLight\tTemperature") # Print column headers
def slow_write(string): # Typing should not be too fast for
for c in string: # the computer to be able to accept
layout.write(c)
time.sleep(0.25) # use 1/4 second pause between characters
while True:
if switch.value: # If the slide switch is on, don't log
continue
# Turn on the LED to show we're logging
led.value = True
temp = thermistor.temperature # In Celsius
# if you want Fahrenheit, uncomment the line below
# temp = temp * 9 / 5 + 32
# Format data into value 'output'
output = "%0.1f\t%d\t%0.1f" % (time.monotonic(), light.value, temp)
print(output) # Print to serial monitor
slow_write(output) # Print to spreadsheet
kbd.press(Keycode.DOWN_ARROW) # Code to go to next row
time.sleep(0.01)
kbd.release_all()
for _ in range(3):
kbd.press(Keycode.LEFT_ARROW)
time.sleep(0.01)
kbd.release_all()
time.sleep(0.01)
led.value = False
# Add time.sleep(1.0) to wait more between samples
# Change 1.0 to whatever time you need