Example #1
0
#!/usr/bin/python3

import time
from quick2wire.gpio import Pin

out_pin = Pin(11, Pin.Out)
out_pin.value = 0
print ("pin 11 value = ", out_pin.value)

try:
	while True:
		out_pin.value = 1 - out_pin.value
		print ("pin 11 value = ", out_pin.value)
		time.sleep(2)

except KeyboardInterrupt:
        out_pin.unexport()

 def setup_method(self, method):
     self.pin = Pin(5)
Example #3
0
import os
sys.path.insert(0, '/home/jack/quick2wire-python-api/src')

from time import sleep
from quick2wire.gpio import Pin
from switch import switch
## import switch

LED = int(sys.argv[1]) if len(sys.argv) > 1 else 1
ontime = int(sys.argv[2]) if len(sys.argv) > 2 else 5



for case in switch(LED):
    if case(1):
        pin = Pin(3, Pin.Out); break
    if case(2):
        pin = Pin(5, Pin.Out); break
    if case(3):
        pin = Pin(7, Pin.Out); break
    if case(4):
        pin = Pin(11, Pin.Out); break
    if case(5):
        pin = Pin(12, Pin.Out); break
    if case(6):
        pin = Pin(13, Pin.Out); break
    if case(7):
        pin = Pin(15, Pin.Out); break
    if case(8):
        pin = Pin(16, Pin.Out); break
    if case(): # default, could also just omit condition or 'if True'
Example #4
0
File: mot.py Project: Mercor/pybal
  pulseLength /= 60                       # 60 Hz
  print( "%d us per period" % pulseLength)
  pulseLength /= 4096                     # 12 bits of resolution
  print( "%d us per bit" % pulseLength)
  pulse *= 1000
  pulse /= pulseLength
  pwm.setPWM(channel, 0, pulse)








pin23= Pin(16, Pin.Out, pull=Pin.PullUp)
pin22= Pin(15, Pin.Out, pull=Pin.PullDown)

pin23.value=1
pin22.value=0

pwm.setPWMFreq(60)                        # Set frequency to 60 Hz
try:
  while (True):
    # Change speed of continuous servo on channel O
    pwm.setPWM(0, 0, servoMin)
   # pwm.setPWM(15, 0, servoMin)
    time.sleep(1)
    pwm.setPWM(0, 0, servoMax)
    #pwm.setPWM(15, 0, servoMax)
    time.sleep(1)
class TestPin:
    def setup_method(self, method):
        self.pin = Pin(5)
    
    def teardown_method(self, method):
        if self.pin.is_exported:
            self.pin.unexport()
    
    def test_pin_must_be_exported_before_use(self):
        with pytest.raises(IOError):
            self.pin.value
        self.pin.export()
        self.pin.value
        
    def test_pin_can_be_unexported_and_made_unusable(self):
        self.pin.export()
        self.pin.unexport()
        with pytest.raises(IOError):
            self.pin.value
    
    def test_can_set_and_query_direction_of_pin(self):
        self.pin.export()
        
        self.pin.direction = Pin.Out
        assert self.pin.direction == Pin.Out
        
        self.pin.direction = Pin.In
        assert self.pin.direction == Pin.In

        
    def test_can_set_value_of_output_pin(self):
        self.pin.export()
        
        self.pin.direction = Pin.Out
        
        self.pin.value = 1
        assert self.pin.value == 1
        
        self.pin.value = 0
        assert self.pin.value == 0
        
    def test_can_export_pin_and_set_direction_on_construction(self):
        p = Pin(5, Pin.Out)
        
        assert p.is_exported
        assert p.direction == Pin.Out
Example #6
0
 def test_can_use_context_manager_with_pin_already_exported(self):
     Pin(25).export()
     self.test_can_automatically_unexport_pin_with_context_manager()
Example #7
0
#!/usr/bin/python3
from quick2wire.gpio import Pin
import time

o1 = Pin(11, Pin.Out)
o2 = Pin(13, Pin.Out)
o3 = Pin(15, Pin.Out)
o4 = Pin(16, Pin.Out)

for i in range(1,16):
    o4.value = bin(i)[-1] if len(bin(i))>2 else 0
    o3.value = bin(i)[-2] if len(bin(i))>3 else 0 
    o2.value = bin(i)[-3] if len(bin(i))>4 else 0
    o1.value = bin(i)[-4] if len(bin(i))>5 else 0
    time.sleep(0.5)


Example #8
0
    def test_can_automatically_unexport_pin_with_context_manager(self):
        with exported(Pin(25)) as p:
            assert p.is_exported

        p = Pin(25)
        assert not p.is_exported
Example #9
0
    def test_can_use_context_manager_with_pin_exported_by_constructor(self):
        with exported(Pin(25, Pin.Out)) as p:
            assert p.is_exported

        p = Pin(25)
        assert not p.is_exported
Example #10
0
    def test_can_export_pin_and_set_direction_on_construction(self):
        p = Pin(25, Pin.Out)

        assert p.is_exported
        assert p.direction == Pin.Out
Example #11
0
 def setup_method(self, method):
     self.pin = Pin(25)
Example #12
0
class TestPin:
    def setup_method(self, method):
        self.pin = Pin(25)

    def teardown_method(self, method):
        if self.pin.is_exported:
            self.pin.unexport()

    def test_pin_must_be_exported_before_use(self):
        with pytest.raises(IOError):
            self.pin.value
        self.pin.export()
        self.pin.value

    def test_pin_can_be_unexported_and_made_unusable(self):
        self.pin.export()
        self.pin.unexport()
        with pytest.raises(IOError):
            self.pin.value

    def test_can_set_and_query_direction_of_pin(self):
        self.pin.export()

        self.pin.direction = Pin.Out
        assert self.pin.direction == Pin.Out

        self.pin.direction = Pin.In
        assert self.pin.direction == Pin.In

    def test_can_set_value_of_output_pin(self):
        self.pin.export()

        self.pin.direction = Pin.Out

        self.pin.value = 1
        assert self.pin.value == 1

        self.pin.value = 0
        assert self.pin.value == 0

    def test_can_export_pin_and_set_direction_on_construction(self):
        p = Pin(25, Pin.Out)

        assert p.is_exported
        assert p.direction == Pin.Out
Example #13
0
from quick2wire.gpio import Pin
from switch import switch

# enable debugging
import cgitb

cgitb.enable()

## import switch

LED = int(sys.argv[1]) if len(sys.argv) > 1 else 1
numBlinks = int(sys.argv[2]) if len(sys.argv) > 2 else 5

for case in switch(LED):
    if case(1):
        pin = Pin(3, Pin.Out)
        break
    if case(2):
        pin = Pin(5, Pin.Out)
        break
    if case(3):
        pin = Pin(7, Pin.Out)
        break
    if case(4):
        pin = Pin(11, Pin.Out)
        break
    if case(5):
        pin = Pin(12, Pin.Out)
        break
    if case(6):
        pin = Pin(13, Pin.Out)
Example #14
0
#!/usr/bin/python3

import sys
from time import sleep
from quick2wire.gpio import Pin

pin = Pin(int(sys.argv[1]) if len(sys.argv) > 1 else 12, Pin.Out)
print pin

try:
    pin.value = 1
    while True:
        sleep(1)
        pin.value = 1 - pin.value
except KeyboardInterrupt:
    pin.value = 0
    pin.unexport()

Example #15
0
from quick2wire.gpio import Pin
from time import sleep
import pytest

Pins = [Pin(header_pin_number) for header_pin_number in [11, 12, 13, 15, 16, 18, 22, 7]]

def setup_module():
    for pin in Pins:
        pin.export()

def teardown_module():
    for pin in Pins:
        if pin.is_exported:
            pin.unexport()

@pytest.mark.loopback
def test_gpio_loopback():
    assert_outputs_seen_at_corresponding_inputs(Pins[:4], Pins[4:])
    assert_outputs_seen_at_corresponding_inputs(Pins[4:], Pins[:4])


def assert_outputs_seen_at_corresponding_inputs(outputs, inputs):
    for (op, ip) in zip(outputs, inputs):
        assert_output_seen_at_input(op, ip)


def assert_output_seen_at_input(output_pin, input_pin):
    output_pin.direction = Pin.Out
    input_pin.direction = Pin.In
    
Example #16
0
#!/usr/bin/python3

import time
import string
from quick2wire.gpio import Pin

# import pins for output
out_pin1 = Pin(11, Pin.Out)
out_pin2 = Pin(13, Pin.Out)
out_pin3 = Pin(15, Pin.Out)
out_pin4 = Pin(16, Pin.Out)

# import pins for input 
in_pin = Pin(7, Pin.In)

# init count
count = 0

print ("This script will increase a counter")
print ("Every time the button is pressed")
print ("Display the counter and binary values")
print ("Please press the button")

# outputs binary reprisentation to 4 leds that matches count. 
def display_count(i):
	binvalue = bin(i)[2:].zfill(4)
	print ("Program output", binvalue)
	out_pin4.value = binvalue[-1]
	out_pin3.value = binvalue[-2]
	out_pin2.value = binvalue[-3]
	out_pin1.value = binvalue[-4]