コード例 #1
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)
コード例 #2
0
#!/usr/bin/env python3
#Zachary Forster CM1646
#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)
コード例 #3
0
import Adafruit_BBIO.GPIO as GPIO

# 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
]
コード例 #4
0
ファイル: etch_matt_howlett.py プロジェクト: howletmj/ECE434
#!/usr/bin/env python3
import Adafruit_BBIO.GPIO as GPIO
import smbus
import time
from Adafruit_BBIO.Encoder import RotaryEncoder, eQEP2, eQEP1
myEncoder = RotaryEncoder(eQEP1)
myEncoder2 = RotaryEncoder(eQEP2)
myEncoder.setAbsolute()
myEncoder.enable()
myEncoder.zero()
myEncoder2.setAbsolute()
myEncoder2.enable()
myEncoder2.zero()
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)

Buttons = ["P8_27", "P8_28"]
matrixarray = [0x00]
for myButton in Buttons:
    print(myButton)
    GPIO.setup(myButton, GPIO.IN)
    GPIO.add_event_detect(myButton, GPIO.FALLING)


def main():
    etchwinsize = int(input(
        "Window Size nxn n = "))  #window size plus one column for row numbers
    global matrixarray
コード例 #5
0
import math
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()
コード例 #6
0
#!/usr/bin/env python3
# From: https://adafruit-beaglebone-io-python.readthedocs.io/en/latest/Encoder.html

from Adafruit_BBIO.Encoder import RotaryEncoder, eQEP2, eQEP1
import time

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

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

# Get the current position
for i in range(1,50) :
    print(myEncoder.position)
    time.sleep(0.1)
コード例 #7
0
# Mark Procter
# ECE434
# Homework 2

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
]
コード例 #8
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
コード例 #9
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]
コード例 #10
0
import time

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
コード例 #11
0
gameArrayPosX = 14
gameArrayPosY = 0
game_array = [
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x01
]
game = None
HEIGHT = 0
WIDTH = 0

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

# -- ENCODERS -- #
Encoder1 = RotaryEncoder(eQEP1)
Encoder2 = RotaryEncoder(eQEP2)

running = True


# Starts the default settings for ncurses
# stdscr - the terminal window
def initCurses(stdscr):
    # Allow keystroke reading
    curses.noecho()

    # turn off buffered input
    curses.cbreak()

    # Enable arrow keys
コード例 #12
0
#!/usr/bin/env python3
# From: https://adafruit-beaglebone-io-python.readthedocs.io/en/latest/Encoder.html
from Adafruit_BBIO.Encoder import RotaryEncoder, eQEP0, eQEP2
import time

# Instantiate the class to access channel eQEP2, and initialize
# that channel
left = RotaryEncoder(eQEP0)
right = RotaryEncoder(eQEP2)

# Get the current position

leftOld = 0
rightOld = 0

print(left.position, right.position)

while True:
    if left.position != leftOld or right.position != rightOld:
        print(left.position, right.position)

        leftOld = left.position
        rightOld = right.position

    time.sleep(0.1)
コード例 #13
0
ファイル: etchASketch.py プロジェクト: grinstba/ECE434
# Define button pins
Button1 = 'P9_11'
Button2 = 'P9_16'
Button3 = 'P9_17'
Button4 = 'P9_13'
Button5 = 'P9_30'

# Setup button pins to be input
GPIO.setup(Button1, GPIO.IN)
GPIO.setup(Button2, GPIO.IN)
GPIO.setup(Button3, GPIO.IN)
GPIO.setup(Button4, GPIO.IN)
GPIO.setup(Button5, GPIO.IN)

# Setup encoder1
encoder1 = RotaryEncoder(eQEP1)
encoder1.setAbsolute()
encoder1.enable()

# Setup encoder2
encoder2 = RotaryEncoder(eQEP2b)
encoder2.setAbsolute()
encoder2.enable()

# Generate a random starting location
xPos = random.randint(0, 7)
yPos = random.randint(0, 7)

# The first byte is GREEN, the second is RED.
hexGrid = [
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
コード例 #14
0
    1: 13,
    0: 15
}  #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
コード例 #15
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()
コード例 #16
0
ファイル: Etch-A-Sketch3.py プロジェクト: taylorrc/ECE434
#!/usr/bin/env python3
#chmod +x

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

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

# Setting up both encoders
rlEncoder = RotaryEncoder(eQEP1)
rlEncoder.setAbsolute()

udEncoder = RotaryEncoder(eQEP2)
udEncoder.setAbsolute()

# Configuring 8x8 Matrix
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)

# Setting up all button inputs
shakeButton = "P9_27"
exitButton = "P9_30"

# Adding event detection to each button
GPIO.setup(shakeButton, GPIO.IN)
GPIO.add_event_detect(shakeButton, GPIO.RISING)
コード例 #17
0
#chmod +x etch_a_sketch_encoders.py
#Author: Emily Dougherty
# 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
コード例 #18
0
from Adafruit_BBIO.Encoder import RotaryEncoder, eQEP1, eQEP2
import Adafruit_BBIO.GPIO as GPIO
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):
コード例 #19
0
from Adafruit_BBIO.Encoder import RotaryEncoder, eQEP2
import time
# Instantiate the class to access channel eQEP2, and initialize
# that channel
myEncoder = RotaryEncoder(eQEP2)

# Get the current position
cur_position = myEncoder.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
# Absolute: the position starts at zero and is incremented or
#           decremented by the encoder's movement
# Relative: the position is reset when the unit timer overflows.
myEncoder.setAbsolute()

# Read the current mode (0: absolute, 1: relative)
# Mode can also be set as a property
mode = myEncoder.mode

# Get the current frequency of update in Hz
freq = myEncoder.frequency

# Set the update frequency to 1 kHz
コード例 #20
0
ファイル: sketch.py プロジェクト: wesley5040/ece434
print("")
print("Controls:")
print("  Move up     :  eQEP2 clockwise")
print("  Move down   :  eQEP2 counter-clockwise")
print("  Move left   :  eQEP1 counter-clockwise")
print("  Move right  :  eQEP1 clockwise")
print("  Exit        :  ^C")
print("")

h, w = 8, 8  # i2c matrix is 8x8
cy, cx = 3, 3  # starting cell is here
ly, lx = 0, 0  # last x and y for the encoders
cols = [0, 0, 0, 0, 0, 0, 0, 0]  # the 8 columns
bus = smbus.SMBus(2)  # use bus 2 for the encoders
matrix = 0x70  # matrix is on i2c address 0x70
e1, e2 = RotaryEncoder(eQEP1), RotaryEncoder(eQEP2)
e1.setAbsolute()
e2.setAbsolute()


def get(b):
    # Makes a binary string to OR with
    return int(('0' * b) + '1' + ('0' * (7 - b)), 2)


def mprint():
    # Just writes the current column
    global cx, cy
    cols[cx] |= get(cy)
    bus.write_i2c_block_data(matrix, cx * 2, [cols[cx]])
コード例 #21
0
#!/usr/bin/env python3
# From: https://adafruit-beaglebone-io-python.readthedocs.io/en/latest/Encoder.html

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 = [
コード例 #22
0
import smbus
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("")
コード例 #23
0
os.system("config-pin P8_41 qep")
os.system("config-pin P8_42 qep")
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))

コード例 #24
0
	[False,False,False,False,False,False,False,False],
	[False,False,False,False,False,False,False,False],
	[False,False,False,False,False,False,False,False],
	[False,False,False,False,False,False,False,False],
	[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]


コード例 #25
0
alarm = 30  # 30 degress Celcius

# clear button state
clear = 0

# button pins
btn_clear = "P9_24"

# ALRM pin for temp sensor 1
ALRM = "P9_41"

# set LED pin
LED = "P9_15"

# rotary encoders
rotary_vertical = RotaryEncoder(eQEP2)
rotary_horizontal = RotaryEncoder(eQEP1)

# encoder vars
step_size = 4  # each turn off encoder = +/-4

# led matrix vars
column = {
    1: 0x00,
    2: 0x02,
    3: 0x04,
    4: 0x06,
    5: 0x08,
    6: 0x0A,
    7: 0x0C,
    8: 0x0E
コード例 #26
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")
コード例 #27
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
コード例 #28
0
ファイル: etchAsketch.py プロジェクト: wildape1/ECE434
os.system("config-pin P8_11 gpio")
os.system("config-pin P8_12 gpio")
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
]