Пример #1
0
import board
import busio
import time
import adafruit_tlc59711

spi = busio.SPI(board.SCK, MOSI=board.MOSI)
leds = adafruit_tlc59711.TLC59711(spi)


def link_absent():
    b_full = 65535
    b_none = 0
    leds[0] = (b_full, b_none, b_none)
    time.sleep(.25)
    leds[0] = (b_none, b_none, b_none)
    time.sleep(.25)


def link_present():
    b_full = 65535
    b_none = 0
    leds[0] = (b_full, b_none, b_none)


def link_nlog():
    b_full = 65535
    b_none = 0
    leds[1] = (b_full, b_none, b_none)
    time.sleep(.05)
    leds[1] = (b_none, b_none, b_none)
    time.sleep(.05)
Пример #2
0
import board
import busio
import digitalio
import adafruit_tlc59711

spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI)
rgb = adafruit_tlc59711.TLC59711(spi)

rgb.red_brightness = 0
rgb.green_brightness = 0
rgb.blue_brightness = 0
# spi_clock = digitalio.DigitalInOut(board.SCK)
# spi_clock.direction = digitalio.Direction.OUTPUT
# spi_mosi = digitalio.DigitalInOut(board.MOSI)
# spi_mosi.direction = digitalio.Direction.OUTPUT
# spi_miso = digitalio.DigitalInOut(board.MISO)
# spi_miso.direction = digitalio.Direction.INPUT

# print((42 * '*') + "\n" + "init busio.SPI")
spi = busio.SPI(board.SCK, MOSI=board.MOSI)

##########################################
print(42 * "*")
print("init TLC5957")
NUM_LEDS = 16
pixels = adafruit_tlc59711.TLC59711(
    spi=spi,
    pixel_count=NUM_LEDS,
)

print("pixel_count", pixels.pixel_count)
print("chip_count", pixels.chip_count)
print("channel_count", pixels.channel_count)

##########################################
# main loop
print(42 * "*")
print("rainbow loop")
hue_offset = 0
while True:
    brightness = 0.8
    color = fancyled.CHSV(hue_offset, 1.0, 1.0)
    color = fancyled.gamma_adjust(color, brightness=brightness)
# simple demo of the TLC59711 16-bit 12 channel LED PWM driver.
# Shows the minimal usage - how to set pixel values in a few ways.
# Author: Tony DiCola

import board
import busio

import adafruit_tlc59711

print("tlc59711_simpletest.py")

# Define SPI bus connected to chip.
# You only need the clock and MOSI (output) line to use this chip.
spi = busio.SPI(board.SCK, MOSI=board.MOSI)
pixels = adafruit_tlc59711.TLC59711(spi, pixel_count=16)

# examples how to set the pixels:
# range:
# 0 - 65535
# or
# 0.0 - 1.0
# every pixel needs a color -
# give it just a list or tuple with 3 integer values: R G B

# set all pixels to a very low level
pixels.set_pixel_all((10, 10, 10))

# every chip has 4 Pixels (=RGB-LEDs = 12 Channel)
pixels[0] = (100, 100, 100)
pixels[1] = (0, 0, 100)
Пример #5
0
"""


import time

import board
import busio

import adafruit_tlc59711


##########################################
PIXEL_COUNT = 16

spi = busio.SPI(board.SCK, MOSI=board.MOSI)
pixels = adafruit_tlc59711.TLC59711(spi, pixel_count=PIXEL_COUNT)


##########################################
# test function


def channelcheck_update_pixel(offset):
    """Channel check pixel."""
    # print("offset", offset)

    pixels.set_pixel_16bit_value(offset, 1000, 100, 0)
    # clear last pixel
    last = offset - 1
    if last < 0:
        last = PIXEL_COUNT - 1
Пример #6
0
    pixel_index = (board_offset * LEDBoard_pixel_count) + pixel_offset

    return pixel_index


pmap = PixelMap2D(
    row_count=Matrix_row_count,
    col_count=Matrix_col_count,
    map_function=mymap_LEDBoard_4x4_16bit,
)

##########################################
# led controller

spi = busio.SPI(board.SCK, MOSI=board.MOSI)
pixels = adafruit_tlc59711.TLC59711(spi, pixel_count=Matrix_pixel_count)


def pixels_init_BCData():
    """Initialise global brightness control data."""
    BCValues = adafruit_tlc59711.TLC59711.calculate_BCData(
        Ioclmax=18,
        IoutR=18,
        IoutG=11,
        IoutB=13,
    )
    print("BCValues = {}".format(BCValues))
    pixels.bcr = BCValues[0]
    pixels.bcg = BCValues[1]
    pixels.bcb = BCValues[2]
    pixels.update_BCData()
Пример #7
0
# Simple demo of the TLC59711 16-bit 12 channel LED PWM driver.
# Shows setting channel values in a few ways.
# Author: Tony DiCola, Steve Pomeroy

import adafruit_tlc59711

# Define the TLC59711 instance. Specify the bus and device.
bus = 0
device = 0
leds = adafruit_tlc59711.TLC59711(bus, device)
# Optionally you can disable the auto_show behavior that updates the chip
# as soon as any channel value is written.  The default is True/on but you can
# disable and explicitly call show to control when updates happen for better
# animation or atomic RGB LED updates.
#leds = adafruit_tlc59711.TLC59711(spi, auto_show=False)

# There are a couple ways to control the channels of the chip.
# The first is using an interface like a strip of NeoPixels.  Index into the
# class for the channel and set or get its R, G, B tuple value.  Note the
# component values are 16-bit numbers that range from 0-65535 (off to full
# brightness).  Remember there are only 4 channels available too (0 to 3).
# For example set channel 0 (R0, G0, B0) to half brightness:
leds[0] = (32767, 32767, 32767)
# Dont forget to call show if you disabled auto_show above.
#leds.show()

# Or to set channel 1 to full red only (green and blue off).
leds[1] = (65535, 0, 0)

# You can also explicitly control each R0, G0, B0, R1, B1, etc. channel
# by getting and setting its 16-bit value directly with properties.
Пример #8
0
class ShowcaseApp(App):
    #kivy properties
    brightness = StringProperty()
    flo_read = ListProperty([0, 0, 0])
    hierarchy_index = ListProperty([])
    DNA_result = StringProperty()
    #config
    config = configparser.ConfigParser()
    config.read('config.ini')

    #brightness =config['BASIC']['brightness']
    led_red_on = False
    led_blue_on = False
    adc_gain = 1
    sample_rate = 8
    unit = NumericProperty(1)
    home_screen = Builder.load_file("./kv/home.kv")
    #adc_loop = False
    try:
        spi = busio.SPI(board.SCK, MOSI=board.MOSI)

    except:
        print('>>>>>>>>>>>>>>>spi init failed<<<<<<<<<<<<<<<<<<<')
    try:
        leds = adafruit_tlc59711.TLC59711(spi, auto_show=False)
        leds[0] = (0, 0, 0)
        leds[1] = (0, 0, 0)
        leds.show()
    except:
        print('>>>>>>>>>>>>>>>led init failed<<<<<<<<<<<<<<<<<<<')
    try:
        i2c = busio.I2C(board.SCL, board.SDA)
    except:
        print('>>>>>>>>>>>>>>>i2c init failed<<<<<<<<<<<<<<<<<<<')
    try:
        ads = ADS.ADS1115(i2c,
                          gain=adc_gain,
                          data_rate=sample_rate,
                          address=0x48)
    except:
        print('>>>>>>>>>>>>>>>ads init failed<<<<<<<<<<<<<<<<<<<')

    try:
        file = open("/sys/class/backlight/rpi_backlight/brightness", "r")
        brightness = file.read()
        file.close()
    except:
        print('>>>>>>>>>>>>>>>Brightness init error<<<<<<<<<<<<<<<<<<<<<<<')

    def build(self):
        self.root = Builder.load_file('kv/main.kv')
        self.title = 'Fluorometer'
        Window.size = (800, 480)

        #self.go_home()
        self.hierarchy_index.append('home')
        print(self.hierarchy_index)
        #screen = Builder.load_file("./kv/home.kv")
        self.root.ids.sm.switch_to(self.home_screen, direction='right')
        self.root.ids.main_label.text = 'Choose an assay'
        self.root.ids.back_btn.disabled = True

    def go_home(self):

        if (len(self.hierarchy_index) == 1) and (self.hierarchy_index[0]
                                                 == 'home'):
            return
        del self.hierarchy_index[:]
        self.hierarchy_index.append('home')
        print(self.hierarchy_index)
        #screen = Builder.load_file("./kv/home.kv")
        self.root.ids.sm.switch_to(self.home_screen, direction='right')
        self.root.ids.main_label.text = 'Choose an assay'
        self.root.ids.back_btn.disabled = True

    def go_settings(self):
        if (len(self.hierarchy_index) == 1) and (self.hierarchy_index[0]
                                                 == 'settings'):
            return
        del self.hierarchy_index[:]
        self.hierarchy_index.append('settings')
        print(self.hierarchy_index)
        screen = Builder.load_file("./kv/settings.kv")
        self.root.ids.sm.switch_to(screen, direction='right')
        self.root.ids.main_label.text = 'Settings'
        self.root.ids.back_btn.disabled = True

    def go_screen(self, screen_name):
        self.hierarchy_index.append('{0}'.format(screen_name))
        print(self.hierarchy_index)
        #self.previous_screen = self.current_screen
        #self.current_screen = screen_name

        screen = self.load_screen(screen_name)

        #sm = self.root.ids.sm
        #sm.switch_to(screen, direction='left')

        self.root.ids.sm.switch_to(screen, direction='left')
        self.root.ids.main_label.text = '{0}'.format(screen_name)
        self.root.ids.back_btn.disabled = False

    def go_previous(self):
        if len(self.hierarchy_index) == 2:
            if self.hierarchy_index[0] == 'home':
                self.go_home()
                return
            if self.hierarchy_index[0] == 'settings':
                self.go_settings()
                return

        self.hierarchy_index.pop()
        previous_name = self.hierarchy_index[-1]
        print(self.hierarchy_index)
        #self.previous_screen = self.current_screen
        #self.current_screen = screen_name

        screen = self.load_screen(previous_name)

        #sm = self.root.ids.sm
        #sm.switch_to(screen, direction='left')

        self.root.ids.sm.switch_to(screen, direction='right')
        self.root.ids.main_label.text = '{0}'.format(previous_name)

    def load_screen(self, screen_name):
        screen = Builder.load_file("./kv/{0}.kv".format(screen_name))
        return screen

#-----------------------------Settings---------------------------------

    def brightness_control(self, *args):
        self.brightness = str(int(args[1]))
        try:
            file = open("/sys/class/backlight/rpi_backlight/brightness", "w")
            file.write(self.brightness)
            file.close()
        except:
            print('Brightness error')

    def blue_led_test(self):
        try:
            print("SCK, MOSI:")
            print(board.SCK)
            print(board.MOSI)
            #spi = busio.SPI(board.SCK, MOSI=board.MOSI)
            #leds = adafruit_tlc59711.TLC59711(self.spi, auto_show=False)
            if self.led_blue_on:
                self.leds[0] = (0, 0, 0)
                self.led_blue_on = False
                self.leds.show()
                print('Blue Led off')
                return
            else:
                self.leds[0] = (65535, 65535, 65535)
                self.led_blue_on = True
                self.leds.show()
                print('Blue Led on')
                return
        except:
            print('Blue test false')

    def red_led_test(self):
        print("SCK, MOSI:")
        print(board.SCK)
        print(board.MOSI)
        #leds = adafruit_tlc59711.TLC59711(self.spi, auto_show=False)
        if self.led_red_on:
            self.leds[1] = (0, 0, 0)
            self.led_red_on = False
            self.leds.show()
            print('Red Led off')
            return
        else:
            self.leds[1] = (65535, 65535, 65535)
            self.led_red_on = True
            self.leds.show()
            print('Red Led on')
            return

    def adc_test(self):
        try:

            #chan0 = AnalogIn(ads, ADS.P0)
            chan1 = AnalogIn(self.ads, ADS.P1)
            chan2 = AnalogIn(self.ads, ADS.P2)
            chan3 = AnalogIn(self.ads, ADS.P3)
            #print("{:>5}\t{:>5.3f}".format(chan0.value, chan0.voltage))
            while True:
                #print("channel 01 {:>5}\t{:>5.3f}".format(chan3.value, chan3.voltage))
                #print("channel 02 {:>5}\t{:>5.3f}".format(chan2.value, chan2.voltage))
                #print("channel 03 {:>5}\t{:>5.3f}".format(chan1.value, chan1.voltage))
                #print("----------------")
                adc01 = chan3.value
                adc02 = chan2.value
                adc03 = chan1.value
                print("{0}, {1}, {2}".format(adc01, adc02, adc03))
                time.sleep(0.3)

        except:
            print('ADC test begin false')

    def adc_diff(self):
        try:
            chan1 = AnalogIn(self.ads, ADS.P1)
            chan2 = AnalogIn(self.ads, ADS.P2)
            chan3 = AnalogIn(self.ads, ADS.P3)
            adc01 = chan3.value
            adc02 = chan2.value
            adc03 = chan1.value
            print("befor led {:>5}\t{:>5}\t{:>5}".format(adc01, adc02, adc03))

            self.leds[0] = (32767, 32767, 32767)
            self.leds.show()
            time.sleep(0.5)
            adc01_af = chan3.value
            adc02_af = chan2.value
            adc03_af = chan1.value
            print("after led {:>5}\t{:>5}\t{:>5}".format(
                adc01_af, adc02_af, adc03_af))
            adc01 = adc01_af - adc01
            adc02 = adc02_af - adc02
            adc03 = adc03_af - adc03

            print("after dif {:>5}\t{:>5}\t{:>5}".format(adc01, adc02, adc03))
            print("---------------------------------------")
            self.leds[0] = (0, 0, 0)
            self.leds.show()

        except:
            print('ADC diff test failed')


#-----------------------------Fluorometer---------------------------------

    def adc_aver(self):
        try:
            chan1sum = 0
            chan2sum = 0
            chan3sum = 0
            chan1 = AnalogIn(self.ads, ADS.P1)
            chan2 = AnalogIn(self.ads, ADS.P2)
            chan3 = AnalogIn(self.ads, ADS.P3)
            for i in range(10):
                chan1read = chan1.value
                chan2read = chan2.value
                chan3read = chan3.value
                chan1sum = chan1sum + chan1read
                chan2sum = chan2sum + chan2read
                chan3sum = chan3sum + chan3read
                print(
                    str(chan3read) + " " + str(chan2read) + " " +
                    str(chan1read))
            print('ADC average: ')
            print(chan3sum / 10)
            print(chan2sum / 10)
            print(chan1sum / 10)
            self.flo_read[0] = str(chan3sum / 10)
            self.flo_read[1] = str(chan2sum / 10)
            self.flo_read[2] = str(chan1sum / 10)
        except:
            print('ADC average test failed')

    def adc_aver_with_led(self):
        try:
            self.leds[0] = (32767, 32767, 32767)
            self.leds.show()
            time.sleep(0.3)
            chan1sum = 0
            chan2sum = 0
            chan3sum = 0
            chan1 = AnalogIn(self.ads, ADS.P1)
            chan2 = AnalogIn(self.ads, ADS.P2)
            chan3 = AnalogIn(self.ads, ADS.P3)
            for i in range(10):
                chan1read = chan1.value
                chan2read = chan2.value
                chan3read = chan3.value
                chan1sum = chan1sum + chan1read
                chan2sum = chan2sum + chan2read
                chan3sum = chan3sum + chan3read
                print(
                    str(chan3read) + " " + str(chan2read) + " " +
                    str(chan1read))
                time.sleep(0.3)
            print("result led always on: ")
            print(
                str(chan3sum / 10) + " " + str(chan2sum / 10) + " " +
                str(chan1sum / 10))
            self.leds[0] = (0, 0, 0)
            self.leds.show()
            self.flo_read[0] = str(chan3sum / 10)
            self.flo_read[1] = str(chan2sum / 10)
            self.flo_read[2] = str(chan1sum / 10)

        except:
            print('ADC average led always on failed')

    def adc_aver_with_blink(self):

        try:
            chan1sum = 0
            chan2sum = 0
            chan3sum = 0
            chan1 = AnalogIn(self.ads, ADS.P1)
            chan2 = AnalogIn(self.ads, ADS.P2)
            chan3 = AnalogIn(self.ads, ADS.P3)

            for i in range(10):
                self.leds[0] = (32767, 32767, 32767)
                self.leds.show()
                time.sleep(0.3)
                chan1read = chan1.value
                chan2read = chan2.value
                chan3read = chan3.value
                chan1sum = chan1sum + chan1read
                chan2sum = chan2sum + chan2read
                chan3sum = chan3sum + chan3read
                print(
                    str(chan3read) + " " + str(chan2read) + " " +
                    str(chan1read))
                self.leds[0] = (0, 0, 0)
                self.leds.show()
                time.sleep(0.3)
            print("result blink: ")
            print(
                str(chan3sum / 10) + " " + str(chan2sum / 10) + " " +
                str(chan1sum / 10))
            self.flo_read[0] = str(chan3sum / 10)
            self.flo_read[1] = str(chan2sum / 10)
            self.flo_read[2] = str(chan1sum / 10)
            #self.root.ids.flo_read1.text = '{0}'.format(str(chan3sum/10))
            #self.root.ids.flo_read2.text = '{0}'.format(str(chan2sum/10))
            #self.root.ids.flo_read3.text = '{0}'.format(str(chan1sum/10))
        except:
            print('ADC average blink failed')

    def read_standard(self):
        print('read stadndard')
        fake_read = 400
        ShowcaseApp.config['DNA']['v'] = str(fake_read)
        with open('config.ini', 'w') as configfile:
            ShowcaseApp.config.write(configfile)

    def read_tube(self):
        fake_read = 459.40
        k = float(ShowcaseApp.config['DNA']['k'])
        g = float(ShowcaseApp.config['DNA']['g'])
        #r = float(ShowcaseApp.config['DNA']['r'])
        n = float(ShowcaseApp.config['DNA']['n'])
        v = float(ShowcaseApp.config['DNA']['v'])
        s = float(ShowcaseApp.config['DNA']['s'])
        print(v)
        r = (v - g) * ((pow(s, n) + k) / pow(s, n))
        ShowcaseApp.DNA_result = str(
            pow(k * (fake_read - g) / (r - (fake_read - g)), 1 / n))
        #print(ShowcaseApp.DNA_result)
        self.go_screen('DNA Result')