コード例 #1
0
def etchAsketch():
    global matrix_data

    running = True
    last_key = 1
    key = 0
    while running:

        x = encoder.get(2)
        y = encoder.get(3)

        x = enc_to_screen(x)
        y = enc_to_screen(y)

        if GPIO.input(pause) == 0:
            running = False
        else:
            pass  #running = False
        if x < 0:
            x = 0
        if x > 7:
            x = 7
        if y < 0:
            y = 0
        if y > 7:
            y = 7

        #print(x, key, last_key)

        if x - key > 0 and last_key < 0:
            last_key = 1
            handle_shake()
        elif x - key < 0 and last_key > 0:
            last_key = -1
            handle_shake()

        key = x

        write_to_matrix(y, x)
        # print(matrix_data)
        # print(x, y)
        bus.write_i2c_block_data(matrix, 0, matrix_data)
        sleep(0.1)
コード例 #2
0
def test1():

    N = 5

    # set to 10

    encoder.set(1, 10)
    assert encoder.get(1) == 10

    encoder.set(2, 10)
    assert encoder.get(2) == 10

    encoder.set(3, 10)
    assert encoder.get(3) == 10

    encoder.set(4, 10)
    assert encoder.get(4) == 10

    # default to zero

    encoder.set(1)
    assert encoder.get(1) == 0

    encoder.set(2)
    assert encoder.get(2) == 0

    encoder.set(3)
    assert encoder.get(3) == 0

    encoder.set(4)
    assert encoder.get(4) == 0

    print('\n ENC #1 |  ENC #2 |  ENC #3 |  ENC #4')

    for i in range(N):

        e1 = encoder.get(1)
        e2 = encoder.get(2)
        e3 = encoder.get(3)
        e4 = encoder.get(4)

        print('\r{:7d} | {:7d} | {:7d} | {:7d}'.format(e1, e2, e3, e4), end='')

        time.sleep(1)
コード例 #3
0
ファイル: Etchv4.py プロジェクト: Douglas2595/ECE497
delay = 1; # Delay between images in s

bus.write_byte_data(matrix, 0x21, 0)   # Start oscillator (p10)
bus.write_byte_data(matrix, 0x81, 0)   # Disp on, blink off (p11)
bus.write_byte_data(matrix, 0xe7, 0)   # Full brightness (page 15)

game = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
]

x = 0x01
y = 0

while 1:
    e1_base = encoder.get(1) # read the encoders
    e2_base = encoder.get(2)

    time.sleep(.5)

    if encoder.get(1) > e1_base:
        if x > 0x01: x = x >> 1
    if encoder.get(1) < e1_base:
        if x < 0x80: x = x << 1
    if encoder.get(2) < e2_base:
        if y < 14: y += 2
    if encoder.get(2) > e2_base:
        if y > 0: y -= 2
    if not GPIO.input(clear):
        game = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
コード例 #4
0
stage = 0
motorset = 5
motor_pwm = [
    0, 0.05, 0.10, 0.15, 0.20, 0.25, 0.30, 0.35, 0.40, 0.45, 0.50, 0.55, 0.60,
    0.65, 0.70, 0.75, 0.80, 0.85, 0.90, 0.95, 1
]
motor_spd = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
old_enc = 0
Ts = 1

for i in motor_pwm:
    for j in range(0, 10):
        if motorset != i:
            print('New Stage Setted')
            motorset = i
            motor.set(i)
        print(f'PWM = {i},Timers = {j}')
        ne = encoder.get()
        spd = (ne - old_enc) / Ts
        old_enc = ne
        time.sleep(Ts)
    motor_spd[stage] = spd
    print(f'stage = {stage}')
    stage += 1
    time.sleep(Ts)

print(motor_spd)
motor.free_spin()
with open('test.txt', 'w') as f:
    f.write(json.dumps(motor_pwm))
    f.write(json.dumps(motor_spd))
コード例 #5
0
# import python libraries
import time

# import rcpy library
# This automatically initizalizes the robotics cape
import rcpy
import rcpy.encoder as encoder

rcpy.set_state(rcpy.RUNNING)
print("Press Ctrl-C to exit")

# header
print('     E1 |     E2')
try:
    # keep running
    while True:
        # running
        if rcpy.get_state() == rcpy.RUNNING:
            e1 = encoder.get(1) # read the encoders
            e2 = encoder.get(2)
            print('\r {:+6d} | {:+6d}'.format(e1,e2), end='')
        time.sleep(.5)  # sleep some

except KeyboardInterrupt:
    # Catch Ctrl-C
    pass

finally:
    print("\nBye BeagleBone!")
コード例 #6
0
# import python libraries
import time

# import rcpy library
# This automatically initizalizes the robotics cape
import rcpy
import rcpy.encoder as encoder

rcpy.set_state(rcpy.RUNNING)
print("Press Ctrl-C to exit")

# header
print('     E2 |     E3')
try:
    # keep running
    while True:
        # running
        if rcpy.get_state() == rcpy.RUNNING:
            e2 = encoder.get(2)  # read the encoders
            e3 = encoder.get(3)
            print('\r {:+6d} | {:+6d}'.format(e2, e3), end='')
        time.sleep(.5)  # sleep some

except KeyboardInterrupt:
    # Catch Ctrl-C
    pass

finally:
    print("\nBye BeagleBone!")
コード例 #7
0
ファイル: rcpy_test_encoders.py プロジェクト: jimfred/rcpy
def main():

    # exit if no options
    if len(sys.argv) < 2:
        usage()
        sys.exit(2)
    
    # Parse command line
    try:
        opts, args = getopt.getopt(sys.argv[1:], "he:", ["help"])

    except getopt.GetoptError as err:
        # print help information and exit:
        print('rcpy_test_encoders: illegal option {}'.format(sys.argv[1:]))
        usage()
        sys.exit(2)

    # defaults
    channel = 0

    for o, a in opts:
        if o in ("-h", "--help"):
            usage()
            sys.exit()
        elif o in "-e":
            channel = int(a)
        else:
            assert False, "Unhandled option"

    # set state to rcpy.RUNNING
    rcpy.set_state(rcpy.RUNNING)

    # message
    print("Press Ctrl-C to exit")

    # header
    if channel == 0:
        print('     E1 |     E2 |     E3 |     E4')
    else:
        print('     E{}'.format(channel))

    try:

        # keep running
        while True:

            # running
            if rcpy.get_state() == rcpy.RUNNING:

                if channel == 0:

                    # read all encoders
                    e1 = encoder.get(1)
                    e2 = encoder.get(2)
                    e3 = encoder.get(3)
                    e4 = encoder.get(4)

                    print('\r {:+6d} | {:+6d} | {:+6d} | {:+6d}'.format(e1,e2,e3,e4), end='')

                else:

                    # read one encoder
                    e = encoder.get(channel)

                    print('\r {:+6d}'.format(e), end='')
                        
            # sleep some
            time.sleep(.5)

    except KeyboardInterrupt:
        # Catch Ctrl-C
        pass
    
    finally:

        # say bye
        print("\nBye Beaglebone!")
コード例 #8
0
def main():

    # exit if no options
    if len(sys.argv) < 2:
        usage()
        sys.exit(2)

    # Parse command line
    try:
        opts, args = getopt.getopt(sys.argv[1:], "he:", ["help"])

    except getopt.GetoptError as err:
        # print help information and exit:
        print('rcpy_test_encoders: illegal option {}'.format(sys.argv[1:]))
        usage()
        sys.exit(2)

    # defaults
    channel = 0

    for o, a in opts:
        if o in ("-h", "--help"):
            usage()
            sys.exit()
        elif o in "-e":
            channel = int(a)
        else:
            assert False, "Unhandled option"

    # set state to rcpy.RUNNING
    rcpy.set_state(rcpy.RUNNING)

    # message
    print("Press Ctrl-C to exit")

    # header
    if channel == 0:
        print('     E1 |     E2 |     E3 |     E4')
    else:
        print('     E{}'.format(channel))

    try:

        # keep running
        while True:

            # running
            if rcpy.get_state() == rcpy.RUNNING:

                if channel == 0:

                    # read all encoders
                    e1 = encoder.get(1)
                    e2 = encoder.get(2)
                    e3 = encoder.get(3)
                    e4 = encoder.get(4)

                    print('\r {:+6d} | {:+6d} | {:+6d} | {:+6d}'.format(
                        e1, e2, e3, e4),
                          end='')

                else:

                    # read one encoder
                    e = encoder.get(channel)

                    print('\r {:+6d}'.format(e), end='')

            # sleep some
            time.sleep(.5)

    except KeyboardInterrupt:
        # Catch Ctrl-C
        pass

    finally:

        # say bye
        print("\nBye Beaglebone!")
コード例 #9
0
# import python libraries
import time

# import rcpy library
# This automatically initizalizes the robotics cape
import rcpy 
import rcpy.encoder as encoder

rcpy.set_state(rcpy.RUNNING)
print("Press Ctrl-C to exit")

# header
print('     E2 |     E3')
try:
    # keep running
    while True:
        # running
        if rcpy.get_state() == rcpy.RUNNING:
            e2 = encoder.get(2) # read the encoders
            e3 = encoder.get(3)
            print('\r {:+6d} | {:+6d}'.format(e2,e3), end='')
        time.sleep(.5)  # sleep some

except KeyboardInterrupt:
    # Catch Ctrl-C
    pass

finally:
    print("\nBye BeagleBone!")
コード例 #10
0
ファイル: test_encoder.py プロジェクト: jimfred/rcpy
def test1():

    N = 5
    
    # set to 10
    
    encoder.set(1, 10)
    assert encoder.get(1) == 10

    encoder.set(2, 10)
    assert encoder.get(2) == 10
    
    encoder.set(3, 10)
    assert encoder.get(3) == 10
    
    encoder.set(4, 10)
    assert encoder.get(4) == 10

    # default to zero
    
    encoder.set(1)
    assert encoder.get(1) == 0

    encoder.set(2)
    assert encoder.get(2) == 0
    
    encoder.set(3)
    assert encoder.get(3) == 0
    
    encoder.set(4)
    assert encoder.get(4) == 0
    
    print('\n ENC #1 |  ENC #2 |  ENC #3 |  ENC #4')

    for i in range(N):

        e1 = encoder.get(1)
        e2 = encoder.get(2)
        e3 = encoder.get(3)
        e4 = encoder.get(4)
        
        print('\r{:7d} | {:7d} | {:7d} | {:7d}'.format(e1,e2,e3,e4),
              end='')
        
        time.sleep(1)