def putpixelline(a, y): x = 0 for n in range(0, 1440, 3): pixel = a[n] << 16 | a[n + 1] << 8 | a[n + 2] lcd.pixels(0 + x, y, pixel) x = x + 1 def displayImage(image): file = open(image, 'rb') for n in range(272): a = file.read(1440) putpixelline(a, n) #callback = lambda e: TS_Interrupt(); #extint = ExtInt(Pin.board.LCD_INT,ExtInt.IRQ_FALLING,pyb.Pin.PULL_NONE,callback) lcd = LCD(0) lcd.clear(0xffff) #displayImage('python.data'); #drawText('Micropython',10,10,0x0000ff) #lcd.fillarea(420,0,480,60,0xff0000) #lcd.fillarea(420,60,480,120,0x00ff00) #lcd.fillarea(420,120,480,180,0x0000ff) #displayImage('calculator.data') #waitTouch();
# main.py -- put your code here! from pyb import LCD, SPI, I2C import math import os import sys import random import pyb SPI(5, SPI.MASTER, 6000000) lcd = LCD(0) lcd.line(0x1c, 1, 1, 1) led = pyb.LED(1) i2c = pyb.I2C(3, pyb.I2C.MASTER) t_pressed = 0 STMPE811_ADDRESS = 0x41 STMPE811_CHIP_ID_VALUE = 0x0811 #Chip ID STMPE811_CHIP_ID = 0x00 #STMPE811 Device identification STMPE811_ID_VER = 0x02 #STMPE811 Revision number; =0x01 for engineering sample; =0x03 for final silicon STMPE811_SYS_CTRL1 = 0x03 #Reset control STMPE811_SYS_CTRL2 = 0x04 #Clock control STMPE811_SPI_CFG = 0x08 #SPI interface configuration STMPE811_INT_CTRL = 0x09 #Interrupt control register STMPE811_INT_EN = 0x0A #Interrupt enable register STMPE811_INT_STA = 0x0B #Interrupt status register STMPE811_GPIO_EN = 0x0C #GPIO interrupt enable register STMPE811_GPIO_INT_STA = 0x0D #GPIO interrupt status register STMPE811_ADC_INT_EN = 0x0E #ADC interrupt enable register
t_pressed = 0 low = int(ord(i2c.mem_read(1, 0x38, regAddressXLow))) cord = (low & 0xff) high = int(ord(i2c.mem_read(1, 0x38, regAddressXHigh))) tempcord = (high & 0x0f) << 8 cord = cord | tempcord #print(cord) Y = cord low = int(ord(i2c.mem_read(1, 0x38, regAddressYLow))) cord = (low & 0xff) high = int(ord(i2c.mem_read(1, 0x38, regAddressYHigh))) tempcord = (high & 0x0f) << 8 cord = cord | tempcord #print(cord) X = cord #print(X,Y); lcd.pixels(X, Y, 0xffffff) def TS_Interrupt(): global t_pressed t_pressed = 1 callback = lambda e: TS_Interrupt() extint = ExtInt(Pin.board.LCD_INT, ExtInt.IRQ_FALLING, pyb.Pin.PULL_UP, callback) lcd = LCD(0)
if old_x == 0: old_x = X; if old_y == 0: old_y = Y; drawLine(old_x,old_y,X,Y,0xffffff); old_x = X; old_y = Y; else: old_x = 0; old_y = 0; def TS_Interrupt(): global t_pressed; t_pressed=1; callback = lambda e: TS_Interrupt() extint = ExtInt(Pin.board.LCD_INT,ExtInt.IRQ_RISING,pyb.Pin.PULL_UP,callback) lcd=LCD(0) lcd=LCD(0); lcd.clear(0); drawText("Sketch Pad",150,10,0x00ff00) #drawLine(10,10,70,70,0xffffff) waitTouch();
desired_moisture_level = float(f.read()[0:4]) except OSError: print('No file to open') except ValueError: print('Invalid moisture level data') finally: f.close() # State variables out_of_water = False pump_on = False debug = True # Set up pins adc = ADC(Pin.board.X8) # Moisuture sensor uses ADC to get value lcd = LCD('Y') water_monitor = Pin('X10', Pin.IN) pump = Pin('X12', Pin.OUT) left_button = Pin('X6', Pin.IN, Pin.PULL_UP) right_button = Pin('X1', Pin.IN, Pin.PULL_UP) lcd.light(True) # Interrupt callbacks def water_incrementer(p): global water_flow_counter water_flow_counter += 1 def button_pushed(button):
textColor = gfx.color565(0xff, 0xff, 0xff) #white #background processes (status bar and return button) async def killer(): pin = Pin('F11', Pin.IN, Pin.PULL_UP) #rightmost button beneath LCD while (pin.value()): bar.update(pairstat) await asyncio.sleep_ms(400) leds = [LED(i) for i in range(1, 4)] leftMotor = motors.Motor(1) rightMotor = motors.Motor(2) lcd = LCD() def fast_hline(x, y, width, color): lcd.fill(x, y, width, 1, color) def fast_vline(x, y, height, color): lcd.fill(x, y, 1, height, color) graphics = gfx.GFX(lcdWidth, lcdHeight, lcd.pixel, hline=fast_hline, vline=fast_vline)