Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import RPi.GPIO as GPIO
- import spidev
- import time
- GPIO.setmode(GPIO.BCM)
- GPIO.setup(12, GPIO.OUT)
- channel=1
- spi=spidev.SpiDev()
- spi.open(0,0)
- spi.max_speed_hz = 5000
- try:
- while True:
- adc=spi.xfer2([1,(8+channel)<<4,0])
- data=((adc[1]&3)<<8) +adc[2]
- data_scale=(data*3.3)/float(1023)
- data_scale=round(data_scale,2)
- if data_scale < 2.2 and data_scale > 2:
- GPIO.output(12,True)
- else:
- GPIO.output(12,False)
- time.sleep(0.001)
- except KeyboardInterrupt:
- GPIO.cleanup()
- pass
- spi.close()
- pi@raspberrypi:~$ ^C
- pi@raspberrypi:~$ python spi_in_test.py
- ^[[A^Cpi@raspberrypython spi_in_test.py
- ^Cpi@raspberrypi:~$ cat matrix.py
- from luma.core.interface.serial import spi, noop
- from luma.core.render import canvas
- from luma.led_matrix.device import max7219
- from PIL import Image
- img = Image.new('RGB', (8,8), color = 'yellow')
- serial = spi(port=0, device=0, gpio=noop())
- device = max7219(serial)
- with canvas(device) as draw:
- draw.rectangle(device.bounding_box, outline="white", fill="yellow")
- while True:
- a = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement