Example #1
0
 def __init__(self, config):
     if not hasattr(self, 'config'):
         self.config = config
     self.lcd = lcd160cr.LCD160CR(config['orientation'])
     self.lcd.erase()
     self.lcd.set_pen(self.colo['white'], self.colo['black'])
     self.lcd.set_text_color(self.colo['white'], self.colo['black'])
     self.lcd.set_orient(lcd160cr.LANDSCAPE)
     self.lcd.set_font(1)
     self.lcd.set_brightness(14)
     self.h_half = round(self.lcd.h / 2)
     self.w_half = round(self.lcd.w / 2)
     self.draw_menu()
Example #2
0
	def __init__(self, all_resistors=[1600, 800, 400, 200, 100, 50, 25, 12.5, 6.25, 3.125]):
		"""Inits Resistor class."""
		self.all_resistors = all_resistors
		self.current_resistor_binary = [1,1,1,1,1,1,1,1,1,1]
		self.current_resistor = (self.dot_prod(self.negate_binary_list(self.current_resistor_binary), self.all_resistors) + 1000.0)
		self.i2c = I2C(2)
		self.i2c = I2C(2, I2C.MASTER)
		self.i2c.init(I2C.MASTER, baudrate=20000)
		info = self.i2c.scan()
		#print("scan ",info)

		#LCD
		self.lcd = lcd160cr.LCD160CR('YX')
		self.lcd.set_orient(lcd160cr.LANDSCAPE)
		self.lcd.set_pos(30, 20)
		self.lcd.set_text_color(self.lcd.rgb(255, 255, 255), self.lcd.rgb(0, 0, 0))
		self.lcd.set_font(1,1,0,0,0)

		self.lcd.erase()
		self.lcd.set_pos(25, 60)
		self.lcd.write("0000.000Ω")

		self.adc = pyb.ADC(pyb.Pin('X19'))
		self.adc_value = float(self.adc.read()/4096.0)
Example #3
0
import lcd160cr
import pyb

lcd = lcd160cr.LCD160CR('X')

fg = lcd.rgb(0, 0, 0)
bg = lcd.rgb(255, 255, 255)
lcd.set_pen(fg, bg)

padding = 10
w = 40
h = 30


def draw_buttons():
    # top left
    lcd.rect(padding, padding, w, h)

    # top right
    lcd.rect(lcd.w - w - padding, padding, w, h)

    # bottom left
    lcd.rect(padding, lcd.h - h - padding, w, h)

    # bottom right
    lcd.rect(lcd.w - w - padding, lcd.h - h - padding, w, h)


def draw_message_box():
    x = int((lcd.w / 2) - (w / 2))
    y = int((lcd.h / 2) - (h / 2))
Example #4
0
def get_lcd(lcd):
    if type(lcd) is str:
        lcd = lcd160cr.LCD160CR(lcd)
    return lcd
Example #5
0
import math

#initialize switch
sw = pyb.Switch()

#-------------------------- LCD ----------------------------

#TESTING
#import lcd160cr_test
#lcd160cr_test.test_all('X')

#####
import lcd160cr

#lcd object
lcd = lcd160cr.LCD160CR('X')  #sets display to X position (there is just XandY)

#---- simple line -----
#set drawin color (red,green,blue) , set display background
#lcd.set_pen(lcd.rgb(255, 0, 0), lcd.rgb(64, 64, 128))
#draw line with current color
#lcd.line(10,10,50,80)
#lcd.erase()

#---- random rectangles ----
'''
from random import randint
for i in range(1000):
    fg = lcd.rgb(randint(128, 255), randint(128, 255), randint(128, 255))
    bg = lcd.rgb(randint(0, 128), randint(0, 128), randint(0, 128))
    lcd.set_pen(fg, bg)
Example #6
0
import os
print('MicroPython {}; {}'.format(os.uname()[3], os.uname()[4]))
import gc
gc.collect()
print('Initial available RAM: {} bytes'.format(gc.mem_free()))
import pyb
import math
import time
import lcd160cr
gc.collect()
print('RAM after importing some modules: {} bytes'.format(
    gc.mem_free()))  # 99120 bytes

try:
    flagLCD160CR = True
    lcd = lcd160cr.LCD160CR(
        'YX')  # display on the left side of Pyboard, default position
except OSError:
    print('LCD160CR display not found on the right side of Pyboard'
          )  # OSError: [Errno 19] ENODEV
    flagLCD160CR = False

if flagLCD160CR:
    print('LCD160CR display turned on')
    ti_us = time.ticks_us()
    import framebuf
    print('Time to import framebuf module: {:.3f} ms'.format(
        time.ticks_diff(time.ticks_us(), ti_us) * 1.0e-3))
    fbufh = lcd.h - 10
    fbuf = framebuf.FrameBuffer(bytearray(lcd.w * fbufh * 2), lcd.w, fbufh,
                                framebuf.RGB565)
    gc.collect()
Example #7
0
phonebook = {
    "xxxxxxx": "+xxxxxxxxxxxx",
    "xxxxxxx": "+xxxxxxxx xxx",
    "xxxxxxx": "+xxxxxxxxxxxx",
    "xxxxxxx": "+xxxxxxxxxxxx",
    "xxxxxxx": "+xxxxxxxxxxxx",
    "xxxxxxx": "+xxxxxxxxxxxx"
}

inverted_pb = dict((v, k) for k, v in phonebook.items())
national_pb = dict((v.replace('+44', '0'), k) for k, v in phonebook.items())

from ui import DialScreen, CallScreen, HomeScreen, PhoneBookScreen, SettingsScreen, MessageScreen, SendsmsScreen

lcd = lcd160cr.LCD160CR('Y')
lcd.set_orient(lcd160cr.PORTRAIT)
dial = DialScreen(lcd, 'Dial')
call = CallScreen(lcd, 'Calling')
incoming = CallScreen(lcd, 'Incoming', True)
home = HomeScreen(lcd, 'UpyPhone')
book = PhoneBookScreen(lcd, 'Phone Book', phonebook)
messages = MessageScreen(lcd, 'Messages')
sendsms = SendsmsScreen(lcd, '')
settings = SettingsScreen(lcd, 'Settings')
applications = upyapps.ManageAppScreen(lcd, lambda x=home: switch_to(x))
phone = sim800l.SIM800L(4)
app = upyapps.CurrencyApp(lcd, phone, lambda x=applications: switch_to(x))
applications.install(app, lambda x=app: switch_to(x))
app = upyapps.WeatherApp(lcd, phone, lambda x=applications: switch_to(x))
applications.install(app, lambda x=app: switch_to(x))
Example #8
0
import lcd160cr, machine, utime

lcd = lcd160cr.LCD160CR("Y")
# X if USB is visible and Y if covered by screen
lcd.set_orient(lcd160cr.PORTRAIT)
# PORTRAIT or LANDSCAPE
lcd.set_startup_deco(lcd160cr.STARTUP_DECO_MLOGO)
lcd.set_brightness(10)
lcd.erase()
lcd.set_pos(0, 0)
lcd.set_text_color(lcd.rgb(255, 255, 255), lcd.rgb(0, 0, 0))
lcd.set_font(2)
lcd.set_pos(0, 0)

lcd.set_pos(0, 0)
lcd.write('Hello MicroPython!')
print('touch:', lcd.get_touch())

lcd.write("Code Check")
for i in range(5):
    lcd.write("i = " + str(i) + "\r\n")
    utime.sleep_ms(1000)
Example #9
0
from pyb import Pin
from pyb import Timer
from pyb import RTC
import uasyncio as asyncio

from mainconfig import lcd_pins
from ui.screen import Screen
from makhina.control import MakhinaControl
from server import ModbusMaster

# set more detailed information on the exception
micropython.alloc_emergency_exception_buf(100)

if 'logs' not in os.listdir('/sd'):
    os.mkdir('/sd/logs')
if 'recipes' not in os.listdir('/sd'):
    os.mkdir('/sd/recipes')

# lcd
lcd = lcd160cr.LCD160CR(lcd_pins)
lcd.set_orient(lcd160cr.PORTRAIT)
lcd.set_pen(lcd.rgb(255, 255, 255), lcd.rgb(0, 0, 0))
lcd.set_brightness(29)
lcd.erase()

# gui
makhina_control = MakhinaControl()
main_screen = Screen(lcd, makhina_control)
master = ModbusMaster(makhina_control, main_screen)
import os
print('MicroPython {}; {}'.format(os.uname()[3], os.uname()[4]))
import gc
gc.collect()
print('Initial available RAM: {} bytes'.format(gc.mem_free()))
import pyb
import math
import time
import lcd160cr
gc.collect()
print('RAM after importing some modules: {} bytes'.format(
    gc.mem_free()))  # 99120 bytes

try:
    flagLCD160CR = True
    lcd = lcd160cr.LCD160CR(
        'XY')  # display on the right side of Pyboard, default position
except OSError:
    print('LCD160CR display not found on the right side of Pyboard'
          )  # OSError: [Errno 19] ENODEV
    flagLCD160CR = False

if flagLCD160CR:
    print('LCD160CR display turned on')
    ti_us = time.ticks_us()
    import framebuf
    print('Time to import framebuf module: {:.3f} ms'.format(
        time.ticks_diff(time.ticks_us(), ti_us) * 1.0e-3))
    fbufh = lcd.h - 10
    fbuf = framebuf.FrameBuffer(bytearray(lcd.w * fbufh * 2), lcd.w, fbufh,
                                framebuf.RGB565)
    gc.collect()
Example #11
0
import os
import lcd160cr
import lcd160cr_test
import pyb
import time

import widgets
from colors import *
from utils import restore_framebuffer

try:
    lcd = lcd160cr.LCD160CR('XY')
except OSError:
    # I might have plugged in into the other side
    lcd = lcd160cr.LCD160CR('YX')
lcd.set_pen(WHITE, BLACK)
lcd.erase()

# ------ Create Button instances -------
PAD = 4
COLS = 2
ROWS = 4


def create_button(i, j, label=""):
    return widgets.Button(
        lcd,
        x1=int(i * (lcd.w / COLS) + PAD),
        y1=int(j * (lcd.h / ROWS) + PAD),
        x2=int((i + 1) * (lcd.w / COLS) - PAD),
        y2=int((j + 1) * (lcd.h / ROWS) - PAD),
Example #12
0
import pyb
import lcd160cr

lcd = lcd160cr.LCD160CR("X")
lcd.set_orient(lcd160cr.PORTRAIT)
lcd.erase()

accel = pyb.Accel()

lcd.set_text_color(1600, 0)
lcd.set_font(2)

red = lcd160cr.LCD160CR.rgb(255, 0, 0)
black = lcd160cr.LCD160CR.rgb(0, 0, 0)

x, y = int(lcd.w / 2), int(lcd.h / 2)

while True:
    dx, dy, dz = accel.filtered_xyz()

    dx = int(round(dx / 5, 0))
    dy = int(round(dy / 5, 0))

    x += dx
    y -= dy

    if x > lcd.w:
        x = lcd.w
    if x < 0:
        x = 0