示例#1
0
    def __init__(self):
        # Configuration for CS and DC pins (these are FeatherWing defaults on M0/M4):
        cs_pin = digitalio.DigitalInOut(board.CE0)
        dc_pin = digitalio.DigitalInOut(board.D25)
        rst_pin = digitalio.DigitalInOut(board.D24)

        # Setup SPI bus using hardware SPI:
        spi = board.SPI()

        # Create the ILI9341-based display, used by the 2.8 inch display and touchscreen:
        disp = ili9341.ILI9341(
            spi,
            rotation=270,
            cs=cs_pin,
            dc=dc_pin,
            rst=rst_pin,
            baudrate=BAUDRATE
        )

        # swap height/width to rotate it to landscape!

        if disp.rotation %180 == 90:
            height = disp.width
            width = disp.height
        else:
            height = disp.height
            width = disp.width
示例#2
0
    def init_spi_display(self):
        self.spi = board.SPI()
        spi = self.spi
        cs = self.cs_pin
        dc = self.dc_pin
        rst = self.reset_pin
        baud = self.baudrate

        self.disp = ili9341.ILI9341(spi, cs=cs, dc=dc, rst=rst, baudrate=baud)
示例#3
0
    def __init__(self, x, y, pixel_per_spin):
        """standard display constructor

        Args:
            x (int): gamefield size x-axes
            y (int): gamefield size y-axes
        """
        if not os.path.exists("out"):
            os.makedirs('out')

        # hardware display
        self.hw_display = ili9341.ILI9341(
                                HW_SPI,
                                width=WIDTH,
                                height=HEIGHT,
                                baudrate=30000000,
                                cs=digitalio.DigitalInOut(CS_PIN),
                                dc=digitalio.DigitalInOut(DC_PIN),
                                rst=digitalio.DigitalInOut(RST_PIN))

        self.size_field = np.array([x, y])
        self.pixel_per_spin = pixel_per_spin
        self.size_window = 320, 240

        pygame.init()
        self.win = pygame.display.set_mode(list(self.size_window))
        pygame.display.set_caption("Ising spin field")
        self.font = pygame.font.SysFont(None, 24)

        self.set_up_level("", None)
        self.level_won = False
        self.level_new = False

        # Images
        dir_path = os.path.dirname(os.path.realpath(__file__)) 
        self.images = [
            [
                pygame.transform.scale(pygame.image.load(f"{dir_path}/images/spinup.png"), (self.pixel_per_spin, self.pixel_per_spin)),
                pygame.transform.scale(pygame.image.load(f"{dir_path}/images/spindown.png"), (self.pixel_per_spin, self.pixel_per_spin)),
                pygame.transform.scale(pygame.image.load(f"{dir_path}/images/questionmark.png"), (self.pixel_per_spin, self.pixel_per_spin)),
            ],
            [
                pygame.transform.scale(pygame.image.load(f"{dir_path}/images/spinup_fix.png"), (self.pixel_per_spin, self.pixel_per_spin)),
                pygame.transform.scale(pygame.image.load(f"{dir_path}/images/spindown_fix.png"), (self.pixel_per_spin, self.pixel_per_spin)),
            ],
        ]
    def __init__(self):

        # Configuration for CS and DC pins (these are PiTFT defaults):
        cs_pin = digitalio.DigitalInOut(board.CE0)
        dc_pin = digitalio.DigitalInOut(board.D25)
        reset_pin = digitalio.DigitalInOut(board.D24)

        # Config for display baudrate (default max is 24mhz):
        BAUDRATE = 24000000

        # Setup SPI bus using hardware SPI:
        spi = board.SPI()
        self.disp = ili9341.ILI9341(
            spi,
            rotation=90,  # 2.2", 2.4", 2.8", 3.2" ILI9341
            cs=cs_pin,
            dc=dc_pin,
            rst=reset_pin,
            baudrate=BAUDRATE,
        )
        # pylint: enable=line-too-long

        # Current location on display
        self.currentX = 0
        self.currentY = -2

        # Create blank image for drawing.
        # Make sure to create image with mode 'RGB' for full color.
        if self.disp.rotation % 180 == 90:
            self.height = self.disp.width  # we swap height/width to rotate it to landscape!
            self.width = self.disp.height
        else:
            self.width = self.disp.width  # we swap height/width to rotate it to landscape!
            self.height = self.disp.height

        self.image = Image.new("RGB", (self.width, self.height))

        # Get drawing object to draw on image.
        self.draw = ImageDraw.Draw(self.image)

        # Draw a black filled box to clear the image.
        self.draw.rectangle((0, 0, self.width, self.height),
                            outline=0,
                            fill=(0, 0, 0))
        self.disp.image(self.image)
示例#5
0
 def __init__(self):
     self.FONTSIZE = 15
     cs_pin = digitalio.DigitalInOut(board.CE0)
     dc_pin = digitalio.DigitalInOut(board.D25)
     reset_pin = digitalio.DigitalInOut(board.D24)
     BAUDRATE = 24000000
     spi = board.SPI()
     self.disp = ili9341.ILI9341(
         spi,
         rotation=90,
         cs=cs_pin,
         dc=dc_pin,
         rst=reset_pin,
         baudrate=BAUDRATE,
     )
     self.st = Adafruit_STMPE610_I2C(board.I2C())
     self.outlineColor = (30, 30, 30)
     self.bgColor = (50, 50, 50)
     self.textColor = (0, 0, 255)
     self.buttonColor = (0, 0, 255)
     self.barColor = self.textColor
     self.height = self.disp.width
     self.width = self.disp.height
     self.Page = 0
     self.currentPos = 0
     self.barPos = 190
     self.barHeight = 4
     self.barWidth = 280
     self.songlength = 0
     self.charList = "1234567890qwertyuiopasdfghjklzxcvbnm"
     self.secondList = "1234!@#$%^&*()-_=+[]{}\|/;:\'\",.<>?`~"
     self.albumURL = ""
     self.songName = ""
     self.artist = ""
     self.medFont = ImageFont.truetype(
         "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", self.FONTSIZE)
     self.smallFont = ImageFont.truetype(
         "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
         self.FONTSIZE - 3)
     self.drawStartup()
示例#6
0
    def __init__(self):
        BORDER = 20
        # Configuration for CS and DC pins (these are PiTFT defaults):
        cs_pin = digitalio.DigitalInOut(board.CE0)
        dc_pin = digitalio.DigitalInOut(board.D24)
        reset_pin = digitalio.DigitalInOut(board.D25)

        # Config for display baudrate (default max is 24mhz):
        BAUDRATE = 24000000

        # Setup SPI bus using hardware SPI:
        spi = board.SPI()

        self.disp = ili9341.ILI9341(spi, rotation=90, cs=cs_pin, dc=dc_pin, rst=reset_pin, baudrate=70000000)

        self.lines = []
        self.width = 320
        self.heigth = 240
        self.image = Image.new('RGB', (self.width, self.heigth))
        self.font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 20)
        # Get drawing object to draw on image.
        self.lines.append("")
        self._update()
示例#7
0
blood = (240, 96, 96)
white = (255, 255, 255)
black = (0,0,0)

# Configuration for CS and DC pins:
CS_PIN = CE0
DC_PIN = D24
RST_PIN = D25

# Setup SPI bus using hardware SPI:
spi = busio.SPI(clock=SCK, MOSI=MOSI, MISO=MISO)

# Create the ILI9341 display:
disp = ili9341.ILI9341(spi,
                          rotation=0,
                          cs=digitalio.DigitalInOut(CS_PIN),
                          rst=digitalio.DigitalInOut(RST_PIN),
                          dc=digitalio.DigitalInOut(DC_PIN))

# Create blank image for drawing.
# Make sure to create image with mode 'RGB' for full color.
if disp.rotation % 180 == 90:
    height = disp.width  # we swap height/width to rotate it to landscape!
    width = disp.height
else:
    width = disp.width  # we swap height/width to rotate it to landscape!
    height = disp.height


def update(humi, temp):
    image = Image.new("RGB", (width, height))
示例#8
0
#Define the CS, DC, and Reset pins
cs_pin = digitalio.DigitalInOut(board.P2_2)
dc_pin = digitalio.DigitalInOut(board.P2_4)
reset_pin = digitalio.DigitalInOut(board.P2_6)

# Config for display baudrate (default max is 24mhz):
BAUDRATE = 24000000

# Setup the SPI bus
spi = board.SPI()

# Create the display
disp = ili9341.ILI9341(spi,
                       rotation=90,
                       cs=cs_pin,
                       dc=dc_pin,
                       rst=reset_pin,
                       baudrate=BAUDRATE)

# ------------------------------------------------------------------------------
# Setup Button
# ------------------------------------------------------------------------------

import time
import Adafruit_BBIO.GPIO as GPIO

BUTTON0 = "P2_8"

# ------------------------------------------------------------------------------
# Setup FinalNews.py and FinalWeather.py and Outputs Desired
# ------------------------------------------------------------------------------
示例#9
0
import board
import busio
from digitalio import DigitalInOut
from adafruit_rgb_display import color565
import adafruit_rgb_display.ili9341 as ili9341

spi = busio.SPI(clock=board.P1_10, MOSI=board.P1_13)
dc_pin = DigitalInOut(board.P0_02)  # any pin!
reset_pin = DigitalInOut(board.P1_15)  # any pin!
cs_pin = DigitalInOut(board.P0_29)  # any pin!

display = ili9341.ILI9341(spi, cs=cs_pin, dc=dc_pin, rst=reset_pin)
display.fill(color565(255, 0, 0))
display.pixel(64, 64, 0)
示例#10
0
from adafruit_rgb_display import color565
import adafruit_rgb_display.ili9341 as ili9341

# Configuratoin for CS and DC pins (these are FeatherWing defaults on ESP8266):
CS_PIN = GPIO0
DC_PIN = GPIO15
# Config for display baudrate (default is 32mhz, about as fast as the ESP supports):
BAUDRATE = 32000000

# Setup SPI bus using hardware SPI:
spi = busio.SPI(clock=SCK, MOSI=MOSI, MISO=MISO)

# Create the ILI9341 display:
display = ili9341.ILI9341(spi,
                          cs=digitalio.DigitalInOut(CS_PIN),
                          dc=digitalio.DigitalInOut(DC_PIN),
                          baudrate=BAUDRATE)

# Main loop:
while True:
    # Clear the display
    display.fill(0)
    # Draw a red pixel in the center.
    display.pixel(120, 160, color565(255, 0, 0))
    # Pause 2 seconds.
    time.sleep(2)
    # Clear the screen blue.
    display.fill(color565(0, 0, 255))
    # Pause 2 seconds.
    time.sleep(2)
示例#11
0
文件: tft-image.py 项目: fl4p/tescan
import board
import digitalio
import adafruit_rgb_display.ili9341 as ili9341
from PIL import Image

# Setup display
cs_pin = digitalio.DigitalInOut(board.C0)
dc_pin = digitalio.DigitalInOut(board.C1)
disp = ili9341.ILI9341(board.SPI(), cs=cs_pin, dc=dc_pin, baudrate=64000000)

# Load image and convert to RGB
image = Image.open('blinka.bmp').convert('RGB')

# Display it (rotated by 90 deg)
disp.image(image, 90)
示例#12
0
    def __init__(self, cwd):
        super(Lcd, self).__init__(cwd)

        # Configuration for CS and DC pins (these are FeatherWing defaults on M0/M4):
        cs_pin = digitalio.DigitalInOut(board.CE0)
        dc_pin = digitalio.DigitalInOut(board.D6)
        reset_pin = digitalio.DigitalInOut(board.D5)

        # Config for display baudrate (default max is 24mhz):
        BAUDRATE = 64000000

        # Setup SPI bus using hardware SPI:
        spi = board.SPI()

        # Create the ST7789 display:
        self.disp = ili9341.ILI9341(spi,
                                    cs=cs_pin,
                                    dc=dc_pin,
                                    rst=reset_pin,
                                    baudrate=BAUDRATE,
                                    width=240,
                                    height=320)

        # Fonts
        self.title_font = ImageFont.truetype("DejaVuSans-Bold.ttf", 26)
        self.splash_font = ImageFont.truetype('DejaVuSans.ttf', 40)
        self.small_font = ImageFont.truetype("DejaVuSans.ttf", 18)
        #self.small_font = ImageFont.truetype(os.path.join(cwd, "fonts", "EtBt6001-JO47.ttf"), 11)

        # Colors
        self.background = (0, 0, 0)
        self.foreground = (255, 255, 255)
        self.highlight = (255, 0, 0)
        self.color_plugin = (100, 100, 240)
        self.color_plugin_bypassed = (80, 80, 80)

        # Width and height exchanged for 90 degree rotation during render/refresh
        self.width = self.disp.height
        self.height = self.disp.width
        self.top = 0
        self.left = 2

        # Zone dimensions
        self.zones = 8
        self.zone_height = {
            0: 38,
            1: 30,
            2: 2,
            3: 30,
            4: 2,
            5: 30,
            6: 48,
            7: 60
        }

        self.footswitch_xy = {
            0: (0, 0, (255, 255, 255)),
            1: (120, 0, (0, 255, 0)),
            2: (240, 0, (0, 0, 255))
        }

        # Element dimensions
        self.plugin_height = 22
        self.plugin_width = 56
        self.plugin_width_medium = 70
        self.plugin_rect_x_pad = 5
        self.plugin_bypass_thickness = 2
        self.plugin_label_length = 7
        self.footswitch_width = 70
        self.footswitch_ring_width = 5

        self.images = [
            Image.new('RGB',
                      (self.width,
                       self.zone_height[0])),  # Pedalboard / Preset Title bar
            Image.new('RGB',
                      (self.width, self.zone_height[1])),  # Analog Controllers
            Image.new('RGB',
                      (self.width, self.zone_height[2])),  # Plugin selection
            Image.new('RGB',
                      (self.width, self.zone_height[3])),  # Plugins Row 1
            Image.new('RGB',
                      (self.width, self.zone_height[4])),  # Plugin selection
            Image.new('RGB',
                      (self.width, self.zone_height[5])),  # Plugins Row 2
            Image.new('RGB',
                      (self.width, self.zone_height[6])),  # Plugin selection
            Image.new('RGB', (self.width, self.zone_height[7]))
        ]  # Footswitch Plugins

        self.draw = [
            ImageDraw.Draw(self.images[0]),
            ImageDraw.Draw(self.images[1]),
            ImageDraw.Draw(self.images[2]),
            ImageDraw.Draw(self.images[3]),
            ImageDraw.Draw(self.images[4]),
            ImageDraw.Draw(self.images[5]),
            ImageDraw.Draw(self.images[6]),
            ImageDraw.Draw(self.images[7])
        ]

        self.check_vars_set()
display (#3315) with the STMPE610 resistive touch controller.
"""

import board
import digitalio
import displayio
from adafruit_rgb_display import ili9341, color565
import adafruit_stmpe610

# Release any resources currently in use for the display
displayio.release_displays()

# Instantiate the 2.4" 320x240 TFT FeatherWing Display(#3315).
cs_pin = digitalio.DigitalInOut(board.D9)
dc_pin = digitalio.DigitalInOut(board.D10)
display = ili9341.ILI9341(board.SPI(), cs=cs_pin, dc=dc_pin)

# Fill the screen with black!
display.fill(color565(0, 0, 0))

# Instantiate the touchpad
ts_cs_pin = digitalio.DigitalInOut(board.D6)
ts = adafruit_stmpe610.Adafruit_STMPE610_SPI(
    board.SPI(),
    ts_cs_pin,
    calibration=((350, 3500), (350, 3500)),
    size=(display.width, display.height),
    disp_rotation=90,
    touch_flip=(True, True),
)
示例#14
0
"""

import board
import digitalio
from adafruit_rgb_display import ili9341, color565
import tsc2004

# Create a SPI bus object for the display
spi = board.SPI()

# Keyboard FeatherWing default pins
tft_cs = digitalio.DigitalInOut(board.D9)
tft_dc = digitalio.DigitalInOut(board.D10)

# Initialize display
display = ili9341.ILI9341(spi, cs=tft_cs, dc=tft_dc)

# Fill with black!
display.fill(color565(0, 0, 0))

# Create a I2C bus object for the touch driver
i2c = board.I2C()

# Create the touch driver object
tsc = tsc2004.TSC2004(i2c)

TS_MINX = 260
TS_MAXX = 4800
TS_MINY = 300
TS_MAXY = 2900
示例#15
0
import adafruit_rgb_display.ili9341 as ili9341

from PIL import Image, ImageDraw, ImageFont

cs_pin = digitalio.DigitalInOut(board.D15)  # USES THE SHIFTER SHIELD LAYOUT
dc_pin = digitalio.DigitalInOut(board.D13)
reset_pin = digitalio.DigitalInOut(board.D7)

BAUDRATE = 24000000  # Not sure about this

spi = busio.SPI(clock=board.SCLK, MOSI=board.MOSI, MISO=board.MISO)

disp = ili9341.ILI9341(
    spi,
    rotation=90,  # Not sure about this
    cs=cs_pin,
    dc=dc_pin,
    rst=reset_pin,
    baudrate=BAUDRATE,
)

if disp.rotation % 180 == 90:
    height = disp.width
    width = disp.height
else:
    width = disp.width
    height = disp.height

font = ImageFont.load_default()

# Image Test
#image = Image.open('logo.bmp').convert('RGB')
示例#16
0
  else:
    log.error("Can't display more than 18 volumes")


# Pins
disp_cs = digitalio.DigitalInOut(cs_pin)
disp_dc = digitalio.DigitalInOut(dc_pin)
touch_cs = digitalio.DigitalInOut(t_cs_pin)
touch_cs.direction = digitalio.Direction.OUTPUT
touch_cs.value = True

# Setup SPI bus using hardware SPI:
spi = busio.SPI(clock=clk_pin, MOSI=mosi_pin, MISO=miso_pin)

# Create the ILI9341 display:
display = ili9341.ILI9341(spi, cs=disp_cs, dc=disp_dc, rst=rst_pin, baudrate=spi_baud, rotation=270)

# Set backlight brightness out of 65535
# Turn off until first image is written to work around not having RST
led = pwmio.PWMOut(led_pin, frequency=5000, duty_cycle=0)
def backlight(on: bool):
  if on:
    led.duty_cycle = int(args.brightness*(2**16-1))
  else:
    led.duty_cycle = 0
backlight(False)

# Start bit=1, A[2:0], 12-bit=0, differential=0, power down when done=00
XPT2046_CMD_X   = 0b11010000  # X=101
XPT2046_CMD_Y   = 0b10010000  # Y=001
XPT2046_CMD_T0  = 0b10000100  # TEMP0=000, measured at 1x current
示例#17
0
# disp = st7789.ST7789(spi, rotation=90,                            # 2.0" ST7789
# disp = st7789.ST7789(spi, height=240, y_offset=80, rotation=180,  # 1.3", 1.54" ST7789
# disp = st7789.ST7789(spi, rotation=90, width=135, height=240, x_offset=53, y_offset=40, # 1.14" ST7789
# disp = hx8357.HX8357(spi, rotation=180,                           # 3.5" HX8357
# disp = st7735.ST7735R(spi, rotation=90,                           # 1.8" ST7735R
# disp = st7735.ST7735R(spi, rotation=270, height=128, x_offset=2, y_offset=3,   # 1.44" ST7735R
# disp = st7735.ST7735R(spi, rotation=90, bgr=True,                 # 0.96" MiniTFT ST7735R
# disp = ssd1351.SSD1351(spi, rotation=180,                         # 1.5" SSD1351
# disp = ssd1351.SSD1351(spi, height=96, y_offset=32, rotation=180, # 1.27" SSD1351
# disp = ssd1331.SSD1331(spi, rotation=180,                         # 0.96" SSD1331
disp = ili9341.ILI9341(
    spi,
    rotation=90,  # 2.2", 2.4", 2.8", 3.2" ILI9341
    cs=cs_pin,
    dc=dc_pin,
    rst=reset_pin,
    baudrate=BAUDRATE,
    width=430,
    height=320,
    x_offset=53,
    y_offset=40)
# pylint: enable=line-too-long

# Create blank image for drawing.
# Make sure to create image with mode 'RGB' for full color.
height = disp.width  # we swap height/width to rotate it to landscape!
width = disp.height
image = Image.new('RGB', (width, height))
rotation = 90

# Get drawing object to draw on image.
示例#18
0
import busio
import board
import digitalio
import adafruit_stmpe610
from adafruit_rgb_display import ili9341, color565

# Create library object using our Bus SPI port
spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)

# Adafruit Metro M0 + 2.8" Capacitive touch shield
cs_pin = digitalio.DigitalInOut(board.D9)
dc_pin = digitalio.DigitalInOut(board.D10)

# Initialize display
display = ili9341.ILI9341(spi, cs=cs_pin, dc=dc_pin)
# Fill with black!
display.fill(color565(0, 0, 0))

st_cs_pin = digitalio.DigitalInOut(board.D6)
st = adafruit_stmpe610.Adafruit_STMPE610_SPI(spi, st_cs_pin)

while True:
    if st.touched:
        while not st.buffer_empty:
            ts = st.touches
            for point in ts:
                # perform transformation to get into display coordinate system!
                y = point["y"]
                x = 4096 - point["x"]
                x = 2 * x // 30
示例#19
0
# Import Python Imaging Library
from PIL import Image, ImageDraw, ImageFont
from adafruit_rgb_display import color565
import adafruit_rgb_display.ili9341 as ili9341

# Configuration for CS and DC pins:
cs_pin = digitalio.DigitalInOut(board.CE0)
dc_pin = digitalio.DigitalInOut(board.D25)
reset_pin = digitalio.DigitalInOut(board.D24)
# Setup SPI bus using hardware SPI:
spi = board.SPI()
# Create the ILI9341 display:
disp = ili9341.ILI9341(
    spi,
    rotation=90,  # 2.2", 2.4", 2.8", 3.2" ILI9341
    cs=cs_pin,
    dc=dc_pin,
    rst=reset_pin,
    baudrate=BAUDRATE,
)


def get_ethermine_values(wallet):
    api_url = "https://api.ethermine.org/miner/{}/dashboard".format(wallet)
    r = requests.get(api_url)
    data = json.loads(r.text)
    ret_value = {}
    ret_value["unpaid"] = data["data"]["currentStatistics"][
        "unpaid"] / 1000000000000000000
    ret_value["workers"] = data["data"]["currentStatistics"]["activeWorkers"]
    ret_value["reported_hashrate"] = data["data"]["currentStatistics"][
        "reportedHashrate"] / 1000000
from adafruit_rgb_display.rgb import color565
import adafruit_rgb_display.ili9341 as ili9341

# Configuratoin for CS and DC pins (these are FeatherWing defaults on M0/M4):
cs_pin = digitalio.DigitalInOut(board.D9)
dc_pin = digitalio.DigitalInOut(board.D10)

# Config for display baudrate (default max is 24mhz):
BAUDRATE = 24000000

# Setup SPI bus using hardware SPI:
spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)

# Create the ILI9341 display:
display = ili9341.ILI9341(spi, cs=cs_pin, dc=dc_pin, baudrate=BAUDRATE)

# Main loop:
while True:
    # Fill the screen red, green, blue, then black:
    for color in ((255, 0, 0), (0, 255, 0), (0, 0, 255)):
        display.fill(color565(color))
    # Clear the display
    display.fill(0)
    # Draw a red pixel in the center.
    display.pixel(display.width // 2, display.height // 2, color565(255, 0, 0))
    # Pause 2 seconds.
    time.sleep(2)
    # Clear the screen a random color
    display.fill(
        color565(random.randint(0, 255), random.randint(0, 255),
示例#21
0
from digitalio import DigitalInOut, Direction, Pull
import busio
import digitalio
from adafruit_rgb_display import ili9341, color565
import bitmapfont



spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)

# For the Metro
cs = digitalio.DigitalInOut(board.D10)
dc = digitalio.DigitalInOut(board.D9)


display = ili9341.ILI9341(spi, cs=cs, dc=dc, width=320, height=240)
display.write(0x36, b'\x3E')

bf = bitmapfont.BitmapFont(320, 240, display.pixel)  # (240, 320, display.pixel)
bf.init()
 
led = simpleio.DigitalOut(board.D13)
GoButton = DigitalInOut(board.D4)  # pin 4 gets 3.3v to start the party.
GoButton.direction = Direction.INPUT
GoButton.pull = Pull.UP
  
def Rounder(IntInput, MaxNum):
    if (IntInput > MaxNum):
        # print("number over " + (str(MaxNum)) + "! Lowered " + (str(IntInput))) 
        IntInput /= 2
        IntInput = int(round(IntInput))
示例#22
0
def fast_vline(x, y, height, color):
    display.fill_rectangle(x, y, 1, height, color)


spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)

# # For the ESP8266
# cs = digitalio.DigitalInOut(board.GPIO0)
# dc = digitalio.DigitalInOut(board.GPIO15)

# For the Feather M0s
cs = digitalio.DigitalInOut(board.D9)
dc = digitalio.DigitalInOut(board.D10)

display = ili9341.ILI9341(spi, cs=cs, dc=dc)

# Initialize the GFX library, giving it the display pixel function as its pixel
# drawing primitive command.  The hline and vline parameters specify optional
# optimized horizontal and vertical line drawing functions.  You can remove these
# to see how much slower the filled shape functions perform!
graphics = gfx.GFX(240, 320, display.pixel, hline=fast_hline, vline=fast_vline)

display.fill(0)  # Clear the display
graphics.line(0, 0, 239, 319, color565(255, 0, 0))

# Now loop forever drawing random lines.
display.fill(0)
while True:
    x0 = randrange(0, 240)
    y0 = randrange(0, 320)
示例#23
0
#==| User Config |========================================================
#pylint: enable=bad-continuation

# Setup X data storage
x_time = [x * REFRESH_RATE for x in range(HIST_SIZE)]
x_time.reverse()

# Setup Y data storage
y_data = [ [deque([None] * HIST_SIZE, maxlen=HIST_SIZE) for _ in plot['line_config']]
           for plot in PLOT_CONFIG
         ]

# Setup display
disp = ili9341.ILI9341(board.SPI(), baudrate = 24000000,
                       cs  = digitalio.DigitalInOut(board.D4),
                       dc  = digitalio.DigitalInOut(board.D5),
                       rst = digitalio.DigitalInOut(board.D6))

# Setup plot figure
plt.style.use('dark_background')
fig, ax = plt.subplots(2, 1, figsize=(disp.width / 100, disp.height / 100))

# Setup plot axis
ax[0].xaxis.set_ticklabels([])
for plot, a in enumerate(ax):
    # add grid to all plots
    a.grid(True, linestyle=':')
    # limit and invert x time axis
    a.set_xlim(min(x_time), max(x_time))
    a.invert_xaxis()
    # custom settings
示例#24
0
import digitalio
import board
# Import Python Imaging Library
from PIL import Image, ImageDraw, ImageFont
from adafruit_rgb_display import color565
import adafruit_rgb_display.ili9341 as ili9341

# Configuration for CS and DC pins:
cs_pin = digitalio.DigitalInOut(board.CE0)
dc_pin = digitalio.DigitalInOut(board.D25)
reset_pin = digitalio.DigitalInOut(board.D24)
# Setup SPI bus using hardware SPI:
spi = busio.SPI(clock=SCK, MOSI=MOSI, MISO=MISO)
# Create the ILI9341 display:
display = ili9341.ILI9341(spi,
                          cs=digitalio.DigitalInOut(CS_PIN),
                          dc=digitalio.DigitalInOut(DC_PIN))


def get_ethermine_values(wallet):
    api_url = "https://api.ethermine.org/miner/{}/dashboard".format(wallet)
    r = requests.get(api_url)
    data = json.loads(r.text)
    ret_value = {}
    ret_value["unpaid"] = data["data"]["currentStatistics"][
        "unpaid"] / 1000000000000000000
    ret_value["workers"] = data["data"]["currentStatistics"]["activeWorkers"]
    ret_value["reported_hashrate"] = data["data"]["currentStatistics"][
        "reportedHashrate"] / 1000000
    ret_value["actual_hashrate"] = data["data"]["currentStatistics"][
        "currentHashrate"] / 1000000
示例#25
0
	def __init__(self, rowcount = NO_OF_ROWS, rowlength = ROW_LENGTH, rotation = 90):
		self.Event = threading.Event()
		self.threadLock = threading.Lock()
		threading.Thread.__init__(self, name='mytft')
		self.q = Queue(maxsize=12)
		self.rowcount = rowcount+1
		self.rowlength = rowlength
		self.last_prog_row = LAST_PROG_ROW
		self.rotation = rotation

		# Setup which pins we are using to control the hardware display
		if protoboard:
		# These are for the 2.2" tft soldered onto proto board.
			cs_pin = digitalio.DigitalInOut(board.CE0)
			dc_pin = digitalio.DigitalInOut(board.D18)		
			reset_pin = digitalio.DigitalInOut(board.D23)	
		else:				# wired tft
			cs_pin = digitalio.DigitalInOut(board.CE0)
			dc_pin = digitalio.DigitalInOut(board.D17)		
			reset_pin = digitalio.DigitalInOut(board.D23)

		# Setup SPI bus using hardware SPI:
		spi = board.SPI()
		self.disp = ili9341.ILI9341(spi, rotation=0,cs=cs_pin, dc=dc_pin, rst=reset_pin, baudrate=BAUDRATE)
		if self.disp.rotation % 180 == 90:
			height = self.disp.width   # we swap height/width to rotate it to landscape!
			width = self.disp.height
		else:
			width = self.disp.width   # we swap height/width to rotate it to landscape!
			height = self.disp.height

		self.image = Image.new("RGB", (width, height)) 	# Draw and text
		self.draw = ImageDraw.Draw(self.image)				# Get drawing object to draw on image.
		# Load a TTF Font
		self.big_font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", BIGFONTSIZE)
		self.time_font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", SMALLFONTSIZE)

#		self.disp = TFT.ILI9341(DC, rst=RST, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=64000000))
#		self.disp.begin()
#		self.disp.clear()	# black
		self.old_text = [' ' for i in range(self.rowcount)]	# used for clearing oled text
#		self.font = ImageFont.load_default()
#		self.font = ImageFont.truetype('binary/morningtype.ttf',FONTSIZE)
#		self.font = ImageFont.truetype('binary/secrcode.ttf',FONTSIZE)
#		self.font = ImageFont.truetype('binary/DS-DIGI.TTF',FONTSIZE)
#		self.font = [ImageFont.load_default() for i in range(self.rowcount)]
#		self.fontsize = [DEFAULT_FONT_SIZE for i in range(self.rowcount)]
#		self.fontsize[BIG_ROW] = 36
#		if TESTING:
#			self.fontsize[2] = 24
#			self.fontsize[3] = 24
#		for i in range(self.rowcount):
#			self.font[i] = ImageFont.truetype(FONT_DIR+'Hack-Regular.ttf',self.fontsize[i])
		# setup row colours
		self.rowcolour = [WHITE for i in range(self.rowcount)]			# set the defaults
		self.rowcolour[0] = YELLOW
#		self.rowcolour[self.rowcount-1] = BLUE
#		self.calc_offsets()
#		GPIO.setmode(GPIO.BCM)
#		GPIO.setup(LED,GPIO.OUT)
#		pi_pwm=GPIO.PWM(LED,100)		# pin number, frquency
#		pi_pwm.start(100)				# duty cycle
#		GPIO.setup(L_BUTTON, GPIO.IN, pull_up_down = GPIO.PUD_UP)
#		GPIO.setup(R_BUTTON, GPIO.IN, pull_up_down = GPIO.PUD_UP)
		self.myalarm = alarm.Alarm()
		self.mypwm = pwm.PWM()
		self.mysystem = system.System()