Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Analog Joystick / MCP3008 / Raspberry Pi
import spidev
import time
import os
spi = spidev.SpiDev(),0)
def spiChannel(channel):
adc = spi.xfer2([1,(8+channel)<<4,0])
data = ((adc[1]&3) << 8) + adc[2]
return data
while True:
button = spiChannel(0)
xas = spiChannel(1)
yas = spiChannel(2)
print("X-as: {} Y-as: {} Button: {}".format(xas,yas,button))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment