Ejemplo n.º 1
0
pin4 = 6
index = 0

print 'Setting up pin %d' % pin1
gpio.pinMode(pin1, gpio.OUTPUT)
print 'Setting up pin %d' % pin2
gpio.pinMode(pin2, gpio.OUTPUT)
print 'Setting up pin %d' % pin3
gpio.pinMode(pin3, gpio.OUTPUT)
print 'Setting up pin %d' % pin4
gpio.pinMode(pin4, gpio.OUTPUT)

print 'Go up now...'
try:
    while (True):
        gpio.digitalWrite(pin4, gpio.LOW)
        gpio.digitalWrite(pin2, gpio.HIGH)
        time.sleep(0.01)

        gpio.digitalWrite(pin1, gpio.LOW)
        gpio.digitalWrite(pin3, gpio.HIGH)
        time.sleep(0.01)

        gpio.digitalWrite(pin2, gpio.LOW)
        gpio.digitalWrite(pin4, gpio.HIGH)
        time.sleep(0.01)

        gpio.digitalWrite(pin3, gpio.LOW)
        gpio.digitalWrite(pin1, gpio.HIGH)
        time.sleep(0.01)
Ejemplo n.º 2
0
# Create a new instance of the GPIOEdison class.
# Setting debug=True gives information about the interaction with sysfs.
gpio = GPIO(debug=False)
pin = 13
state = gpio.HIGH

# Set pin 13 to be used as an output GPIO pin.
print 'Setting up pin %d' % pin
gpio.pinMode(pin, gpio.OUTPUT)

print 'Blinking pin %d now...' % pin
try:
    while (True):
        # Write a state to the pin. ON or OFF.
        gpio.digitalWrite(pin, state)

        # Toggle the state.
        state = gpio.LOW if state == gpio.HIGH else gpio.HIGH

        # Sleep for a while.
        time.sleep(0.5)

# When you get tired of seeing the led blinking kill the loop with Ctrl-C.
except KeyboardInterrupt:
    # Leave the led turned off.
    print '\nCleaning up...'
    gpio.digitalWrite(pin, gpio.LOW)

    # Do a general cleanup. Calling this function is not mandatory.
    gpio.cleanup()
Ejemplo n.º 3
0
print 'Setting up all pins...'

# Set pin 14 to be used as an analog input GPIO pin.
gpio.pinMode(analogpin, gpio.ANALOG_INPUT)

# Set pin 13 to be used as an output GPIO pin.
gpio.pinMode(pin, gpio.OUTPUT)

print 'Analog reading from pin %d now...' % analogpin
try:
    while (True):
        # Read the voltage on pin 14
        value = gpio.analogRead(analogpin)

        # Turn ON pin 13
        gpio.digitalWrite(pin, gpio.HIGH)

        # Sleep for a while depending on the voltage we just read. The higher
        # the voltage the more we sleep.
        time.sleep(value / 1023.0)

        # Turn OFF pin 13
        gpio.digitalWrite(pin, gpio.LOW)

        # Sleep for a while depending on the voltage we just read. The higher
        # the voltage the more we sleep.
        time.sleep(value / 1023.0)

# When you get tired of seeing the led blinking kill the loop with Ctrl-C.
except KeyboardInterrupt:
    # Leave the led turned off.
Ejemplo n.º 4
0
Hitting Ctrl-C stops motor.
"""

#!usr/bin/python

from wiringx86 import GPIOEdison as GPIO
import time

gpio = GPIO(debug=False)
pin = 9
pin2 = 13
fastness = 100
delta = 5

gpio.pinMode(pin, gpio.PWM)
gpio.pinMode(pin2, gpio.OUTPUT)
gpio.digitalWrite(pin2, gpio.HIGH)

try:
    while (True):
        gpio.analogWrite(pin, fastness)
        fastness = fastness + delta
        if fastness == 0 or fastness == 255:
            delta = -delta
        time.sleep(0.03)

except KeyboardInterrupt:
    gpio.analogWrite(pin, 0)
    gpio.cleanup()
Ejemplo n.º 5
0
#collection = db.data_consume
###############################

counter = 0

try:
    while(True):
        if counter == 10:
            data = urllib2.urlopen("http://192.168.100:8000/data.txt").read()
            print "Received:", data
            #collection = db.data_consume
            #print list(db.data_consume.find().sort({ 'uid', pymongo.DESCENDING}).limit(1))
            global counter
            print "Received:", data
            if data == 1000:
                gpio.digitalWrite(pin[0], gpio.HIGH)
            if data == 2000:
                gpio.digitalWrite(pin[1], gpio.HIGH)
            if data == 3000:
                gpio.digitalWrite(pin[2], gpio.HIGH)
            if data == 4000:
                gpio.digitalWrite(pin[3], gpio.HIGH)
            if data == 5000:
                gpio.digitalWrite(pin[4], gpio.HIGH)
            if data == 6000:
                gpio.digitalWrite(pin[5], gpio.HIGH)
            if data == 7000:
                gpio.digitalWrite(pin[6], gpio.HIGH)
            if data == 8000:
                gpio.digitalWrite(pin[7], gpio.HIGH)
            if data == 9000:
Ejemplo n.º 6
0
# Setting debug=True gives information about the interaction with sysfs.
gpio = GPIO(debug=False)
state = gpio.HIGH
pins = 20

# Set all pins to be used as output GPIO pins.
print 'Setting up all pins...'
for pin in range(0, pins):
    gpio.pinMode(pin, gpio.OUTPUT)

print 'Blinking all pins now...'
try:
    while(True):
        for pin in range(0, pins):
            # Write a state to the pin. ON or OFF.
            gpio.digitalWrite(pin, state)

        # Toggle the state.
        state = gpio.LOW if state == gpio.HIGH else gpio.HIGH

        # Sleep for a while.
        time.sleep(0.5)

# When you get tired of seeing the led blinking kill the loop with Ctrl-C.
except KeyboardInterrupt:
    # Leave all leds turned off.
    print '\nCleaning up...'
    for pin in range(0, pins):
        gpio.digitalWrite(pin, gpio.LOW)

    # Do a general cleanup. Calling this function is not mandatory.
Ejemplo n.º 7
0
print 'Setting up pins %d and %d...' % (pin, button)

# Set pin 13 to be used as an output GPIO pin.
gpio.pinMode(pin, gpio.OUTPUT)

# Set pin 2 to be used as an input GPIO pin.
gpio.pinMode(button, gpio.INPUT)

print 'Reading from pin %d now...' % button
try:
    while(True):
        # Read the state of the button
        state = gpio.digitalRead(button)

        # If the button is pressed turn ON pin 13
        if state == 1:
            gpio.digitalWrite(pin, gpio.HIGH)

        # If the button is not pressed turn OFF pin 13
        else:
            gpio.digitalWrite(pin, gpio.LOW)

# Kill the loop with Ctrl-C.
except KeyboardInterrupt:
    # Leave the led turned off.
    print '\nCleaning up...'
    gpio.digitalWrite(pin, gpio.LOW)

    # Do a general cleanup. Calling this function is not mandatory.
    gpio.cleanup()