Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1.  
  2. import RPi.GPIO as GPIO
  3. import spidev
  4. import time
  5.  
  6. GPIO.setmode(GPIO.BCM)
  7. GPIO.setup(12, GPIO.OUT)
  8.  
  9. channel=1
  10.  
  11. spi=spidev.SpiDev()
  12. spi.open(0,0)
  13. spi.max_speed_hz = 5000
  14. try:
  15.         while True:
  16.                 adc=spi.xfer2([1,(8+channel)<<4,0])
  17.                 data=((adc[1]&3)<<8) +adc[2]
  18.                 data_scale=(data*3.3)/float(1023)
  19.                 data_scale=round(data_scale,2)
  20.                 if data_scale < 2.2 and data_scale > 2:
  21.                         GPIO.output(12,True)
  22.                 else:
  23.                         GPIO.output(12,False)
  24.                 time.sleep(0.001)
  25. except KeyboardInterrupt:
  26.         GPIO.cleanup()
  27.         pass
  28. spi.close()
  29.  
  30. pi@raspberrypi:~$ ^C
  31. pi@raspberrypi:~$ python spi_in_test.py
  32. ^[[A^Cpi@raspberrypython spi_in_test.py
  33. ^Cpi@raspberrypi:~$ cat matrix.py
  34. from luma.core.interface.serial import spi, noop
  35. from luma.core.render import canvas
  36. from luma.led_matrix.device import max7219
  37. from PIL import Image
  38.  
  39. img = Image.new('RGB', (8,8), color = 'yellow')
  40.  
  41. serial = spi(port=0, device=0, gpio=noop())
  42. device = max7219(serial)
  43.  
  44. with canvas(device) as draw:
  45.     draw.rectangle(device.bounding_box, outline="white", fill="yellow")
  46.  
  47. while True:
  48.     a = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement