Exemplo n.º 1
0
##### setup BBB GPIO pins
GPIO.setup("P8_37", GPIO.OUT)
GPIO.setup("P8_38", GPIO.OUT)
GPIO.setup("P8_31", GPIO.OUT)
GPIO.setup("P8_32", GPIO.OUT)
PWM.start(PWM1, 60)
PWM.start(PWM2, 60)

Enc1 = RotaryEncoder(eQEP1)
Enc1.enable()
if (Enc1.enabled == 1):
    print("Enc1 Enabled")
else:
    print("Enc1 NOT enabled")
Enc1.setAbsolute()
Enc1.zero()
Enc2 = RotaryEncoder(eQEP2)
Enc2.enable()
if (Enc2.enabled == 1):
    print("Enc2 Enabled")
else:
    print("Enc2 NOT enabled")
    Enc2.setAbsolute()
    Enc2.zero()


def get_arrows():
    key = keys.read_key()
    if key == ARROW_LEFT:
        angVel -= 10
    elif key == ARROW_RIGHT:
Exemplo n.º 2
0
        tdata.write("Cal_Disp(mm),Temperature('c),Time(s) \n")
        for cycle in range(1, cy):
            for count in range(1, h):
                GPIO.output(Act, GPIO.LOW)
                distance = myEncoder.position * 0.01
                temp = max(sensor.readPixels())
                Vr = ADC.read(analogPin)
                R = 10000 * Vr / (1.8 - Vr)
                print("%.2f,%d,%d,%.1f\n" % (distance, temp, R, count * 0.1))
                tdata.write("%.2f,%d,%d,%.1f\n" %
                            (distance, temp, R, count * 0.1))
                time.sleep(0.1)
            GPIO.output(Act, GPIO.HIGH)
            for count in range(1, c):
                GPIO.output(Fan, GPIO.LOW)
                distance = myEncoder.position * 0.01
                temp = max(sensor.readPixels())
                Vr = ADC.read(analogPin)
                R = 10000 * Vr / (1.8 - Vr)
                print("%.2f,%d,%d,%.1f\n" % (distance, temp, R, count * 0.1))
                tdata.write("%.2f,%d,%d,%.1f\n" %
                            (distance, temp, R, count * 0.1))
                time.sleep(0.1)
            GPIO.output(Fan, GPIO.HIGH)
        GPIO.output(Act, GPIO.HIGH)
        GPIO.output(Fan, GPIO.HIGH)
    elif a == 5:
        myEncoder.zero()

tdata.close()
Exemplo n.º 3
0
import time

bus = smbus.SMBus(2)  # select i2c bus 2
matrix = 0x70  # define matrix address on i2c bus

# --------------------MATRIX SETUP--------------------
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)

SW = ["P8_11", "P8_12", "P8_33",
      "P8_35"]  # define switches by their header pin

# set up left/right rotary encoder & refresh at 1000kHz
lrEncoder = RotaryEncoder(eQEP2)
lrEncoder.zero()
lrEncoder.setAbsolute()
lrEncoder.frequency = 1000
lrEncoder.enable()
# set up up/down rotary encoder
udEncoder = RotaryEncoder(eQEP1)
udEncoder.zero()
udEncoder.setAbsolute()
udEncoder.frequency = 1000
udEncoder.enable()


def main():
    print("Welcome to etch a sketch!")
    print("")
    print("8x8 LED edition")
Exemplo n.º 4
0
            display[y] = display[y] | temp
    elif (myEncoder2.position > 0):  #move down
        y += 2
        if (y < 16):
            temp = display[y]
            display[y] = 1 << x
            display[y] = display[y] | temp
#		handle for wraparound moving down
        elif (y >= 16):
            y = 0
            temp = display[y]
            display[y] = 1 << x
            display[y] = display[y] | temp
    elif (myEncoder2.position < 0):  #move up
        y -= 2
        if (y >= 0):
            temp = display[y]
            display[y] = 1 << x
            display[y] = display[y] | temp
#		handle for wraparound moving up
        elif (y < 0):
            y = 14
            temp = display[y]
            display[y] = 1 << x
            display[y] = display[y] | temp
    bus.write_i2c_block_data(matrix, 0, display)
    myEncoder1.zero()
    myEncoder2.zero()

    time.sleep(0.1)
Exemplo n.º 5
0
# Clear the whole board
def clearGrid(channel=None):
    global grid
    grid = [[0 for i in range(8)] for j in range(8)]
    updateMatrix()


# Setup buttons to trigger a function
GPIO.add_event_detect(Button1, GPIO.RISING, callback=cursorLeft)
GPIO.add_event_detect(Button2, GPIO.RISING, callback=cursorDown)
GPIO.add_event_detect(Button3, GPIO.RISING, callback=cursorRight)
GPIO.add_event_detect(Button4, GPIO.RISING, callback=cursorUp)
GPIO.add_event_detect(Button5, GPIO.RISING, callback=clearGrid)

# Get the current position
while True:
    # Read encoders and update the cursor if they move
    if (encoder1.position >= 4):
        cursorUp()
        encoder1.zero()
    elif (encoder1.position <= -4):
        cursorDown()
        encoder1.zero()
    elif (encoder2.position >= 4):
        cursorRight()
        encoder2.zero()
    elif (encoder2.position <= -4):
        cursorLeft()
        encoder2.zero()
    else:
        pass
Exemplo n.º 6
0
    # Place red square on current position
    picture[redPicture[xpos]] = picture[redPicture[xpos]] | yposPicture[ypos]
    picture[
        greenPicture[xpos]] = picture[greenPicture[xpos]] & ~yposPicture[ypos]

    bus.write_i2c_block_data(matrix, 0, picture)  #redraw picture

    # Place green square on current position
    picture[redPicture[xpos]] = picture[redPicture[xpos]] & ~yposPicture[ypos]
    picture[
        greenPicture[xpos]] = picture[greenPicture[xpos]] | yposPicture[ypos]


drawPicture()

#loop unil exit
while True:

    #if left/right encoder is moved go to userInput()
    encoderLRValue = myEncoderLR.position
    if (encoderLRValue != 0): userInput(encoderLRValue, "lr")
    myEncoderLR.zero()

    #if up/dowm encoder is moved go to userInput()
    encoderUDValue = myEncoderUD.position
    if (encoderUDValue != 0): userInput(encoderUDValue, "ud")
    myEncoderUD.zero()

    time.sleep(0.5)
Exemplo n.º 7
0
#Create window for curses
begin_x = 0
begin_y = 0
height = 20
width = 20
win = curses.newwin(height, width, begin_y, begin_x)
x = 0
y = 0

while True:
    time.sleep(0.1)

    #Right Direction
    if (myEncoder2.position <
            -5):  #Buffer for encoder, check if really negative
        myEncoder.zero()  #Zero out encoders
        myEncoder2.zero()

        if (x < 7):  #Check for wall

            if (board[2 * (x + 1)] & pow(2, y) == 0x00
                ):  #Check if the next space is already colored

                x = x + 1  #Increment
                board[2 * x] = pow(2, y) + board[2 * x]  #Color next spot Green
                bus.write_i2c_block_data(matrix, 0, board)

                board[2 * x + 1] = pow(2, y) + board[
                    2 * x +
                    1]  #Color the spot red as well to make orange for the cursor
                board[2 * x - 1] = board[2 * x - 1] - pow(