-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccelleratiometer with switch
64 lines (51 loc) · 1.67 KB
/
accelleratiometer with switch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import board
import busio
import digitalio
import os
import adafruit_sdcard
import storage
import adafruit_lsm6ds.lsm6ds33
import microcontroller
import time
import neopixel
#Initialisierung der SD Karte
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
#use a digitalio pin 10 for breakout wiring:
cs = digitalio.DigitalInOut(board.D10)
sdcard = adafruit_sdcard.SDCard(spi, cs)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")
led = digitalio.DigitalInOut(board.BLUE_LED)
led.direction = digitalio.Direction.OUTPUT
i2c = board.I2C()
lsm6ds33 = adafruit_lsm6ds.lsm6ds33.LSM6DS33(i2c)
neo = neopixel.NeoPixel(board.NEOPIXEL, 1)
neo.brightness = 0.3
button=digitalio.DigitalInOut(board.SWITCH)
button.direction = digitalio.Direction.INPUT
button.pull = digitalio.Pull.UP
status=1
altbutton=0
print("Acceleration: {:.2f} {:.2f} {:.2f} m/s^2".format(*lsm6ds33.acceleration))
print("Logging acceleration to filesystem")
# append to the file!
while True:
if button.value!=altbutton:
status+=1
else:
status=status
if status/2 %2==0:
neo[0] = (0, 255, 0)
# open file for append
with open("/sd/acceleration.csv", "a") as f:
led.value = True # turn on LED to indicate we're writing to the file
print("{},{:.2f},{:.2f},{:.2f}\n".format(time.monotonic(),*lsm6ds33.acceleration))
f.write("{},{:.2f},{:.2f},{:.2f}\n".format(time.monotonic(),*lsm6ds33.acceleration))
led.value = False # turn off LED to indicate we're done
# file is saved
else:
neo[0] = (255, 0, 0)
altbutton=button.value
print(button.value)
print(status)
time.sleep(0.1)