def main(): global touchSensor touchSensor = TrillLib(1, "square", 0x28) touchSensor.setPrescaler(3) screenWidth, screenHeight = pyautogui.size() print("screen size", screenWidth, screenHeight) while (1): moveMouse() time.sleep(0.05)
def init(): global lastTouched, lastRingTouchTime, lastScroll, scroll global touchSensor, ringSensor lastTouched = time.time() lastRingTouchTime = time.time() lastScroll = 0 touchSensor = TrillLib(1, "square", 0x28) touchSensor.setPrescaler(3) ringSensor = TrillLib(1, "ring", 0x38) ringSensor.setPrescaler(3)
def init(): global screen, textHeight, font global lastRingTouch, sounds, tune, tunePointer global lineCol, hiCol, backCol, colours, tempo global ringSensor, trillCol, rx, ry, halo, energy global cylinderNumber, cylNames, changeCyl colours = [(160, 160, 160), (255, 0, 0), (255, 170, 0), (0, 255, 0), (0, 168, 255), (172, 0, 255), (255, 255, 255)] pygame.init() pygame.event.set_allowed(None) pygame.event.set_allowed([pygame.KEYDOWN, pygame.QUIT]) pygame.display.set_caption("Music Box") os.environ['SDL_VIDEO_WINDOW_POS'] = 'center' sWide = 400 sHigh = 400 padCo = (sWide // 2 - 100, 48) # top of screen screen = pygame.display.set_mode([sWide, sHigh], 0, 32) textHeight = 24 font = pygame.font.Font(None, textHeight) pygame.mixer.pre_init(44100, -16, 12, 512) pygame.mixer.init() sounds = [ pygame.mixer.Sound("music_box_sounds/" + str(i + 35) + ".wav") for i in range(50) ] pygame.mixer.set_num_channels(16) rawRect = pygame.Rect((338, 160), (338, 101)) lineCol = (0, 128, 255) backCol = (160, 160, 160) hiCol = (0, 255, 255) # highlight colour trillCol = (32, 32, 32) textCol = (0, 0, 0) ringSensor = TrillLib(1, "ring", 0x38) ringSensor.setPrescaler(3) ringSensor.readTrill() ry = 200 rx = 200 # set up halo ring halo = [] xc = rx yc = ry r = 150 thInc = (2 * 3.142) / 24.0 ang = -thInc for i in range(24): # center of halo LED ang += thInc xp = xc + r * math.cos(ang) yp = yc + r * math.sin(ang) halo.append((int(xp), int(yp))) energy = 24 lastRingTouch = 0 changeCyl = False cylinderNumber = 0 # initial cylinder to play cylNames = [ "blue_danube", "baa_baa", "green_sleeves", "god_save", "bach_air", "lullaby", "rock-a-bye", "twinkle" ] loadCylinder(cylinderNumber)
def main(): attachedSensors = [] availableSensors = [] for device in range(0x20, 0x41): # look at all possible addresses test = TrillLib(1, "none", 256) if test.testForI2CDevice(device, 0, 1): # a device is found print("Device found at address", hex(device)) del test test = TrillLib(1, "none", device) # initialise with valid address testType = test.getTypeNumber() print("Device identifies as", testType, trillType[testType]) attachedSensors.append([trillType[testType], device]) availableSensors.append(testType) del test print("Final Report") print("We found", len(availableSensors), "sensors on the I2C bus") print("List of sensor types attached with addresses (decimal) :-") print(attachedSensors)
def findSensors(): global trillSensor, attachedSensors, availableSensors, currentType, addr attachedSensors = [] availableSensors = [] for device in range(0x20, 0x41): # look at all possible addresses test = TrillLib(1, "none", 256) if test.testForI2CDevice(device, 0, 1): # a device is found #print("Device found at address", hex(device)) del test test = TrillLib(1, "none", device) # initialise with valid address testType = test.getTypeNumber() #print("Device identifies as", testType, trillType[testType]) attachedSensors.append([trillType[testType], device]) availableSensors.append(testType) del test currentType = availableSensors[0] initNewSensor(0, attachedSensors[0][0] in trillType) # first sensor found trillSensor.printDetails()
#!/usr/bin/env python #Trill Ring Jukebox - plays files in the Music Directory # use one finger round the ring to see the files, make a second touch to play it # make three touches to stop the track # by Mike Cook - Jan 2021 # need to do pip3 install omxplayer-wrapper first import os import time from omxplayer.player import OMXPlayer from pathlib import Path from trill_lib import TrillLib ringSensor = TrillLib(1, "ring", 0x38) ringSensor.setPrescaler(3) lastIndex = 0 lastTouched = time.time() fileNumber = 0 def main(): global lastIndex, lastTouched, fileNumber print("Trill Ring Jukebox") print("Press Ctrl-C to stop.") getFiles() print(soundList[fileNumber]) while 1: ringSensor.readTrill() numTouch = ringSensor.getNumTouches() if numTouch != 0: # when touched if numTouch == 2:
def initNewSensor(i, newSensor): global trillSensor, currentType, addr, entryValue, currentMode trillSensor = TrillLib(1, attachedSensors[i][0], attachedSensors[i][1]) addr = attachedSensors[i][1] currentType = availableSensors[i] entryValue = i # the entry in the scanned list we found if currentType == 3: currentMode = 3 trillSensor.setMode(modeTypes[currentMode]) trillSensor.setPrescaler(currentPrescale) trillSensor.setScanSettings(currentSpeed, currentBits) updateThreshold() trillSensor.updateBaseLine() updatePrams() # change address updateType() # tick in right box pygame.display.update() trillSensor.readTrill() return len(attachedSensors) # exit while loop