ELEC60013-ES-CW1/main.py

37 lines
736 B
Python
Raw Normal View History

2022-02-26 22:36:47 +00:00
from lis3dh import *
2022-03-01 14:26:58 +00:00
from datetime import datetime
2022-03-01 16:06:12 +00:00
import signal
import sys
import RPi.GPIO as GPIO
2022-02-26 19:51:43 +00:00
print("Raspberry Pi Zero W, up and running!")
2022-02-26 23:05:48 +00:00
bus = smbus2.SMBus(1)
2022-03-01 14:33:09 +00:00
accel = lis3dh(bus,2,1)
2022-02-26 19:51:43 +00:00
print("LIS3DH initiated successfully!")
2022-03-01 16:06:12 +00:00
INT1 = 18
INT2 = 17
def signal_handler(sig,frame):
GPIO.cleanup()
sys.exit(0)
def int1_callback(channel):
# do something here
GPIO.setmode(GPIO.BCM)
# # Data logging
# now = datetime.now()
# date_time = now.strftime("%d_%m_%Y_%H_%M_%S")
# name = "output_"+date_time+".txt"
# f = open(name,"x")
# print("X","Y","Z", file=f)
# f.close()
2022-03-01 09:18:04 +00:00
2022-02-26 19:51:43 +00:00
while True:
[X,Y,Z] = accel.readAll()
2022-03-01 16:06:12 +00:00
print("X: ",X,"\tY: ",Y,"\t Z: ",Z,"\n")
# with open(name,"a") as f:
# print(X,Y,Z, file=f)