# A simple program that emulates a SNES machine's clock and latch line # signals and sends them to a SNES controller, # and also reads incoming data from a SNES controller. import RPi.GPIO as GPIO import WiringPi as Wire GPIO.setmode(GPIO.BCM) GPIO.setup(12, GPIO.OUT) # LATCH GPIO.setup(13, GPIO.IN, pull_up_down=GPIO.PUD_UP) # READ GPIO.setup(4,GPIO.ALT0) # CLOCK GPIO.setclock(4,8333333) # Sets the clock equal to about 8MHZ. int count int register = [16] ############## ### ### # Latch Loop # ### ### ############## while 1: count = 0 GPIO.output(12, GPIO.HIGH) # Set the pin to high. register[count] = GPIO.input(13) count ++ Wire.delayMicroseconds(12) # Wait 12us. GPIO.output(12, GPIO.LOW) # Set the pin to low. Wire.delayMicroseconds(6) # Wait 6us before starting the clock. GPIO.output(4,1) # Turn the clock on. ################## ### ### # Data Read Loop # ### ### ################## while count < 16: register[count] = GPIO.input(13) Wire.waitMicroseconds(12) count ++ Wire.delayMicroseconds(16120000) #Wait for 16.12ms or 60hz.
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question