コード例 #1
0
# This is a program for an etch a sketch game in which the user 
# controls what part of the board lights up by turning the encoder knobs. The board 
# can be 'shaken' at any time by pressing the clear button. There is also
# a button to exit the game.

import sys
import numpy as np
import Adafruit_BBIO.GPIO as GPIO
import time
import smbus
from Adafruit_BBIO.Encoder import RotaryEncoder, eQEP1
from Adafruit_BBIO.Encoder import RotaryEncoder, eQEP2

Encoder1 = RotaryEncoder(eQEP1)
Encoder1.setAbsolute()
Encoder1.enable()

Encoder2 = RotaryEncoder(eQEP2)
Encoder2.setAbsolute()
Encoder2.enable()

bus = smbus.SMBus(2)  # Use i2c bus 1
matrix = 0x70         # Use address 0x70

newcur_y =1
newcur_x = 0
cur_x = 0
cur_y =1

cur_enc1 = Encoder1.position #used for left/right
cur_enc2 = Encoder2.position #used for up/down
コード例 #2
0
ファイル: etchasketch.py プロジェクト: aisaacn/ECE434
def main():
    size = 8  # static when using 8x8 matrix

    # Setup GPIO
    GPIO.setup("P9_22", GPIO.IN)  # left
    GPIO.add_event_detect("P9_22", GPIO.RISING)

    GPIO.setup("P9_24", GPIO.IN)  # up
    GPIO.add_event_detect("P9_24", GPIO.RISING)

    GPIO.setup("P9_23", GPIO.IN)  # right
    GPIO.add_event_detect("P9_23", GPIO.RISING)

    GPIO.setup("P9_21", GPIO.IN)  # down
    GPIO.add_event_detect("P9_21", GPIO.RISING)

    GPIO.setup("P9_26", GPIO.IN)  # clear
    GPIO.add_event_detect("P9_26", GPIO.RISING)

    xEncoder = RotaryEncoder(eQEP2)
    yEncoder = RotaryEncoder(eQEP1)

    xEncoder.setAbsolute()
    yEncoder.setAbsolute()

    xEncoder.enable()
    yEncoder.enable()

    enc_x = xEncoder.position
    enc_y = yEncoder.position

    cur_x = 0
    cur_y = 0

    image = new_image()
    board = new_board(size)

    bus.write_i2c_block_data(matrix, 0, image)

    while True:
        changed = False

        # Updates current position based on button pressed
        if GPIO.event_detected("P9_22"):
            if cur_x > 0:
                cur_x = cur_x - 1
                changed = True
        elif GPIO.event_detected("P9_23"):
            if cur_x < size - 1:
                cur_x = cur_x + 1
                changed = True
        elif GPIO.event_detected("P9_21"):
            if cur_y > 0:
                cur_y = cur_y - 1
                changed = True
        elif GPIO.event_detected("P9_24"):
            if cur_y < size - 1:
                cur_y = cur_y + 1
                changed = True
        elif GPIO.event_detected("P9_26"):
            cur_x = 0
            cur_y = 0
            image = new_image()
            board = new_board(size)

        # Updates current position based on rotary encoder
        if xEncoder.position < enc_x - 3:
            if cur_x < size - 1:
                cur_x = cur_x + 1
                changed = True
            enc_x = xEncoder.position
        elif xEncoder.position > enc_x + 3:
            if cur_x > 0:
                cur_x = cur_x - 1
                changed = True
            enc_x = xEncoder.position

        if yEncoder.position < enc_y - 3:
            if cur_y < size - 1:
                cur_y = cur_y + 1
                changed = True
            enc_y = yEncoder.position
        elif yEncoder.position > enc_y + 3:
            if cur_y > 0:
                cur_y = cur_y - 1
                changed = True
            enc_y = yEncoder.position

#		enc_x = xEncoder.position
#		enc_y = yEncoder.position

# If x,y was changed and that spot on the board is not on
        if changed and not board[cur_x][cur_y]:
            index = 2 * cur_x  # + 1 # add this for red
            delta = int(math.pow(2, cur_y))
            image[index] = image[index] + delta
            board[cur_x][cur_y] = True

        bus.write_i2c_block_data(matrix, 0, image)
コード例 #3
0
 def main(self, stdscr):
     # Defining Buttons
     buttonUp = "P9_27"
     buttonDown = "P9_16"
     buttonLeft = "P9_17"
     buttonRight = "P9_18"
     buttonQuit = "P9_22"
     buttonShake = "P9_24"
     # Setting up buttons
     GPIO.setup(buttonUp, GPIO.IN)
     GPIO.setup(buttonDown, GPIO.IN)
     GPIO.setup(buttonLeft, GPIO.IN)
     GPIO.setup(buttonRight, GPIO.IN)
     GPIO.setup(buttonQuit, GPIO.IN)
     GPIO.setup(buttonShake, GPIO.IN)
     # Setup the encoders
     upDownEncoder = RotaryEncoder(eQEP2)
     leftRightEncoder = RotaryEncoder(eQEP1)
     upDownEncoder.setAbsolute()
     leftRightEncoder.setAbsolute()
     upDownEncoder.enable()
     leftRightEncoder.enable()
     # Setting up the LED matrix
     self.bus.write_byte_data(self.matrix, 0x21, 0)   # Start oscillator (p10)
     self.bus.write_byte_data(self.matrix, 0x81, 0)   # Disp on, blink off (p11)
     self.bus.write_byte_data(self.matrix, 0xe7, 0)   # Full brightness (page 15)
     # Pointing the screen to itself
     self.stdscr = stdscr
     stdscr.clear()
     self.shake()
     try:
         while True:
             # Update cursor
             self.cursor()
             # Initliaze the screen
             curses.initscr()
             if GPIO.input(buttonUp) | upDownEncoder.position > 0:
                 if self.pos[1] > 0:
                     self.pos[1] -= 1
             elif GPIO.input(buttonDown) | upDownEncoder.position < 0:
                 if self.pos[1] < self.height - 1:
                     self.pos[1] += 1
             elif GPIO.input(buttonLeft) | leftRightEncoder.position > 0:
                 if self.pos[0] > 0:
                     self.pos[0] -= 1
             elif GPIO.input(buttonRight) | leftRightEncoder.position < 0:
                 if self.pos[0] < self.width - 1:
                     self.pos[0] += 1
             elif GPIO.input(buttonQuit):
                 break
             elif GPIO.input(buttonShake):
                 self.shake()
                 self.oldpos = list(self.pos)
                 continue
             else:
                 continue
             upDownEncoder.position = 0
             leftRightEncoder.position = 0
             # Draw something on the board
             stdscr.addstr(self.oldpos[1], self.oldpos[0], self.full)
             self.updateLEDMatrix()
             # Update the old position
             self.oldpos = list(self.pos)
             time.sleep(delay/10)
     finally:
           GPIO.cleanup()
コード例 #4
0
# set up pins for clear and stop
GPIO.setup("P9_23", GPIO.IN)
GPIO.setup("P9_42", GPIO.IN)

bus = smbus.SMBus(2)  # Use i2c bus 1
matrix = 0x70  # Use address 0x70

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)

# Instantiate the class to access channel eQEP, and initialize
# that channel
leftRightEncoder = RotaryEncoder(eQEP1)
leftRightEncoder.setAbsolute()  # set to 0 position
leftRightEncoder.enable()

upDownEncoder = RotaryEncoder(eQEP2b)
upDownEncoder.setAbsolute()  # set to 0 position
upDownEncoder.enable()

#begin of etch a sketch
col = 0
row = 0
mapping = [1, 2, 4, 8, 16, 32, 64, 128]
board = [
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00
]
while True:
    time.sleep(.05)
コード例 #5
0
ファイル: hw01.py プロジェクト: EricMorse/ECE434
def main():
    bus = smbus.SMBus(2)  # Use i2c bus 2
    matrix = 0x70  # Use Addresss

    # enables the rotary encoders
    myEncoder1 = RotaryEncoder(eQEP2b)
    myEncoder2 = RotaryEncoder(eQEP1)
    myEncoder1.enable()
    myEncoder2.enable()
    myEncoder1.setAbsolute()  # sets rotary position to 0
    myEncoder2.setAbsolute()  # sets rotary position to 0

    dimensional_size = 8  # size of LED matrix
    # initializes etcher LED screen
    etcher_screen = [[" "] * dimensional_size for _ in range(dimensional_size)]
    LED_screen = [
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00
    ]

    bus.write_byte_data(matrix, 0x21, 0)  # Starts oscillator (page 10)
    bus.write_byte_data(matrix, 0x81, 0)  # Display on, blink 0ff (page 11)
    bus.write_byte_data(matrix, 0xe7, 0)  # Full Brightness (page 15)

    bus.write_i2c_block_data(matrix, 0, LED_screen)  # clears LED screen
    cur_position1 = myEncoder1.position  # current position of encoder 1
    cur_position2 = myEncoder2.position  # current position of encoder 2
    etcher_string = ""
    cursor_position = [0, 0]
    # loop for the etcher sketch operation
    while True:
        # draws the etcher sketch board
        old_position1 = cur_position1
        old_position2 = cur_position2
        header_string = "    "
        for x in range(0, dimensional_size + 1):
            if x == 0:
                for z in range(0, dimensional_size):
                    header_string += str(z) + " "
                print(header_string)
            else:
                for y in range(0, dimensional_size):
                    if y == 0: etcher_string = str(x - 1) + ":" + "  "
                    etcher_string = etcher_string + etcher_screen[x -
                                                                  1][y] + " "
                print(etcher_string)
                etcher_string = ""
        # gets user input for move_command and executes it
        print("right encoder clockwide moves up, counterclockwise moves down")
        print(
            "left encoder clockwise moves right, counterclockwise moves left")
        # loop to wait for user movement on rotary encoders
        while ((old_position1 == cur_position1)
               and (old_position2 == cur_position2)):
            cur_position1 = myEncoder1.position
            cur_position2 = myEncoder2.position
            time.sleep(0.2)
        system('clear')
        # processes rotary encoder movement
        if old_position1 > cur_position1:
            if cursor_position[1] == 0:
                print("Error: can't go left")
            else:
                cursor_position[1] -= 1
                etcher_screen[cursor_position[0]][cursor_position[1]] = "X"
                LED_screen[cursor_position[1] * 2] = modifyBit(
                    LED_screen[cursor_position[1] * 2], 7 - cursor_position[0],
                    1)
                bus.write_i2c_block_data(matrix, 0, LED_screen)
        elif old_position1 < cur_position1:
            if cursor_position[1] == dimensional_size - 1:
                print("Error: can't go right")
            else:
                cursor_position[1] += 1
                etcher_screen[cursor_position[0]][cursor_position[1]] = "X"
                LED_screen[cursor_position[1] * 2] = modifyBit(
                    LED_screen[cursor_position[1] * 2], 7 - cursor_position[0],
                    1)
                bus.write_i2c_block_data(matrix, 0, LED_screen)
        elif old_position2 > cur_position2:
            if cursor_position[0] == 0:
                print("Error: can't go up")
            else:
                cursor_position[0] -= 1
                etcher_screen[cursor_position[0]][cursor_position[1]] = "X"
                LED_screen[cursor_position[1] * 2] = modifyBit(
                    LED_screen[cursor_position[1] * 2], 7 - cursor_position[0],
                    1)
                bus.write_i2c_block_data(matrix, 0, LED_screen)
        elif old_position2 < cur_position2:
            if cursor_position[0] == dimensional_size - 1:
                print("Error: can't go down")
            else:
                cursor_position[0] += 1
                etcher_screen[cursor_position[0]][cursor_position[1]] = "X"
                LED_screen[cursor_position[1] * 2] = modifyBit(
                    LED_screen[cursor_position[1] * 2], 7 - cursor_position[0],
                    1)
                bus.write_i2c_block_data(matrix, 0, LED_screen)
        else:
            print("Error: no movement detected")
コード例 #6
0
os.system("config-pin P8_33 qep")
os.system("config-pin P8_35 qep")
matrix = 0x70
bus = smbus.SMBus(2)
bus.write_byte_data(matrix, 0x21, 0)
bus.write_byte_data(matrix, 0x81, 0)
bus.write_byte_data(matrix, 0xe7, 0)
matrix_data = [
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00
]
temp_address = 0x48

yEncoder = RotaryEncoder(eQEP1)
yEncoder.setAbsolute()
yEncoder.enable()
xEncoder = RotaryEncoder(eQEP2b)
xEncoder.setAbsolute()
xEncoder.enable()

x_dim = 8
y_dim = 8

bus.write_i2c_block_data(matrix, 0, matrix_data)
currx = 0
curry = 7
matrix_data[curry * 2] |= int(pow(2, currx))


def update(xory, dir):
    global currx
コード例 #7
0
#ECE434 HW3

import Adafruit_BBIO.GPIO as GPIO
from Adafruit_BBIO.Encoder import RotaryEncoder, eQEP2b, eQEP1
import time
from subprocess import call
import smbus

#Run setup script
GPIO.cleanup()
call("./etchAsketchSetup.sh")

#declare rotary encoders
myEncoderR = RotaryEncoder(eQEP2b)
myEncoderR.setAbsolute()
myEncoderR.enable()

myEncoderL = RotaryEncoder(eQEP1)
myEncoderL.setAbsolute()
myEncoderL.enable()

bus = smbus.SMBus(1)  # Use i2c bus 1
matrix = 0x70         # Use address 0x70

#setup the 8x8 led display
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)

#Green byte then red byte in left to right columbs
display = [0, 0, 0, 0, 0, 0, 0, 0,
コード例 #8
0
#!/usr/bin/env python
import sys
from Adafruit_BBIO.Encoder import RotaryEncoder, eQEP2, eQEP1
import Adafruit_BBIO.GPIO as GPIO
import time
import smbus

l_Encoder = RotaryEncoder(eQEP2)
l_Encoder.setAbsolute()
l_Encoder.enable()

r_Encoder = RotaryEncoder(eQEP1)
r_Encoder.setAbsolute()
r_Encoder.enable()

# Setting up matrix
bus = smbus.SMBus(2)  # Use i2c bus 1
matrix = 0x70         # Use address 0x70

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)

etch=[0x00, 0x00, 
        0x00, 0x00, 
        0x00, 0x00, 
        0x00, 0x00, 
        0x00, 0x00, 
        0x00, 0x00, 
        0x00, 0x00, 
        0x00, 0x00]
コード例 #9
0
import curses
import argparse

#Initialize matrix
bus = smbus.SMBus(2)  #Use i2c bus 1
matrix = 0x70  #Use address 0x70 for matrix

delay = 1  #Delay between images in second
bus.write_byte_data(matrix, 0x21, 0)  #Start oscillator
bus.write_byte_data(matrix, 0x81, 0)  #Disp on, blink off
bus.write_byte_data(matrix, 0xe7, 0)  #Full brightness

#Initialize encoder
myEncoder_1 = RotaryEncoder(eQEP1)
myEncoder_1.setAbsolute()
myEncoder_1.enable()
myEncoder_2 = RotaryEncoder(eQEP2)
myEncoder_2.setAbsolute()
myEncoder_2.enable()


def model_pos_to_view_pos(y, x):
    """
        Map model position to view position
    """
    return y + 1, 3 + 2 * x


def clear_status(height, width):
    """
        Clear window
コード例 #10
0
    horizontalPos = 0

    bus = smbus.SMBus(2)  # Use i2c bus 1
    matrix = 0x70  # Use address 0x70 for display
    address = 0x48  # Use address 0x48 for temp sensor

    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)

    greenBoard = [[0] * 8 for _ in range(8)]

    verticalMatrix = [0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80]

    green = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
    red = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]

    eraseBoard()

    encoder1 = RotaryEncoder(eQEP1)
    encoder2 = RotaryEncoder(eQEP2)

    encoder1.setAbsolute()
    encoder2.setAbsolute()
    encoder1.enable()
    encoder2.enable()

    red[userX] = red[userX] + verticalMatrix[userY]

    main()
コード例 #11
0
#!/usr/bin/env python3
# From: https://adafruit-beaglebone-io-python.readthedocs.io/en/latest/Encoder.html
from Adafruit_BBIO.Encoder import RotaryEncoder, eQEP1
import time

# Instantiate the class to access channel eQEP2, and initialize
# that channel

myEncoder = RotaryEncoder(eQEP1)
myEncoder.setAbsolute()
myEncoder.enable()

print('frequency ' + str(myEncoder.frequency))

# Get the current position
for i in range(1,50):
    print(myEncoder.position)
    time.sleep(0.1)
    
cur_position = myEncoder.position
print(cur_position)

# # Set the current position
# next_position = 15
# myEncoder.position = next_position

# # Reset position to 0
# myEncoder.zero()

# # Change mode to relative (default is absolute)
# # You can use setAbsolute() to change back to absolute
コード例 #12
0
os.system("config-pin P8_33 qep")
os.system("config-pin P8_35 qep")
os.system("config-pin P8_11 gpio")
os.system("config-pin P8_12 gpio")
os.system("config-pin P8_41 qep")
os.system("config-pin P8_42 qep")
 
i2cbus= smbus.SMBus(2)
led_addr= 0x70
i2cbus.write_byte_data(led_addr, 0x21, 0)
i2cbus.write_byte_data(led_addr, 0x81, 0)
i2cbus.write_byte_data(led_addr, 0xe7, 0)

myEncoderx = RotaryEncoder(eQEP2b)
myEncoderx.setAbsolute()
myEncoderx.enable()
myEncodery = RotaryEncoder(eQEP1)
myEncodery.setAbsolute()
myEncodery.enable()

GPIO.setup("P8_7", GPIO.IN)

cur_positionx = myEncoderx.position
cur_positiony = myEncodery.position

ledx=0
ledy=0
row=0
column=0

ledMatrix=[0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
コード例 #13
0
#9/24/19

from Adafruit_BBIO.Encoder import RotaryEncoder, eQEP1
from Adafruit_BBIO.Encoder import RotaryEncoder, eQEP2
import time
import smbus
import subprocess
import math
import Adafruit_BBIO.GPIO as GPIO

# Instantiate the class to access channel eQEP1 and eQEP2, and initialize
# that channel

myEncoder1 = RotaryEncoder(eQEP1)
myEncoder1.setAbsolute()
myEncoder1.enable()
myEncoder2 = RotaryEncoder(eQEP2)
myEncoder2.setAbsolute()
myEncoder2.enable()

encoder_x = 0
encoder_y = 0

GPIO.setup("P9_23", GPIO.IN)

bus = smbus.SMBus(2)
matrix = 0x70

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)
コード例 #14
0
}  #red picture location
yposPicture = {
    0: 0x01,
    1: 0x02,
    2: 0x04,
    3: 0x08,
    4: 0x10,
    5: 0x20,
    6: 0x40,
    7: 0x80
}  #y curosr location

#setup rotaery encoders 1 and 2
myEncoderLR = RotaryEncoder(eQEP1)
myEncoderLR.setAbsolute()
myEncoderLR.enable()
myEncoderUD = RotaryEncoder(eQEP2)
myEncoderUD.setAbsolute()
myEncoderUD.enable()

# Use i2c bus 1 adress 0x70
bus = smbus.SMBus(1)
matrix = 0x70
bus.write_byte_data(matrix, 0x21, 0)  # Start oscillator (page 10)
bus.write_byte_data(matrix, 0x81, 0)  # Disp on, blink off (p11)
bus.write_byte_data(matrix, 0xe7, 0)  # Full brightness (p15)


#callback funtion-- moves cursor based of used input
def userInput(encoderValue, encoderdirection):
    global xpos, ypos
コード例 #15
0
import sys
import curses
import time
import Adafruit_BBIO.GPIO as GPIO
from Adafruit_BBIO.Encoder import RotaryEncoder, eQEP1, eQEP2
import smbus

bus = smbus.SMBus(2)
matrix = 0x70  # Use address

# rotary encoders
rotary_vert = RotaryEncoder(eQEP1)
rotary_horiz = RotaryEncoder(eQEP2)
rotary_vert.setAbsolute()
rotary_vert.enable()
rotary_horiz.setAbsolute()
rotary_horiz.enable()

# led matrix var
display = [
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00
]
displayEmpty = [
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00
]

# Start oscillator (p10)
bus.write_byte_data(matrix, 0x21, 0)
コード例 #16
0
ファイル: sketch.py プロジェクト: wesley5040/ece434
def mprint():
    # Just writes the current column
    global cx, cy
    cols[cx] |= get(cy)
    bus.write_i2c_block_data(matrix, cx * 2, [cols[cx]])


def clear_scr():
    # Clears the grid
    bus.write_i2c_block_data(matrix, 0,
                             [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
    mprint()


clear_scr()
e1.enable()
e2.enable()
while True:
    dy, dx = ly - e2.position, lx - e1.position
    if (dy > 0) and (cy < 7):  # go down
        cy += 1
    if (dy < 0) and (cy > 0):  # go up
        cy -= 1
    if (dx > 0) and (cx < 7):  # go right
        cx += 1
    if (dx < 0) and (cx > 0):  # go left
        cx -= 1
    ly = e2.position
    lx = e1.position
    mprint()
    time.sleep(0.1)
コード例 #17
0
from Adafruit_BBIO.Encoder import RotaryEncoder, eQEP2, eQEP1
import smbus
import time

bus = smbus.SMBus(2)
matrix = 0x70
tmp101_1 = 0x4a
tmp101_0 = 0x48

# Instantiate the class to access channel eQEP2, and initialize that channel

Vertical = RotaryEncoder(eQEP2)
Horizontal = RotaryEncoder(eQEP1)
Vertical.setAbsolute()
Horizontal.setAbsolute()
Vertical.enable()
Horizontal.enable()

cursorX = 1
cursorY = 0x80

# The first byte is GREEN, the second is RED
clear = [
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00
]

state = [
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00
]
コード例 #18
0
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")

    xdim = 8
    ydim = 8
コード例 #19
0
import threading
import keys

ADC.setup()  # setup BBB ADC
PWM1 = "P8_13"  # motor 1 signal
PWM2 = "P8_19"  # motor 2 signal
##### 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()
コード例 #20
0
	[False,False,False,False,False,False,False,False],
	[False,False,False,False,False,False,False,False]]
			
grid = copy.deepcopy(reset)
first = True
pos = [0,0]

resetState = "P9_11"

GPIO.setup(resetState, GPIO.IN)

verticalEncoder = RotaryEncoder(eQEP1)
horizontalEncoder = RotaryEncoder(eQEP2)
verticalEncoder.setAbsolute()
horizontalEncoder.setAbsolute()
verticalEncoder.enable()
horizontalEncoder.enable()

bus.write_byte_data(matrix, 0x21, 0)
bus.write_byte_data(matrix, 0x81, 0)
bus.write_byte_data(matrix, 0xe7, 0)

output = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]



def mark():
	global grid
	global output
	for row in range(len(grid)):
コード例 #21
0
import time
#from Adafruit_AMG88xx import Adafruit_AMG88xx
from time import sleep
import Adafruit_BBIO.GPIO as GPIO
import Adafruit_BBIO.ADC as ADC
from Adafruit_BBIO.Encoder import RotaryEncoder, eQEP2
from Adafruit_AMG88xx import Adafruit_AMG88xx

myEncoder = RotaryEncoder(eQEP2)
myEncoder.enable()
sensor = Adafruit_AMG88xx(address=0x69, busnum=2)

ADC.setup()
analogPin = "P9_39"
Act = 'P8_7'
Actt = 'P8_9'
Fan = 'P8_11'
Fann = 'P8_15'
GPIO.setup(Act, GPIO.OUT)
GPIO.setup(Actt, GPIO.OUT)
GPIO.setup(Fan, GPIO.OUT)
GPIO.setup(Fann, GPIO.OUT)
GPIO.output(Act, GPIO.HIGH)

f = raw_input('file name : ')
filename = f + '.txt'
tdata = open(filename, 'a+')

tdata.write("Cal_Disp(mm),Temperature('c),Time(s) \n")
a = 0
コード例 #22
0
ファイル: etchAsketch.py プロジェクト: wildape1/ECE434
os.system("config-pin P8_33 qep")
os.system("config-pin P8_35 qep")
os.system("config-pin P8_41 qep")
os.system("config-pin P8_42 qep")

bus = smbus.SMBus(2)
matrix = 0x70
bus.write_byte_data(matrix, 0x21, 0)
bus.write_byte_data(matrix, 0x81, 0)
bus.write_byte_data(matrix, 0xe7, 0)

reset = "P8_11"

VEncoder = RotaryEncoder(eQEP1)
VEncoder.setAbsolute()
VEncoder.enable()

HEncoder = RotaryEncoder(eQEP2b)
HEncoder.setAbsolute()
HEncoder.enable()

# Set up pins as inputs or outputs
GPIO.setup(reset, GPIO.IN)

output = [
    0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00
]


def update(output, xcur, ycur):