コード例 #1
0
# A easy Gpio library example for the Udoo Neo created by David Smerkous
# The current things this library can do

# digitalWriting/Reading - Soon to come PWM

from neo import Gpio # import Gpio library
from time import sleep # import sleep to wait for blinks

neo = Gpio() #create new Neo object

pinTwo = 2 #pin to use
pinThree = 3

neo.pinMode(pinTwo, neo.OUTPUT)# Use innerbank pin 2 and set it as output either 0 (neo.INPUT) or 1 (neo.OUTPUT)
neo.pinMode(pinThree, neo.INPUT)# Use pin three(innerbank) and read set state to read

#Blink example
for a in range(0, 5): #Do for five times
	neo.digitalWrite(pinTwo,neo.HIGH) #write high value to pin
	sleep(1)# wait one second
	neo.digitalWrite(pinTwo,neo.LOW) #write low value to pin
	sleep(1)# wait one second

#Read pin
print "Current pin("+str(pinThree)+") state is: "+str(neo.digitalRead(pinThree)) # read current value of pinThree(To succesfully read a pin it must be either pulled to ground or 3.3v, a non connected wire will not work)
コード例 #2
0
ファイル: IRLearner.py プロジェクト: monicabaluna/willyfog
    def getSamsungCode(self):

        # Learning mode feedback led
        pinLED = 26
        # IR receiver
        pinIR = 25

        command_length_samasung = 65

        neo = Gpio()
        neo.pinMode(pinIR, neo.INPUT)
        neo.pinMode(pinLED, neo.OUTPUT)
        neo.digitalWrite(pinLED, neo.HIGH)

        sample_number = 0
        # Compute the average result after MAX_SAMPLES
        bits_sum = [0] * 32
        MAX_SAMPLES = 3
        while True:

            # stop the receiver after MAX_SAMPLES
            if sample_number == MAX_SAMPLES:
                for x in range(0, len(bits_sum)):
                    bits_sum[x] = bits_sum[x] / (MAX_SAMPLES * 1.0)
                break

            value = 1

            # Loop until get IR data
            time_to_live = 45000
            while value and time_to_live:
                value = neo.digitalRead(pinIR)
                time_to_live -= 1

            if time_to_live == 0:
                neo.digitalWrite(pinLED, neo.LOW)
                return ""

            # Grab the start time of the command
            startTime = datetime.now()

            # Used to buffer the command pulses
            command = []

            # The end of the "command" happens when we read more than
            # a certain number of 1s (1 is off for the IR receiver)
            numOnes = 0

            # Used to keep track of transitions from 1 to 0
            previousVal = 0

            while True:

                if value != previousVal:
                    # The value has changed, so calculate the length of this run
                    now = datetime.now()
                    pulseLength = now - startTime
                    startTime = now

                    command.append((previousVal, pulseLength.microseconds))
#					print str(previousVal) + " " + str(pulseLength.microseconds)
#if len(command) == command_length_samasung:
#	break
                if value:
                    numOnes = numOnes + 1
                else:
                    numOnes = 0
                if numOnes > 100:
                    break
                #if numOnes > 300:
                #	break
                previousVal = value
                value = neo.digitalRead(pinIR)

            # A Sony IR signal starts with 2400 microseconds on and 600 microseconds off;
            # that's the first wide pulse. A "1" bit is transmitted with 1200 microseconds on and 600 microseconds off,
            # while a "0" bit is transmitted with 600 microseconds on and 600 microseconds off.
            # (This encoding is also called SIRC or SIRCS encoding.)

            # Chop the header of the received IR signal
            # print command

            command = command[2:]
            command = command[:64]
            #print "Command length: " + str(len(command))
            # Establish the payload of the received IR signal
            binaryString = "".join(
                map(lambda x: "1" if x[1] > 1080 else "0",
                    filter(lambda x: x[0] == 1, command)))

            # The length of the payload, according to SONY protocol is 12 bits; skip otherwise
            #print len(binaryString)
            if len(binaryString) != 32:
                continue
            #print "Good length!"
            sample_number = sample_number + 1
            binaryString = map(int, binaryString)

            bits_sum = [sum(x) for x in zip(bits_sum, binaryString)]

        # compute the IR code based on MAX_SAMPLES
        result = ""
        for x in bits_sum:
            if x < 0.5:
                result += '0'
            else:
                result += '1'
        neo.digitalWrite(pinLED, neo.LOW)

        print result
        return result
コード例 #3
0
ファイル: IRRawLearner.py プロジェクト: monicabaluna/willyfog
	def getCode(self):
		
		# Learning mode feedback led
		pinLED = 26
		# IR receiver 
		pinIR = 25

		neo = Gpio()
		neo.pinMode(pinIR, neo.INPUT) 
		neo.pinMode(pinLED, neo.OUTPUT)
		neo.digitalWrite(pinLED, neo.HIGH)

		# Compute the average result after MAX_SAMPLES
		gap_number = 0
		MAX_GAPS = 3
		GAP_TIME = 20000
		
		value = 1

		time_to_live = 45000 
		while value and time_to_live:
			value = neo.digitalRead(pinIR)
			time_to_live -= 1

		if time_to_live == 0:
			neo.digitalWrite(pinLED, neo.LOW)
			return ""

		# Grab the start time of the command
		startTime = datetime.now()

		# Used to buffer the command pulses
		command = []

		# Used to keep track of transitions from 1 to 0
		previousVal = 0

		while True:

			if value != previousVal:
				# The value has changed, so calculate the length of this run
				now = datetime.now()
				pulseLength = now - startTime
				startTime = now
				if pulseLength.microseconds > GAP_TIME:
					gap_number = gap_number + 1
				if gap_number == MAX_GAPS:
					break
				command.append((previousVal, pulseLength.microseconds))

			previousVal = value
			value = neo.digitalRead(pinIR)
		
		
		neo.digitalWrite(pinLED, neo.LOW)
		result = ""
		for (i, j) in command:
			result = result + " " + str(j)
		#result = result.replace(",", "")
		result = result[1:]
		print result
		return result