From fddeec64b2940e7481581e9b25136975bcd8da0c Mon Sep 17 00:00:00 2001 From: Guy D Carver Date: Mon, 3 Nov 2014 18:02:34 -0500 Subject: [PATCH] Created All of my MicroPython stuff --- .gitignore | 215 +++++++++++++ Balance.py | 38 +++ Lib/ST7735.py | 725 ++++++++++++++++++++++++++++++++++++++++++ Lib/basicfont.py | 265 +++++++++++++++ Lib/seriffont.py | 99 ++++++ Lib/terminalfont.py | 100 ++++++ README.md | 5 + README.txt | 12 + SonarDisplay.py | 113 +++++++ TreatThrower.py | 41 +++ _SYNCAPP/metadata.xml | Bin 0 -> 16214 bytes bombs.py | 63 ++++ level.py | 70 ++++ main.py | 31 ++ 14 files changed, 1777 insertions(+) create mode 100644 .gitignore create mode 100644 Balance.py create mode 100644 Lib/ST7735.py create mode 100644 Lib/basicfont.py create mode 100644 Lib/seriffont.py create mode 100644 Lib/terminalfont.py create mode 100644 README.md create mode 100644 README.txt create mode 100644 SonarDisplay.py create mode 100644 TreatThrower.py create mode 100644 _SYNCAPP/metadata.xml create mode 100644 bombs.py create mode 100644 level.py create mode 100644 main.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b9d6bd9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,215 @@ +################# +## Eclipse +################# + +*.pydevproject +.project +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.classpath +.settings/ +.loadpath + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# PDT-specific +.buildpath + + +################# +## Visual Studio +################# + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results + +[Dd]ebug/ +[Rr]elease/ +x64/ +build/ +[Bb]in/ +[Oo]bj/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.log +*.scc + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +*.ncrunch* +.*crunch*.local.xml + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.Publish.xml +*.pubxml + +# NuGet Packages Directory +## TODO: If you have NuGet Package Restore enabled, uncomment the next line +#packages/ + +# Windows Azure Build Output +csx +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +sql/ +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.[Pp]ublish.xml +*.pfx +*.publishsettings + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +App_Data/*.mdf +App_Data/*.ldf + +############# +## Windows detritus +############# + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Mac crap +.DS_Store + + +############# +## Python +############# + +*.py[co] + +# Packages +*.egg +*.egg-info +dist/ +build/ +eggs/ +parts/ +var/ +sdist/ +develop-eggs/ +.installed.cfg + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +.coverage +.tox + +#Translations +*.mo + +#Mr Developer +.mr.developer.cfg diff --git a/Balance.py b/Balance.py new file mode 100644 index 0000000..c60a0d5 --- /dev/null +++ b/Balance.py @@ -0,0 +1,38 @@ +# Control bot that throws treats using a servo + +import pyb + +servoNums = [1, 2] +ledNum = 3 + +def pitchtoangle( aPitch ): + return aPitch * 90 / 32 + +def setservo( aServo, aPitch ): + aServo.angle(pitchtoangle(aPitch)) + +def main( ) : + a = pyb.Accel() + pitches = [ a.x, a.y ] + servos = [ pyb.Servo(sn) for sn in servoNums ] + curangles = [-100, -100] + +# mn, mx, _, a, s = s1.calibration() +# s1.calibration(mn, mx, servoCenter, a, s) +# s1.speed(0) + + l = pyb.LED(ledNum) + sw = pyb.Switch() + + while(1): + if sw(): + break; + for i in range(len(pitches)): + p = pitches[i]() + if curangles[i] != p: + curangles[i] = p + setservo(servos[i], p) + pyb.delay(20) + +if __name__ == '__main__': + main() diff --git a/Lib/ST7735.py b/Lib/ST7735.py new file mode 100644 index 0000000..157cff6 --- /dev/null +++ b/Lib/ST7735.py @@ -0,0 +1,725 @@ +#driver for Sainsmart 1.8" TFT display ST7735 +#Translated by Guy Carver from the ST7735 sample code. + +import pyb +from math import sqrt + +ST_NOP = 0x0 +ST_SWRESET = 0x01 +ST_RDDID = 0x04 +ST_RDDST = 0x09 + +ST_SLPIN = 0x10 +ST_SLPOUT = 0x11 +ST_PTLON = 0x12 +ST_NORON = 0x13 + +ST_INVOFF = 0x20 +ST_INVON = 0x21 +ST_DISPOFF = 0x28 +ST_DISPON = 0x29 +ST_CASET = 0x2A +ST_RASET = 0x2B +ST_RAMWR = 0x2C +ST_RAMRD = 0x2E + +ST_COLMOD = 0x3A +ST_MADCTL = 0x36 + +ST_FRMCTR1 = 0xB1 +ST_FRMCTR2 = 0xB2 +ST_FRMCTR3 = 0xB3 +ST_INVCTR = 0xB4 +ST_DISSET5 = 0xB6 + +ST_PWCTR1 = 0xC0 +ST_PWCTR2 = 0xC1 +ST_PWCTR3 = 0xC2 +ST_PWCTR4 = 0xC3 +ST_PWCTR5 = 0xC4 +ST_VMCTR1 = 0xC5 + +ST_RDID1 = 0xDA +ST_RDID2 = 0xDB +ST_RDID3 = 0xDC +ST_RDID4 = 0xDD + +ST_PWCTR6 = 0xFC + +ST_GMCTRP1 = 0xE0 +ST_GMCTRN1 = 0xE1 + +#TFTRotations and TFTRGB are bits to set +# on MADCTL to control display rotation/color layout +#Looking at display with pins on top. +#00 = upper left printing right +#10 = does nothing (MADCTL_ML) +#20 = upper left printing down (backwards) (Vertical flip) +#40 = upper right printing left (backwards) (X Flip) +#80 = lower left printing right (backwards) (Y Flip) +#04 = (MADCTL_MH) + +#60 = 90 right rotation +#C0 = 180 right rotation +#A0 = 270 right rotation +TFTRotations = [0x00, 0x60, 0xC0, 0xA0] +TFTBGR = 0x08 #When set color is bgr else rgb. +TFTRGB = 0x00 + +class Point(object): + """2D point class""" + + def __init__(self, x = 0, y = 0) : + self.x = x + self.y = y + + def __str__(self) : + return "ST7735.Point(" + str(self.x) + "," + str(self.y)+ ")" + + def __repr__(self) : + return self.__str__() + + def clone( self ) : + return Point(self.x, self.y) + +def clamp( aValue, aMin, aMax ) : + return max(aMin, min(aMax, aValue)) + +def TFTColor( aR, aG, aB ) : + '''Create a 16 bit rgb value from the given R,G,B from 0-255. + This assumes rgb 565 layout and will be incorrect for bgr.''' + return ((aR & 0xF8) << 8) | ((aG & 0xFC) << 3) | (aB >> 3) + +BLACK = 0 +RED = TFTColor(0xFF, 0x00, 0x00) +MAROON = TFTColor(0x80, 0x00, 0x00) +GREEN = TFTColor(0x00, 0xFF, 0x00) +BLUE = TFTColor(0x00, 0x00, 0xFF) +NAVY = TFTColor(0x00, 0x00, 0x80) +CYAN = TFTColor(0x00, 0xFF, 0xFF) +YELLOW = TFTColor(0xFF, 0xFF, 0x00) +PURPLE = TFTColor(0xFF, 0x00, 0xFF) +WHITE = TFTColor(0xFF, 0xFF, 0xFF) +GRAY = TFTColor(0x80, 0x80, 0x80) + +ScreenSize = Point(128, 160) + +class TFT(object) : + """Sainsmart TFT 7735 display driver.""" + + @staticmethod + def makecolor(aR, aG, aB): + '''Create a 565 rgb TFTColor value''' + return TFTColor(aR, aG, aB) + + def __init__(self, aLoc, aDC, aReset) : + """aLoc SPI pin location is either 1 for 'X' or 2 for 'Y'. + aDC is the DC pin and aReset is the reset pin.""" + self.size = ScreenSize.clone() + self.rotate = 0 #Vertical with top toward pins. + self.rgb = TFTRGB #color order of rgb. + self.dc = pyb.Pin(aDC, pyb.Pin.OUT_PP, pyb.Pin.PULL_DOWN) + self.reset = pyb.Pin(aReset, pyb.Pin.OUT_PP, pyb.Pin.PULL_DOWN) + rate = 100000000 #Set way high but will be clamped to a maximum in SPI constructor. + cs = "X5" if aLoc == 1 else "Y5" + self.cs = pyb.Pin(cs, pyb.Pin.OUT_PP, pyb.Pin.PULL_DOWN) + self.cs.high() + self.spi = pyb.SPI(aLoc, pyb.SPI.MASTER, baudrate = rate, polarity = 0, phase = 1, crc=None) + self.colorData = bytearray(2) + self.windowLocData = bytearray(4) + + def on( self, aTF = True ) : + '''Turn display on or off.''' + self._writecommand(ST_DISPON if aTF else ST_DISPOFF) + + def invertcolor( self, aBool ) : + '''Invert the color data IE: Black = White.''' + self._writecommand(ST_INVON if aBool else ST_INVOFF) + + def setrgb( self, aTF = True ) : + '''True = rgb else bgr''' + self.rgb = TFTRBG if aTF else TFTBGR + self._setMADCTL() + + def setrotation( self, aRot ) : + '''0 - 3. Starts vertical with top toward pins and rotates 90 deg + clockwise each step.''' + if (0 <= aRot < 4): + rotchange = self.rotate ^ aRot + self.rotate = aRot + #If switching from vertical to horizontal swap x,y + # (indicated by bit 0 changing). + if (rotchange & 1): + self.size.x, self.size.y = self.size.y, self.size.x + self._setMADCTL() + + def drawpixel( self, aPos, aColor ) : + '''Draw a pixel at the given position''' + if 0 <= aPos.x < self.size.x and 0 <= aPos.y < self.size.y: + self._setwindowpoint(aPos) + self._pushcolor(aColor) + + def drawstring( self, aPos, aString, aColor, aFont, aSize = 1 ) : + '''Draw a string at the given position. If the string reaches the end of the + display it is wrapped to aPos.x on the next line. aSize may be an integer + which will size the font uniformly on w,h or a Point with x,y scales or + any type that may be indexed with [0] or [1].''' + + #Make a size either from single value or 2 elements. + if (type(aSize) == int) or (type(aSize) == float): + wh = Point(aSize, aSize) + elif (type(aSize) == Point): + wh = aSize + else: + wh = Point(aSize[0], aSize[1]) + + pos = aPos.clone() + width = wh.x * aFont["Width"] + 1 + for c in aString: + self.drawchar(pos, c, aColor, aFont, wh) + pos.x += width + #We check > rather than >= to let the right (blank) edge of the + # character print off the right of the screen. + if pos.x + width > self.size.x: + pos.y += aFont["Height"] * wh.y + 1 + pos.x = aPos.x + + def drawchar( self, aPos, aChar, aColor, aFont, aSizes ) : + '''Draw a character at the given position using the given font and color. + aSizes is a Point with x, y as integer scales indicating the + # of pixels to draw for each pixel in the character.''' + + if aFont == None: + return + + startchar = aFont['Start'] + endchar = aFont['End'] + + ci = ord(aChar) + if (startchar <= ci <= endchar): + fontw = aFont['Width'] + fonth = aFont['Height'] + ci = (ci - startchar) * fontw + + charA = aFont["Data"][ci:ci + fontw] + pos = aPos.clone() + if aSizes.x <= 1 and aSizes.y <= 1 : + for c in charA : + pos.y = aPos.y + for r in range(fonth) : + if c & 0x01 : + self.drawpixel(pos, aColor) + pos.y += 1 + c >>= 1 + pos.x += 1 + else: + for c in charA : + pos.y = aPos.y + for r in range(fonth) : + if c & 0x01 : + self.fillrect(pos, aSizes, aColor) + pos.y += aSizes.y + c >>= 1 + pos.x += aSizes.x + + def drawline( self, aStart, aEnd, aColor ) : + '''Draws a line from aStart to aEnd in the given color. Vertical or horizontal + lines are forwarded to vline and hline.''' + if aStart.x == aEnd.x: + #Make sure we use the smallest y. + pnt = aEnd if (aEnd.y < aStart.y) else aStart + self.vline(pnt, abs(aEnd.y - aStart.y) + 1, aColor) + elif aStart.y == aEnd.y: + #Make sure we use the smallest x. + pnt = aEnd if aEnd.x < aStart.x else aStart + self.hline(pnt, abs(aEnd.x - aStart.x) + 1, aColor) + else: + slope = float(aEnd.y - aStart.y) / (aEnd.x - aStart.x) + if (abs(slope) < 1.0): + for x in range(aStart.x, aEnd.x + 1) : + y = (x - aStart.x) * slope + aStart.y + self.drawpixel(Point(x, int(y + 0.5)), aColor) + else: + for y in range(aStart.y, aEnd.y + 1) : + x = (y - aStart.y) / slope + aStart.x + self.drawpixel(Point(int(x + 0.5), y), aColor) + + def vline( self, aStart, aLen, aColor ) : + '''Draw a vertical line from aStart for aLen. aLen may be negative.''' + start = Point(clamp(aStart.x, 0, self.size.x), clamp(aStart.y, 0, self.size.y)) + stop = Point(start.x, clamp(start.y + aLen, 0, self.size.y)) + #Make sure smallest y 1st. + if (stop.y < start.y): + start, stop = stop, start + self._setwindowloc(start, stop) + self._draw(aLen, aColor) + + def hline( self, aStart, aLen, aColor ) : + '''Draw a horizontal line from aStart for aLen. aLen may be negative.''' + start = Point(clamp(aStart.x, 0, self.size.x), clamp(aStart.y, 0, self.size.y)) + stop = Point(clamp(start.x + aLen, 0, self.size.x), start.y) + #Make sure smallest x 1st. + if (stop.x < start.x): + start, stop = stop, start + self._setwindowloc(start, stop) + self._draw(aLen, aColor) + + def rect( self, aStart, aSize, aColor ) : + '''Draw a hollow rectangle. aStart is the smallest coordinate corner + and aSize is a Point indicating width, height.''' + self.hline(aStart, aSize.x, aColor) + self.hline(Point(aStart.x, aStart.y + aSize.y - 1), aSize.x, aColor) + self.vline(aStart, aSize.y, aColor) + self.vline(Point(aStart.x + aSize.x - 1, aStart.y), aSize.y, aColor) + + def fillrect( self, aStart, aSize, aColor ) : + '''Draw a filled rectangle. aStart is the smallest coordinate corner + and aSize is a Point indicating width, height.''' + start = Point(clamp(aStart.x, 0, self.size.x), clamp(aStart.y, 0, self.size.y)) + end = Point(clamp(start.x + aSize.x - 1, 0, self.size.x), clamp(start.y + aSize.y - 1, 0, self.size.y)) + + if (end.x < start.x): + end.x, start.x = start.x, end.x + if (end.y < start.y): + end.y, start.y = start.y, end.y + + self._setwindowloc(start, end) + numPixels = (end.x - start.x + 1) * (end.y - start.y + 1) + self._draw(numPixels, aColor) + + def circle( self, aPos, aRadius, aColor ) : + '''Draw a hollow circle with the given radius and color with aPos as center.''' + self.colorData[0] = aColor >> 8 + self.colorData[1] = aColor + xend = int(0.7071 * aRadius) + 1 + rsq = aRadius * aRadius + for x in range(xend) : + y = int(sqrt(rsq - x * x)) + xp = aPos.x + x + yp = aPos.y + y + xn = aPos.x - x + yn = aPos.y - y + xyp = aPos.x + y + yxp = aPos.y + x + xyn = aPos.x - y + yxn = aPos.y - x + + self._setwindowpoint(Point(xp, yp)) + self._writedata(self.colorData) + self._setwindowpoint(Point(xp, yn)) + self._writedata(self.colorData) + self._setwindowpoint(Point(xn, yp)) + self._writedata(self.colorData) + self._setwindowpoint(Point(xn, yn)) + self._writedata(self.colorData) + self._setwindowpoint(Point(xp, yn)) + self._writedata(self.colorData) + self._setwindowpoint(Point(xyp, yxp)) + self._writedata(self.colorData) + self._setwindowpoint(Point(xyp, yxn)) + self._writedata(self.colorData) + self._setwindowpoint(Point(xyn, yxp)) + self._writedata(self.colorData) + self._setwindowpoint(Point(xyn, yxn)) + self._writedata(self.colorData) + + def fillcircle( self, aPos, aRadius, aColor ) : + '''Draw a filled circle with given radius and color with aPos as center''' + rsq = aRadius * aRadius + for x in range(aRadius) : + y = int(sqrt(rsq - x * x)) + y0 = aPos.y - y + ln = y * 2 + self.vline(Point(aPos.x + x, y0), ln, aColor) + self.vline(Point(aPos.x - x, y0), ln, aColor) + + def fill( self, aColor ) : + '''Fill screen with the given color.''' + self.fillrect(Point(0, 0), self.size, aColor) + self._draw(self.size.x * self.size.y, aColor) + + def _draw( self, aPixels, aColor ) : + '''Send given color to the device aPixels times.''' + self.colorData[0] = aColor >> 8 + self.colorData[1] = aColor + + self.dc.high() + self.cs.low() + for i in range(aPixels): + self.spi.send(self.colorData) + self.cs.high() + + def _setwindowpoint( self, aPos ) : + '''Set a single point for drawing a color to.''' + x = int(aPos.x) + y = int(aPos.y) + self._writecommand(ST_CASET) #Column address set. + self.windowLocData[0] = 0x00 + self.windowLocData[1] = x + self.windowLocData[2] = 0x00 + self.windowLocData[3] = x + self._writedata(self.windowLocData) + + self._writecommand(ST_RASET) #Row address set. + self.windowLocData[1] = y + self.windowLocData[3] = y + self._writedata(self.windowLocData) + self._writecommand(ST_RAMWR) #Write to RAM. + + def _setwindowloc( self, aPos0, aPos1 ) : + '''Set a rectangular area for drawing a color to.''' + self._writecommand(ST_CASET) #Column address set. + self.windowLocData[0] = 0x00 + self.windowLocData[1] = int(aPos0.x) + self.windowLocData[2] = 0x00 + self.windowLocData[3] = int(aPos1.x) + self._writedata(self.windowLocData) + + self._writecommand(ST_RASET) #Row address set. + self.windowLocData[1] = int(aPos0.y) + self.windowLocData[3] = int(aPos1.y) + self._writedata(self.windowLocData) + + self._writecommand(ST_RAMWR) #Write to RAM. + + def _writecommand( self, aCommand ) : + '''Write given command to the device.''' + self.dc.low() + self.cs.low() + self.spi.send(aCommand) + self.cs.high() + + def _writedata( self, aData ) : + '''Write given data to the device. This may be + either a single int or a bytearray of values.''' + self.dc.high() + self.cs.low() + self.spi.send(aData) + self.cs.high() + + def _pushcolor( self, aColor ) : + '''Push given color to the device.''' + self.colorData[0] = aColor >> 8 + self.colorData[1] = aColor + self._writedata(self.colorData) + + def _setMADCTL( self ) : + '''Set screen rotation and RGB/BGR format.''' + self._writecommand(ST_MADCTL) + self._writedata(TFTRotations[self.rotate] | self.rgb) + + def _reset(self): + '''Reset the device.''' + self.dc.low() + self.reset.high() + pyb.delay(500) + self.reset.low() + pyb.delay(500) + self.reset.high() + pyb.delay(500) + + def _initb(self): + '''Initialize blue tab version.''' + self.size.x = ScreenSize.x + 2 + self.size.y = ScreenSize.y + 1 + self._reset() + self._writecommand(ST_SWRESET) #Software reset. + pyb.delay(50) + self._writecommand(ST_SLPOUT) #out of sleep mode. + pyb.delay(500) + + data1 = bytearray(1) + self._writecommand(ST_COLMOD) #Set color mode. + data1[0] = 0x05 #16 bit color. + self._writedata(data1) + pyb.delay(10) + + data3 = bytearray([0x00, 0x06, 0x03]) #fastest refresh, 6 lines front, 3 lines back. + self._writecommand(ST_FRMCTR1) #Frame rate control. + self._writedata(data3) + pyb.delay(10) + + self._writecommand(ST_MADCTL) + data1[0] = 0x08 #row address/col address, bottom to top refresh + self._writedata(data1) + + data2 = bytearray(2) + self._writecommand(ST_DISSET5) #Display settings + data2[0] = 0x15 #1 clock cycle nonoverlap, 2 cycle gate rise, 3 cycle oscil, equalize + data2[1] = 0x02 #fix on VTL + self._writedata(data2) + + self._writecommand(ST_INVCTR) #Display inversion control + data1[0] = 0x00 #Line inversion. + self._writedata(data1) + + self._writecommand(ST_PWCTR1) #Power control + data2[0] = 0x02 #GVDD = 4.7V + data2[1] = 0x70 #1.0uA + self._writedata(data2) + pyb.delay(10) + + self._writecommand(ST_PWCTR2) #Power control + data1[0] = 0x05 #VGH = 14.7V, VGL = -7.35V + self._writedata(data1) + +#Took this out because with it the screen stays all white. +#But I tested on green tab version so maybe it will work for blue. +# self._writecommand(ST_PWCTR3) #Power control +# data2[0] = 0x01 #Opamp current small +# data2[1] = 0x02 #Boost frequency +# self._writedata(data2) + + self._writecommand(ST_VMCTR1) #Power control + data2[0] = 0x3C #VCOMH = 4V + data2[1] = 0x38 #VCOML = -1.1V + self._writedata(data2) + pyb.delay(10) + + self._writecommand(ST_PWCTR6) #Power control + data2[0] = 0x11 + data2[1] = 0x15 + self._writedata(data2) + + #These different values don't seem to make a difference. +# dataGMCTRP = bytearray([0x0f, 0x1a, 0x0f, 0x18, 0x2f, 0x28, 0x20, 0x22, 0x1f, +# 0x1b, 0x23, 0x37, 0x00, 0x07, 0x02, 0x10]) + dataGMCTRP = bytearray([0x02, 0x1c, 0x07, 0x12, 0x37, 0x32, 0x29, 0x2d, 0x29, + 0x25, 0x2b, 0x39, 0x00, 0x01, 0x03, 0x10]) + self._writecommand(ST_GMCTRP1) + self._writedata(dataGMCTRP) + +# dataGMCTRN = bytearray([0x0f, 0x1b, 0x0f, 0x17, 0x33, 0x2c, 0x29, 0x2e, 0x30, +# 0x30, 0x39, 0x3f, 0x00, 0x07, 0x03, 0x10]) + dataGMCTRN = bytearray([0x03, 0x1d, 0x07, 0x06, 0x2e, 0x2c, 0x29, 0x2d, 0x2e, + 0x2e, 0x37, 0x3f, 0x00, 0x00, 0x02, 0x10]) + self._writecommand(ST_GMCTRN1) + self._writedata(dataGMCTRN) + pyb.delay(10) + + self._writecommand(ST_CASET) #Column address set. + self.windowLocData[0] = 0x00 + self.windowLocData[1] = 2 #Start at column 2 + self.windowLocData[2] = 0x00 + self.windowLocData[3] = self.size.x - 1 + self._writedata(self.windowLocData) + + self._writecommand(ST_RASET) #Row address set. + self.windowLocData[1] = 1 #Start at row 2. + self.windowLocData[3] = self.size.y - 1 + self._writedata(self.windowLocData) + + self._writecommand(ST_NORON) #Normal display on. + pyb.delay(10) + + self._writecommand(ST_RAMWR) + pyb.delay(500) + + self._writecommand(ST_DISPON) + self.cs.high() + pyb.delay(500) + + def _initr(self): + '''Initialize a red tab version.''' + self._reset() + + self._writecommand(ST_SWRESET) #Software reset. + pyb.delay(150) + self._writecommand(ST_SLPOUT) #out of sleep mode. + pyb.delay(500) + + data3 = bytearray([0x01, 0x2C, 0x2D]) #fastest refresh, 6 lines front, 3 lines back. + self._writecommand(ST_FRMCTR1) #Frame rate control. + self._writedata(data3) + + self._writecommand(ST_FRMCTR2) #Frame rate control. + self._writedata(data3) + + data6 = bytearray([0x01, 0x2c, 0x2d, 0x01, 0x2c, 0x2d]) + self._writecommand(ST_FRMCTR3) #Frame rate control. + self._writedata(data6) + pyb.delay(10) + + data1 = bytearray(1) + self._writecommand(ST_INVCTR) #Display inversion control + data1[0] = 0x07 #Line inversion. + self._writedata(data1) + + self._writecommand(ST_PWCTR1) #Power control + data3[0] = 0xA2 + data3[1] = 0x02 + data3[2] = 0x84 + self._writedata(data3) + + self._writecommand(ST_PWCTR2) #Power control + data1[0] = 0xC5 #VGH = 14.7V, VGL = -7.35V + self._writedata(data1) + + data2 = bytearray(2) + self._writecommand(ST_PWCTR3) #Power control + data2[0] = 0x0A #Opamp current small + data2[1] = 0x00 #Boost frequency + self._writedata(data2) + + self._writecommand(ST_PWCTR4) #Power control + data2[0] = 0x8A #Opamp current small + data2[1] = 0x2A #Boost frequency + self._writedata(data2) + + self._writecommand(ST_PWCTR5) #Power control + data2[0] = 0x8A #Opamp current small + data2[1] = 0xEE #Boost frequency + self._writedata(data2) + + self._writecommand(ST_VMCTR1) #Power control + data1[0] = 0x0E + self._writedata(data1) + + self._writecommand(ST_INVOFF) + + self._writecommand(ST_MADCTL) #Power control + data1[0] = 0xC8 + self._writedata(data1) + + self._writecommand(ST_COLMOD) + data1[0] = 0x05 + self._writedata(data1) + + self._writecommand(ST_CASET) #Column address set. + self.windowLocData[0] = 0x00 + self.windowLocData[1] = 0x00 + self.windowLocData[2] = 0x00 + self.windowLocData[3] = self.size.x - 1 + self._writedata(self.windowLocData) + + self._writecommand(ST_RASET) #Row address set. + self.windowLocData[3] = self.size.y - 1 + self._writedata(self.windowLocData) + + dataGMCTRP = bytearray([0x0f, 0x1a, 0x0f, 0x18, 0x2f, 0x28, 0x20, 0x22, 0x1f, + 0x1b, 0x23, 0x37, 0x00, 0x07, 0x02, 0x10]) + self._writecommand(ST_GMCTRP1) + self._writedata(dataGMCTRP) + + dataGMCTRN = bytearray([0x0f, 0x1b, 0x0f, 0x17, 0x33, 0x2c, 0x29, 0x2e, 0x30, + 0x30, 0x39, 0x3f, 0x00, 0x07, 0x03, 0x10]) + self._writecommand(ST_GMCTRN1) + self._writedata(dataGMCTRN) + pyb.delay(10) + + self._writecommand(ST_DISPON) + pyb.delay(100) + + self._writecommand(ST_NORON) #Normal display on. + pyb.delay(10) + + self.cs.high() + + def _initg(self): + '''Initialize a green tab version.''' + self._reset() + + self._writecommand(ST_SWRESET) #Software reset. + pyb.delay(150) + self._writecommand(ST_SLPOUT) #out of sleep mode. + pyb.delay(255) + + data3 = bytearray([0x01, 0x2C, 0x2D]) #fastest refresh, 6 lines front, 3 lines back. + self._writecommand(ST_FRMCTR1) #Frame rate control. + self._writedata(data3) + + self._writecommand(ST_FRMCTR2) #Frame rate control. + self._writedata(data3) + + data6 = bytearray([0x01, 0x2c, 0x2d, 0x01, 0x2c, 0x2d]) + self._writecommand(ST_FRMCTR3) #Frame rate control. + self._writedata(data6) + pyb.delay(10) + + self._writecommand(ST_INVCTR) #Display inversion control + self._writedata(0x07) + + self._writecommand(ST_PWCTR1) #Power control + data3[0] = 0xA2 + data3[1] = 0x02 + data3[2] = 0x84 + self._writedata(data3) + + self._writecommand(ST_PWCTR2) #Power control + self._writedata(0xC5) + + data2 = bytearray(2) + self._writecommand(ST_PWCTR3) #Power control + data2[0] = 0x0A #Opamp current small + data2[1] = 0x00 #Boost frequency + self._writedata(data2) + + self._writecommand(ST_PWCTR4) #Power control + data2[0] = 0x8A #Opamp current small + data2[1] = 0x2A #Boost frequency + self._writedata(data2) + + self._writecommand(ST_PWCTR5) #Power control + data2[0] = 0x8A #Opamp current small + data2[1] = 0xEE #Boost frequency + self._writedata(data2) + + self._writecommand(ST_VMCTR1) #Power control + self._writedata(0x0E) + + self._writecommand(ST_INVOFF) + + self._setMADCTL() + + self._writecommand(ST_COLMOD) + self._writedata(0x05) + + self._writecommand(ST_CASET) #Column address set. + self.windowLocData[0] = 0x00 + self.windowLocData[1] = 0x01 #Start at row/column 1. + self.windowLocData[2] = 0x00 + self.windowLocData[3] = self.size.x - 1 + self._writedata(self.windowLocData) + + self._writecommand(ST_RASET) #Row address set. + self.windowLocData[3] = self.size.y - 1 + self._writedata(self.windowLocData) + + dataGMCTRP = bytearray([0x02, 0x1c, 0x07, 0x12, 0x37, 0x32, 0x29, 0x2d, 0x29, + 0x25, 0x2b, 0x39, 0x00, 0x01, 0x03, 0x10]) + self._writecommand(ST_GMCTRP1) + self._writedata(dataGMCTRP) + + dataGMCTRN = bytearray([0x03, 0x1d, 0x07, 0x06, 0x2e, 0x2c, 0x29, 0x2d, 0x2e, + 0x2e, 0x37, 0x3f, 0x00, 0x00, 0x02, 0x10]) + self._writecommand(ST_GMCTRN1) + self._writedata(dataGMCTRN) + + self._writecommand(ST_NORON) #Normal display on. + pyb.delay(10) + + self._writecommand(ST_DISPON) + pyb.delay(100) + + self.cs.high() + +def maker(): + t = TFT(1, "X1", "X2") + print("Initializing") + t._initr() + t.fill(0) + return t + +def makeb( ): + t = TFT(1, "X1", "X2") + print("Initializing") + t._initb() + t.fill(0) + return t + +def makeg( ): + t = TFT(1, "X1", "X2") + print("Initializing") + t._initg() + t.fill(0) + return t diff --git a/Lib/basicfont.py b/Lib/basicfont.py new file mode 100644 index 0000000..8dc3425 --- /dev/null +++ b/Lib/basicfont.py @@ -0,0 +1,265 @@ +#Font used for ST7735 display. + +#Each character uses 5 bytes. +#index using ASCII value * 5. +#Each byte contains a column of pixels. +#The character may be 8 pixels high and 5 wide. + +basicfont = {"Width": 5, "Height": 8, "Start": 0, "End": 255, "Data": bytearray([ + 0x00, 0x00, 0x00, 0x00, 0x00, + 0x3E, 0x5B, 0x4F, 0x5B, 0x3E, + 0x3E, 0x6B, 0x4F, 0x6B, 0x3E, + 0x1C, 0x3E, 0x7C, 0x3E, 0x1C, + 0x18, 0x3C, 0x7E, 0x3C, 0x18, + 0x1C, 0x57, 0x7D, 0x57, 0x1C, + 0x1C, 0x5E, 0x7F, 0x5E, 0x1C, + 0x00, 0x18, 0x3C, 0x18, 0x00, + 0xFF, 0xE7, 0xC3, 0xE7, 0xFF, + 0x00, 0x18, 0x24, 0x18, 0x00, + 0xFF, 0xE7, 0xDB, 0xE7, 0xFF, + 0x30, 0x48, 0x3A, 0x06, 0x0E, + 0x26, 0x29, 0x79, 0x29, 0x26, + 0x40, 0x7F, 0x05, 0x05, 0x07, + 0x40, 0x7F, 0x05, 0x25, 0x3F, + 0x5A, 0x3C, 0xE7, 0x3C, 0x5A, + 0x7F, 0x3E, 0x1C, 0x1C, 0x08, + 0x08, 0x1C, 0x1C, 0x3E, 0x7F, + 0x14, 0x22, 0x7F, 0x22, 0x14, + 0x5F, 0x5F, 0x00, 0x5F, 0x5F, + 0x06, 0x09, 0x7F, 0x01, 0x7F, + 0x00, 0x66, 0x89, 0x95, 0x6A, + 0x60, 0x60, 0x60, 0x60, 0x60, + 0x94, 0xA2, 0xFF, 0xA2, 0x94, + 0x08, 0x04, 0x7E, 0x04, 0x08, + 0x10, 0x20, 0x7E, 0x20, 0x10, + 0x08, 0x08, 0x2A, 0x1C, 0x08, + 0x08, 0x1C, 0x2A, 0x08, 0x08, + 0x1E, 0x10, 0x10, 0x10, 0x10, + 0x0C, 0x1E, 0x0C, 0x1E, 0x0C, + 0x30, 0x38, 0x3E, 0x38, 0x30, + 0x06, 0x0E, 0x3E, 0x0E, 0x06, + 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x5F, 0x00, 0x00, + 0x00, 0x07, 0x00, 0x07, 0x00, + 0x14, 0x7F, 0x14, 0x7F, 0x14, + 0x24, 0x2A, 0x7F, 0x2A, 0x12, + 0x23, 0x13, 0x08, 0x64, 0x62, + 0x36, 0x49, 0x56, 0x20, 0x50, + 0x00, 0x08, 0x07, 0x03, 0x00, + 0x00, 0x1C, 0x22, 0x41, 0x00, + 0x00, 0x41, 0x22, 0x1C, 0x00, + 0x2A, 0x1C, 0x7F, 0x1C, 0x2A, + 0x08, 0x08, 0x3E, 0x08, 0x08, + 0x00, 0x80, 0x70, 0x30, 0x00, + 0x08, 0x08, 0x08, 0x08, 0x08, + 0x00, 0x00, 0x60, 0x60, 0x00, + 0x20, 0x10, 0x08, 0x04, 0x02, + 0x3E, 0x51, 0x49, 0x45, 0x3E, + 0x00, 0x42, 0x7F, 0x40, 0x00, + 0x72, 0x49, 0x49, 0x49, 0x46, + 0x21, 0x41, 0x49, 0x4D, 0x33, + 0x18, 0x14, 0x12, 0x7F, 0x10, + 0x27, 0x45, 0x45, 0x45, 0x39, + 0x3C, 0x4A, 0x49, 0x49, 0x31, + 0x41, 0x21, 0x11, 0x09, 0x07, + 0x36, 0x49, 0x49, 0x49, 0x36, + 0x46, 0x49, 0x49, 0x29, 0x1E, + 0x00, 0x00, 0x14, 0x00, 0x00, + 0x00, 0x40, 0x34, 0x00, 0x00, + 0x00, 0x08, 0x14, 0x22, 0x41, + 0x14, 0x14, 0x14, 0x14, 0x14, + 0x00, 0x41, 0x22, 0x14, 0x08, + 0x02, 0x01, 0x59, 0x09, 0x06, + 0x3E, 0x41, 0x5D, 0x59, 0x4E, + 0x7C, 0x12, 0x11, 0x12, 0x7C, + 0x7F, 0x49, 0x49, 0x49, 0x36, + 0x3E, 0x41, 0x41, 0x41, 0x22, + 0x7F, 0x41, 0x41, 0x41, 0x3E, + 0x7F, 0x49, 0x49, 0x49, 0x41, + 0x7F, 0x09, 0x09, 0x09, 0x01, + 0x3E, 0x41, 0x41, 0x51, 0x73, + 0x7F, 0x08, 0x08, 0x08, 0x7F, + 0x00, 0x41, 0x7F, 0x41, 0x00, + 0x20, 0x40, 0x41, 0x3F, 0x01, + 0x7F, 0x08, 0x14, 0x22, 0x41, + 0x7F, 0x40, 0x40, 0x40, 0x40, + 0x7F, 0x02, 0x1C, 0x02, 0x7F, + 0x7F, 0x04, 0x08, 0x10, 0x7F, + 0x3E, 0x41, 0x41, 0x41, 0x3E, + 0x7F, 0x09, 0x09, 0x09, 0x06, + 0x3E, 0x41, 0x51, 0x21, 0x5E, + 0x7F, 0x09, 0x19, 0x29, 0x46, + 0x26, 0x49, 0x49, 0x49, 0x32, + 0x03, 0x01, 0x7F, 0x01, 0x03, + 0x3F, 0x40, 0x40, 0x40, 0x3F, + 0x1F, 0x20, 0x40, 0x20, 0x1F, + 0x3F, 0x40, 0x38, 0x40, 0x3F, + 0x63, 0x14, 0x08, 0x14, 0x63, + 0x03, 0x04, 0x78, 0x04, 0x03, + 0x61, 0x59, 0x49, 0x4D, 0x43, + 0x00, 0x7F, 0x41, 0x41, 0x41, + 0x02, 0x04, 0x08, 0x10, 0x20, + 0x00, 0x41, 0x41, 0x41, 0x7F, + 0x04, 0x02, 0x01, 0x02, 0x04, + 0x40, 0x40, 0x40, 0x40, 0x40, + 0x00, 0x03, 0x07, 0x08, 0x00, + 0x20, 0x54, 0x54, 0x78, 0x40, + 0x7F, 0x28, 0x44, 0x44, 0x38, + 0x38, 0x44, 0x44, 0x44, 0x28, + 0x38, 0x44, 0x44, 0x28, 0x7F, + 0x38, 0x54, 0x54, 0x54, 0x18, + 0x00, 0x08, 0x7E, 0x09, 0x02, + 0x18, 0xA4, 0xA4, 0x9C, 0x78, + 0x7F, 0x08, 0x04, 0x04, 0x78, + 0x00, 0x44, 0x7D, 0x40, 0x00, + 0x20, 0x40, 0x40, 0x3D, 0x00, + 0x7F, 0x10, 0x28, 0x44, 0x00, + 0x00, 0x41, 0x7F, 0x40, 0x00, + 0x7C, 0x04, 0x78, 0x04, 0x78, + 0x7C, 0x08, 0x04, 0x04, 0x78, + 0x38, 0x44, 0x44, 0x44, 0x38, + 0xFC, 0x18, 0x24, 0x24, 0x18, + 0x18, 0x24, 0x24, 0x18, 0xFC, + 0x7C, 0x08, 0x04, 0x04, 0x08, + 0x48, 0x54, 0x54, 0x54, 0x24, + 0x04, 0x04, 0x3F, 0x44, 0x24, + 0x3C, 0x40, 0x40, 0x20, 0x7C, + 0x1C, 0x20, 0x40, 0x20, 0x1C, + 0x3C, 0x40, 0x30, 0x40, 0x3C, + 0x44, 0x28, 0x10, 0x28, 0x44, + 0x4C, 0x90, 0x90, 0x90, 0x7C, + 0x44, 0x64, 0x54, 0x4C, 0x44, + 0x00, 0x08, 0x36, 0x41, 0x00, + 0x00, 0x00, 0x77, 0x00, 0x00, + 0x00, 0x41, 0x36, 0x08, 0x00, + 0x02, 0x01, 0x02, 0x04, 0x02, + 0x3C, 0x26, 0x23, 0x26, 0x3C, + 0x1E, 0xA1, 0xA1, 0x61, 0x12, + 0x3A, 0x40, 0x40, 0x20, 0x7A, + 0x38, 0x54, 0x54, 0x55, 0x59, + 0x21, 0x55, 0x55, 0x79, 0x41, + 0x21, 0x54, 0x54, 0x78, 0x41, + 0x21, 0x55, 0x54, 0x78, 0x40, + 0x20, 0x54, 0x55, 0x79, 0x40, + 0x0C, 0x1E, 0x52, 0x72, 0x12, + 0x39, 0x55, 0x55, 0x55, 0x59, + 0x39, 0x54, 0x54, 0x54, 0x59, + 0x39, 0x55, 0x54, 0x54, 0x58, + 0x00, 0x00, 0x45, 0x7C, 0x41, + 0x00, 0x02, 0x45, 0x7D, 0x42, + 0x00, 0x01, 0x45, 0x7C, 0x40, + 0xF0, 0x29, 0x24, 0x29, 0xF0, + 0xF0, 0x28, 0x25, 0x28, 0xF0, + 0x7C, 0x54, 0x55, 0x45, 0x00, + 0x20, 0x54, 0x54, 0x7C, 0x54, + 0x7C, 0x0A, 0x09, 0x7F, 0x49, + 0x32, 0x49, 0x49, 0x49, 0x32, + 0x32, 0x48, 0x48, 0x48, 0x32, + 0x32, 0x4A, 0x48, 0x48, 0x30, + 0x3A, 0x41, 0x41, 0x21, 0x7A, + 0x3A, 0x42, 0x40, 0x20, 0x78, + 0x00, 0x9D, 0xA0, 0xA0, 0x7D, + 0x39, 0x44, 0x44, 0x44, 0x39, + 0x3D, 0x40, 0x40, 0x40, 0x3D, + 0x3C, 0x24, 0xFF, 0x24, 0x24, + 0x48, 0x7E, 0x49, 0x43, 0x66, + 0x2B, 0x2F, 0xFC, 0x2F, 0x2B, + 0xFF, 0x09, 0x29, 0xF6, 0x20, + 0xC0, 0x88, 0x7E, 0x09, 0x03, + 0x20, 0x54, 0x54, 0x79, 0x41, + 0x00, 0x00, 0x44, 0x7D, 0x41, + 0x30, 0x48, 0x48, 0x4A, 0x32, + 0x38, 0x40, 0x40, 0x22, 0x7A, + 0x00, 0x7A, 0x0A, 0x0A, 0x72, + 0x7D, 0x0D, 0x19, 0x31, 0x7D, + 0x26, 0x29, 0x29, 0x2F, 0x28, + 0x26, 0x29, 0x29, 0x29, 0x26, + 0x30, 0x48, 0x4D, 0x40, 0x20, + 0x38, 0x08, 0x08, 0x08, 0x08, + 0x08, 0x08, 0x08, 0x08, 0x38, + 0x2F, 0x10, 0xC8, 0xAC, 0xBA, + 0x2F, 0x10, 0x28, 0x34, 0xFA, + 0x00, 0x00, 0x7B, 0x00, 0x00, + 0x08, 0x14, 0x2A, 0x14, 0x22, + 0x22, 0x14, 0x2A, 0x14, 0x08, + 0xAA, 0x00, 0x55, 0x00, 0xAA, + 0xAA, 0x55, 0xAA, 0x55, 0xAA, + 0x00, 0x00, 0x00, 0xFF, 0x00, + 0x10, 0x10, 0x10, 0xFF, 0x00, + 0x14, 0x14, 0x14, 0xFF, 0x00, + 0x10, 0x10, 0xFF, 0x00, 0xFF, + 0x10, 0x10, 0xF0, 0x10, 0xF0, + 0x14, 0x14, 0x14, 0xFC, 0x00, + 0x14, 0x14, 0xF7, 0x00, 0xFF, + 0x00, 0x00, 0xFF, 0x00, 0xFF, + 0x14, 0x14, 0xF4, 0x04, 0xFC, + 0x14, 0x14, 0x17, 0x10, 0x1F, + 0x10, 0x10, 0x1F, 0x10, 0x1F, + 0x14, 0x14, 0x14, 0x1F, 0x00, + 0x10, 0x10, 0x10, 0xF0, 0x00, + 0x00, 0x00, 0x00, 0x1F, 0x10, + 0x10, 0x10, 0x10, 0x1F, 0x10, + 0x10, 0x10, 0x10, 0xF0, 0x10, + 0x00, 0x00, 0x00, 0xFF, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0xFF, 0x10, + 0x00, 0x00, 0x00, 0xFF, 0x14, + 0x00, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0x00, 0x1F, 0x10, 0x17, + 0x00, 0x00, 0xFC, 0x04, 0xF4, + 0x14, 0x14, 0x17, 0x10, 0x17, + 0x14, 0x14, 0xF4, 0x04, 0xF4, + 0x00, 0x00, 0xFF, 0x00, 0xF7, + 0x14, 0x14, 0x14, 0x14, 0x14, + 0x14, 0x14, 0xF7, 0x00, 0xF7, + 0x14, 0x14, 0x14, 0x17, 0x14, + 0x10, 0x10, 0x1F, 0x10, 0x1F, + 0x14, 0x14, 0x14, 0xF4, 0x14, + 0x10, 0x10, 0xF0, 0x10, 0xF0, + 0x00, 0x00, 0x1F, 0x10, 0x1F, + 0x00, 0x00, 0x00, 0x1F, 0x14, + 0x00, 0x00, 0x00, 0xFC, 0x14, + 0x00, 0x00, 0xF0, 0x10, 0xF0, + 0x10, 0x10, 0xFF, 0x10, 0xFF, + 0x14, 0x14, 0x14, 0xFF, 0x14, + 0x10, 0x10, 0x10, 0x1F, 0x00, + 0x00, 0x00, 0x00, 0xF0, 0x10, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0xFF, 0xFF, 0xFF, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xFF, 0xFF, + 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, + 0x38, 0x44, 0x44, 0x38, 0x44, + 0x7C, 0x2A, 0x2A, 0x3E, 0x14, + 0x7E, 0x02, 0x02, 0x06, 0x06, + 0x02, 0x7E, 0x02, 0x7E, 0x02, + 0x63, 0x55, 0x49, 0x41, 0x63, + 0x38, 0x44, 0x44, 0x3C, 0x04, + 0x40, 0x7E, 0x20, 0x1E, 0x20, + 0x06, 0x02, 0x7E, 0x02, 0x02, + 0x99, 0xA5, 0xE7, 0xA5, 0x99, + 0x1C, 0x2A, 0x49, 0x2A, 0x1C, + 0x4C, 0x72, 0x01, 0x72, 0x4C, + 0x30, 0x4A, 0x4D, 0x4D, 0x30, + 0x30, 0x48, 0x78, 0x48, 0x30, + 0xBC, 0x62, 0x5A, 0x46, 0x3D, + 0x3E, 0x49, 0x49, 0x49, 0x00, + 0x7E, 0x01, 0x01, 0x01, 0x7E, + 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, + 0x44, 0x44, 0x5F, 0x44, 0x44, + 0x40, 0x51, 0x4A, 0x44, 0x40, + 0x40, 0x44, 0x4A, 0x51, 0x40, + 0x00, 0x00, 0xFF, 0x01, 0x03, + 0xE0, 0x80, 0xFF, 0x00, 0x00, + 0x08, 0x08, 0x6B, 0x6B, 0x08, + 0x36, 0x12, 0x36, 0x24, 0x36, + 0x06, 0x0F, 0x09, 0x0F, 0x06, + 0x00, 0x00, 0x18, 0x18, 0x00, + 0x00, 0x00, 0x10, 0x10, 0x00, + 0x30, 0x40, 0xFF, 0x01, 0x01, + 0x00, 0x1F, 0x01, 0x01, 0x1E, + 0x00, 0x19, 0x1D, 0x17, 0x12, + 0x00, 0x3C, 0x3C, 0x3C, 0x3C, + 0x00, 0x00, 0x00, 0x00, 0x00 +])} + diff --git a/Lib/seriffont.py b/Lib/seriffont.py new file mode 100644 index 0000000..836d863 --- /dev/null +++ b/Lib/seriffont.py @@ -0,0 +1,99 @@ + +seriffont = {"Width": 6, "Height": 8, "Start": 32, "End": 127, "Data": bytearray([ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, #0x00, + 0x2F, 0x00, 0x00, 0x00, 0x00, 0x00, #0x00, + 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, #0x00, + 0x12, 0x3F, 0x12, 0x3F, 0x12, 0x00, #0x00, + 0x26, 0x7F, 0x32, 0x00, 0x00, 0x00, #0x00, + 0x13, 0x0B, 0x34, 0x32, 0x00, 0x00, #0x00, + 0x1A, 0x25, 0x1A, 0x28, 0x00, 0x00, #0x00, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, #0x00, + 0x7E, 0x81, 0x00, 0x00, 0x00, 0x00, #0x00, + 0x81, 0x7E, 0x00, 0x00, 0x00, 0x00, #0x00, + 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, #0x00, + 0x08, 0x1C, 0x08, 0x00, 0x00, 0x00, #0x00, + 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, #0x00, + 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, #0x00, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, #0x00, + 0x38, 0x07, 0x00, 0x00, 0x00, 0x00, #0x00, + 0x1E, 0x21, 0x21, 0x1E, 0x00, 0x00, #0x00, + 0x02, 0x3F, 0x00, 0x00, 0x00, 0x00, #0x00, + 0x32, 0x29, 0x29, 0x36, 0x00, 0x00, #0x00, + 0x12, 0x21, 0x25, 0x1A, 0x00, 0x00, #0x00, + 0x18, 0x16, 0x3F, 0x10, 0x00, 0x00, #0x00, + 0x27, 0x25, 0x19, 0x00, 0x00, 0x00, #0x00, + 0x1E, 0x25, 0x25, 0x18, 0x00, 0x00, #0x00, + 0x03, 0x39, 0x07, 0x00, 0x00, 0x00, #0x00, + 0x1A, 0x25, 0x25, 0x1A, 0x00, 0x00, #0x00, + 0x06, 0x29, 0x29, 0x1E, 0x00, 0x00, #0x00, + 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, #0x00, + 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, #0x00, + 0x08, 0x14, 0x22, 0x00, 0x00, 0x00, #0x00, + 0x14, 0x14, 0x14, 0x00, 0x00, 0x00, #0x00, + 0x22, 0x14, 0x08, 0x00, 0x00, 0x00, #0x00, + 0x02, 0x29, 0x05, 0x02, 0x00, 0x00, #0x00, + 0x1C, 0x22, 0x49, 0x55, 0x59, 0x12, #0x0C, + 0x30, 0x2C, 0x0B, 0x0B, 0x2C, 0x30, #0x00, + 0x21, 0x3F, 0x25, 0x25, 0x1A, 0x00, #0x00, + 0x1E, 0x21, 0x21, 0x21, 0x13, 0x00, #0x00, + 0x21, 0x3F, 0x21, 0x21, 0x1E, 0x00, #0x00, + 0x21, 0x3F, 0x25, 0x33, 0x00, 0x00, #0x00, + 0x21, 0x3F, 0x25, 0x03, 0x00, 0x00, #0x00, + 0x1E, 0x21, 0x21, 0x29, 0x3B, 0x00, #0x00, + 0x3F, 0x04, 0x04, 0x3F, 0x00, 0x00, #0x00, + 0x3F, 0x21, 0x00, 0x00, 0x00, 0x00, #0x00, + 0x21, 0x1F, 0x01, 0x00, 0x00, 0x00, #0x00, + 0x21, 0x3F, 0x0C, 0x33, 0x21, 0x00, #0x00, + 0x3F, 0x21, 0x30, 0x00, 0x00, 0x00, #0x00, + 0x21, 0x3F, 0x0C, 0x30, 0x0C, 0x3F, #0x21, + 0x3F, 0x03, 0x0C, 0x3F, 0x01, 0x00, #0x00, + 0x1E, 0x21, 0x21, 0x21, 0x1E, 0x00, #0x00, + 0x3F, 0x29, 0x06, 0x00, 0x00, 0x00, #0x00, + 0x1E, 0x21, 0x21, 0x61, 0x1E, 0x00, #0x00, + 0x21, 0x3F, 0x09, 0x36, 0x00, 0x00, #0x00, + 0x32, 0x25, 0x25, 0x1B, 0x00, 0x00, #0x00, + 0x01, 0x3F, 0x01, 0x00, 0x00, 0x00, #0x00, + 0x1F, 0x21, 0x20, 0x21, 0x1F, 0x00, #0x00, + 0x03, 0x0D, 0x30, 0x30, 0x0D, 0x03, #0x00, + 0x0F, 0x31, 0x0C, 0x0C, 0x31, 0x0F, #0x00, + 0x21, 0x33, 0x0C, 0x0C, 0x33, 0x21, #0x00, + 0x03, 0x24, 0x38, 0x24, 0x03, 0x01, #0x00, + 0x29, 0x25, 0x33, 0x00, 0x00, 0x00, #0x00, + 0x7F, 0x41, 0x00, 0x00, 0x00, 0x00, #0x00, + 0x07, 0x38, 0x00, 0x00, 0x00, 0x00, #0x00, + 0x41, 0x7F, 0x00, 0x00, 0x00, 0x00, #0x00, + 0x02, 0x01, 0x02, 0x00, 0x00, 0x00, #0x00, + 0x40, 0x40, 0x40, 0x40, 0x00, 0x00, #0x00, + 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, #0x00, + 0x14, 0x24, 0x38, 0x00, 0x00, 0x00, #0x00, + 0x3F, 0x28, 0x24, 0x18, 0x00, 0x00, #0x00, + 0x18, 0x24, 0x24, 0x00, 0x00, 0x00, #0x00, + 0x18, 0x24, 0x25, 0x3F, 0x00, 0x00, #0x00, + 0x18, 0x24, 0x28, 0x00, 0x00, 0x00, #0x00, + 0x3E, 0x25, 0x00, 0x00, 0x00, 0x00, #0x00, + 0x18, 0xA4, 0xA4, 0x7C, 0x00, 0x00, #0x00, + 0x3F, 0x04, 0x38, 0x00, 0x00, 0x00, #0x00, + 0x3D, 0x00, 0x00, 0x00, 0x00, 0x00, #0x00, + 0xFD, 0x00, 0x00, 0x00, 0x00, 0x00, #0x00, + 0x3F, 0x18, 0x24, 0x00, 0x00, 0x00, #0x00, + 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, #0x00, + 0x3C, 0x04, 0x38, 0x04, 0x38, 0x00, #0x00, + 0x3C, 0x04, 0x38, 0x00, 0x00, 0x00, #0x00, + 0x18, 0x24, 0x24, 0x18, 0x00, 0x00, #0x00, + 0xFC, 0xA4, 0x24, 0x18, 0x00, 0x00, #0x00, + 0x18, 0x24, 0xA4, 0xFC, 0x00, 0x00, #0x00, + 0x3C, 0x04, 0x00, 0x00, 0x00, 0x00, #0x00, + 0x28, 0x24, 0x14, 0x00, 0x00, 0x00, #0x00, + 0x1E, 0x24, 0x00, 0x00, 0x00, 0x00, #0x00, + 0x1C, 0x20, 0x3C, 0x00, 0x00, 0x00, #0x00, + 0x0C, 0x30, 0x0C, 0x00, 0x00, 0x00, #0x00, + 0x0C, 0x30, 0x0C, 0x30, 0x0C, 0x00, #0x00, + 0x24, 0x18, 0x24, 0x00, 0x00, 0x00, #0x00, + 0x9C, 0x60, 0x1C, 0x00, 0x00, 0x00, #0x00, + 0x34, 0x24, 0x2C, 0x00, 0x00, 0x00, #0x00, + 0x08, 0x77, 0x00, 0x00, 0x00, 0x00, #0x00, + 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, #0x00, + 0x77, 0x08, 0x00, 0x00, 0x00, 0x00, #0x00, + 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, #0x00, + 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, #0x00 +])} diff --git a/Lib/terminalfont.py b/Lib/terminalfont.py new file mode 100644 index 0000000..0ba22f7 --- /dev/null +++ b/Lib/terminalfont.py @@ -0,0 +1,100 @@ + +terminalfont = {"Width": 6, "Height": 8, "Start": 32, "End": 127, "Data": bytearray([ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x06, 0x5F, 0x06, 0x00, + 0x00, 0x07, 0x03, 0x00, 0x07, 0x03, + 0x00, 0x24, 0x7E, 0x24, 0x7E, 0x24, + 0x00, 0x24, 0x2B, 0x6A, 0x12, 0x00, + 0x00, 0x63, 0x13, 0x08, 0x64, 0x63, + 0x00, 0x36, 0x49, 0x56, 0x20, 0x50, + 0x00, 0x00, 0x07, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x3E, 0x41, 0x00, 0x00, + 0x00, 0x00, 0x41, 0x3E, 0x00, 0x00, + 0x00, 0x08, 0x3E, 0x1C, 0x3E, 0x08, + 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08, + 0x00, 0x00, 0xE0, 0x60, 0x00, 0x00, + 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, + 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, + 0x00, 0x20, 0x10, 0x08, 0x04, 0x02, + 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E, + 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00, + 0x00, 0x62, 0x51, 0x49, 0x49, 0x46, + 0x00, 0x22, 0x49, 0x49, 0x49, 0x36, + 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10, + 0x00, 0x2F, 0x49, 0x49, 0x49, 0x31, + 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30, + 0x00, 0x01, 0x71, 0x09, 0x05, 0x03, + 0x00, 0x36, 0x49, 0x49, 0x49, 0x36, + 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E, + 0x00, 0x00, 0x6C, 0x6C, 0x00, 0x00, + 0x00, 0x00, 0xEC, 0x6C, 0x00, 0x00, + 0x00, 0x08, 0x14, 0x22, 0x41, 0x00, + 0x00, 0x24, 0x24, 0x24, 0x24, 0x24, + 0x00, 0x00, 0x41, 0x22, 0x14, 0x08, + 0x00, 0x02, 0x01, 0x59, 0x09, 0x06, + 0x00, 0x3E, 0x41, 0x5D, 0x55, 0x1E, + 0x00, 0x7E, 0x11, 0x11, 0x11, 0x7E, + 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36, + 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22, + 0x00, 0x7F, 0x41, 0x41, 0x41, 0x3E, + 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41, + 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01, + 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A, + 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F, + 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00, + 0x00, 0x30, 0x40, 0x40, 0x40, 0x3F, + 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41, + 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40, + 0x00, 0x7F, 0x02, 0x04, 0x02, 0x7F, + 0x00, 0x7F, 0x02, 0x04, 0x08, 0x7F, + 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E, + 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06, + 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E, + 0x00, 0x7F, 0x09, 0x09, 0x19, 0x66, + 0x00, 0x26, 0x49, 0x49, 0x49, 0x32, + 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01, + 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F, + 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F, + 0x00, 0x3F, 0x40, 0x3C, 0x40, 0x3F, + 0x00, 0x63, 0x14, 0x08, 0x14, 0x63, + 0x00, 0x07, 0x08, 0x70, 0x08, 0x07, + 0x00, 0x71, 0x49, 0x45, 0x43, 0x00, + 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00, + 0x00, 0x02, 0x04, 0x08, 0x10, 0x20, + 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00, + 0x00, 0x04, 0x02, 0x01, 0x02, 0x04, + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, + 0x00, 0x00, 0x03, 0x07, 0x00, 0x00, + 0x00, 0x20, 0x54, 0x54, 0x54, 0x78, + 0x00, 0x7F, 0x44, 0x44, 0x44, 0x38, + 0x00, 0x38, 0x44, 0x44, 0x44, 0x28, + 0x00, 0x38, 0x44, 0x44, 0x44, 0x7F, + 0x00, 0x38, 0x54, 0x54, 0x54, 0x08, + 0x00, 0x08, 0x7E, 0x09, 0x09, 0x00, + 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C, + 0x00, 0x7F, 0x04, 0x04, 0x78, 0x00, + 0x00, 0x00, 0x00, 0x7D, 0x40, 0x00, + 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00, + 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00, + 0x00, 0x00, 0x00, 0x7F, 0x40, 0x00, + 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78, + 0x00, 0x7C, 0x04, 0x04, 0x78, 0x00, + 0x00, 0x38, 0x44, 0x44, 0x44, 0x38, + 0x00, 0xFC, 0x44, 0x44, 0x44, 0x38, + 0x00, 0x38, 0x44, 0x44, 0x44, 0xFC, + 0x00, 0x44, 0x78, 0x44, 0x04, 0x08, + 0x00, 0x08, 0x54, 0x54, 0x54, 0x20, + 0x00, 0x04, 0x3E, 0x44, 0x24, 0x00, + 0x00, 0x3C, 0x40, 0x20, 0x7C, 0x00, + 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C, + 0x00, 0x3C, 0x60, 0x30, 0x60, 0x3C, + 0x00, 0x6C, 0x10, 0x10, 0x6C, 0x00, + 0x00, 0x9C, 0xA0, 0x60, 0x3C, 0x00, + 0x00, 0x64, 0x54, 0x54, 0x4C, 0x00, + 0x00, 0x08, 0x3E, 0x41, 0x41, 0x00, + 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, + 0x00, 0x00, 0x41, 0x41, 0x3E, 0x08, + 0x00, 0x02, 0x01, 0x02, 0x01, 0x00, + 0x00, 0x3C, 0x26, 0x23, 0x26, 0x3C +])} + diff --git a/README.md b/README.md new file mode 100644 index 0000000..ee4a483 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# My MicroPython repository + +## Contents + +* ST7735 - Sainsmart LCD display driver. diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..7c70b74 --- /dev/null +++ b/README.txt @@ -0,0 +1,12 @@ +This is a Micro Python board + +You can get started right away by writing your Python code in 'main.py'. + +For a serial prompt: + - Windows: you need to go to 'Device manager', right click on the unknown device, + then update the driver software, using the 'pybcdc.inf' file found on this drive. + Then use a terminal program like Hyperterminal or putty. + - Mac OS X: use the command: screen /dev/tty.usbmodem* + - Linux: use the command: screen /dev/ttyACM0 + +Please visit http://micropython.org/help/ for further help. diff --git a/SonarDisplay.py b/SonarDisplay.py new file mode 100644 index 0000000..b7ab21f --- /dev/null +++ b/SonarDisplay.py @@ -0,0 +1,113 @@ +#Display distance reported by the HC-SR04 on the ST7735 LCD. + +import ultrasonic +import pyb +from ST7735 import NAVY, CYAN, Point, TFTColor +import terminalfont + +ZeroPoint = Point(0, 0) +SONAR_DELAY = 100 +FONT_HEIGHT = terminalfont.terminalfont["Height"] + +#100-15 = blue +#15-10 = green +#10-5 = yellow +#5-0 = red + +COLORS = [(0, 255, 0, 0) + (5, 255, 255, 0), + (10, 0, 255, 0), + (15, 0, 0, 255), + ] + +def getrgb( aDistance ) : + '''Get an interpolated TFTColor based on distance. + Uses the COLORS list.''' + clr = NAVY + + def interp(l, v0, v1): + return (v0 * (1.0 - l) + (v1 * l)) + + for i in range(1, len(COLORS)) : + c = colors[i] + if c[0] >= aDistance: + rng0, r0, g0, b0 = colors[i - 1] + rng1, r1, g1, b1 = c + #interpolate between rng0 and rng1 + l = (aDistance - rng0) / float(rng1 - rng0) + r = interp(l, r0, r1) + g = interp(l, g0, g1) + b = interp(l, b0, b1) + clr = TFTColor(r,g,b) + + return clr + +class RangePoint(object): + """Display a point on the screen""" + + def __init__(self, aSize): + self.size = aSize + self.pos = Point(-1, 0) + self.prevdistance = -1 + + def update( self, aDisplay, aDistance, aTime ) : + if (self.prevdistance != aDistance): + self._draw(aDisplay, 0) + clr = getrgb(aDistance) + self.pos.x = int((aDisplay.size.x / 2) - (self.size / 2)) + y = min(1.0, aDistance / MAXRANGE) + self.pos.y = int(y * aDisplay.size.y) + self._draw(aDisplay, clr) + self.prevdistance = aDistance + + def _draw( self, aDisplay, aColor ) : + if self.pos.x >= 0: + aDisplay.fillrect(self.pos, self.size, aColor) + +class SonarDisplay(object): + """Display HC-SR04 distance on ST7735 LCD with text and a box""" + def __init__( self, aDisplay, aTrigger, aEcho ): + self.display = aDisplay + self.triggerpin = aTrigger + self.echopin = aEcho + self.rangepoint = RangePoint(4) + self.hc = ultrasonic.Ultrasonic(self.triggerpin, self.echopin) + + def printdistance( self, aDistance ) : + s = "I: " + str(aDistance) + aDisplay.fillrect(ZeroPoint, Point(aDisplay.size.x, FONT_HEIGHT), 0) + aDisplay.drawstring(ZeroPoint, s, CYAN, terminalfont.terminalfont) + + def run( self ): + self.display.fill(0) + sw = pyb.Switch() + lasttime = pyb.millis() + while sw() == False : + pyb.delay(SONAR_DELAY) + distance = self.hc.distance_in_inches() + thistime = pyb.millis() + t = thistime - lasttime + self.printdistance(distance) + self.rangepoint.update(self.display, distance, t / 1000.0) + lasttime = thistime + +# sensor1_trigPin = pyb.Pin.board.X8 +# sensor1_echoPin = pyb.Pin.board.X7 + +# sensor1 = ultrasonic.Ultrasonic(sensor1_trigPin, sensor1_echoPin) + +# switch = pyb.Switch() + +# # function that prints each sensor's distance +# def print_sensor_values(): +# # get sensor1's distance in cm +# distance1 = sensor1.distance_in_inches() + +# print("Sensor1", distance1, "inches") + +# # prints values every second +# while True: +# print("Sensing") +# print_sensor_values() +# # ultrasonic.wait(10000) +# pyb.delay(100) diff --git a/TreatThrower.py b/TreatThrower.py new file mode 100644 index 0000000..5f632d9 --- /dev/null +++ b/TreatThrower.py @@ -0,0 +1,41 @@ +# Control bot that throws treats using a servo + +import pyb + +servoNum = 1 +servoCenter = 1440 +servoSpeed = 100 +servoTime = 1450 +ledNum = 3 +triggerInput = 'X3' + +def runservo( aServo, aSpeed, aDelay ): + aServo.speed(aSpeed) + pyb.delay(aDelay) + aServo.speed(0) + +def main( ) : + s1 = pyb.Servo(servoNum) + btn = pyb.Pin(triggerInput, pyb.Pin.IN, pyb.Pin.PULL_UP) + mn, mx, _, a, s = s1.calibration() + s1.calibration(mn, mx, servoCenter, a, s) + s1.speed(0) + l = pyb.LED(ledNum) + + def throwit( ): + l.on() + runservo(s1, servoSpeed, servoTime) + l.off() + + sw = pyb.Switch() +# sw.callback(throwit) + + while(1): + if (btn.value() == 0): + throwit() + if sw(): + break; + pyb.delay(20) + +if __name__ == '__main__': + main() diff --git a/_SYNCAPP/metadata.xml b/_SYNCAPP/metadata.xml new file mode 100644 index 0000000000000000000000000000000000000000..cd6995a03c66391d2817d2cdda2d9cc0270a398f GIT binary patch literal 16214 zcmc(G2UB9(wk`%Tf+9h3P{}!pAV?Af1(b{gQ9vaJB`NsV-(aoP-R{%%?me$+SG`)* zo2uO{!klxA@um5YUi6>+!=ZFof9^CJ(!%YHbT*qA>fP?FzL>yY8lDHeif8AOvn=VZ z-BDRWD)P~#`xfSmw`7lwrUyFu1LL|;URU+Svz#UEOL-q!Ax-$D(CXAHbof{9xLeR8 zEhEj;I{tR8DyXXN>-XGCc7DA|)l=h}A;*z#M^`uN>rr?bYF(Wkoi7wk)vc@Gsi>pv z%q#vhF}d?R8{)p|`GYY*4A%Wlib|*x>e}Uju2&N4d9tTFZkBc5$UjM$`A5a0?6LTn zY3EG)pH~fX?%;WQ%#V3*`UxY`gm>c3s26xU*O_^Xlk%*HH)VY%yl}rO&ovisob2Ih z-0|Vem9ylDlda>Or`jqpzg_sJ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dn{Q)DUm~w>W_UQ2$CEN4 zCv$MhMxP(I3*UG#YsI^uw)tc49Y7q=HCvD%=w+M#%-nE}_tl-USjjbXjh(8XC@M?f zzG7Y3%(3A{6o)3n&*ONF}H_MyFEkreu%O*`gM=uf3BR<05ZO1<^ zpg*5ed|wGl;uGRh1QXFecQ51LP-GD3--6qZ1RD-UIi&FR?veA~5cT=rOuwoKH&Jfnr59YxJyeL%N8+HFyu>76S_Nb5g|Aa{~5r4jLh zbYUNwwu6Z7=4K9dWdRA3Qz3x3KPFC4i|z6!J3#Jo#f}r&7sAIDDiZAY^BU4>bpAMd=O;oA*83Zv@k4B<7XNKLyI~4G+_AWjZ?XTyiyary`v<5)@RRD63?-HSI48gE#NjHy z!CzE)b5+feKS`nYHb7RHCFjXid>Mq>eEvxUAqCjAM9NZ~@>ck-XY{X literal 0 HcmV?d00001 diff --git a/bombs.py b/bombs.py new file mode 100644 index 0000000..d9b3186 --- /dev/null +++ b/bombs.py @@ -0,0 +1,63 @@ + +import pyb +import time +from ST7735 import Point, CYAN, RED, GREEN, YELLOW, TFTColor + +#todo: Pick a ransom spot, random radius, random color +#todo: Animate the spot + +colorA = [CYAN, RED, GREEN, YELLOW] + +class bomb(object): + """Animate a circle on the screen.""" + def __init__(self, aPos, aRadius, aColor, aSpeed): + self.pos = aPos + self.radius = aRadius + self.color = aColor + self.speed = aSpeed + self.curradius = 0.0 + self.state = 0 + + def update( self, aDisplay, aTime ) : + self.curradius += self.speed * aTime + rad = self.curradius + color = self.color + if self.curradius > self.radius: + rad = self.radius + self.state += 1 + self.color = 0 + self.curradius = 1.0 + + aDisplay.fillcircle(self.pos, rad, color) + + return self.state != 2 + +def randval( aVal ) : + v = pyb.rng() & 0xFFFF + return aVal * (v / 65535.0) + +class bomber(object): + """Control a bunch of bombs.""" + def __init__(self, aDisplay): + self.display = aDisplay + self.numbombs = 4 + self.bombs = [] + self.sw = pyb.Switch() + + def addbomb( self ) : + x = int(randval(self.display.size.x)) + y = int(randval(self.display.size.y)) + rad = randval(20) + 5 + r = pyb.rng() & 0xFF + g = pyb.rng() & 0xFF + b = pyb.rng() & 0xFF + spd = randval(30.0) + 1.0 + clr = TFTColor(r,g,b) #colorA[pyb.rng() & 0x03] + self.bombs.insert(0, bomb(Point(x, y), rad, clr, spd)) + + def run( self ) : + while self.sw() == False : + pyb.delay(100) + if len(self.bombs) < self.numbombs: + self.addbomb() + self.bombs = [b for b in self.bombs if b.update(self.display, 0.1) ] diff --git a/level.py b/level.py new file mode 100644 index 0000000..62c3bdf --- /dev/null +++ b/level.py @@ -0,0 +1,70 @@ +#Show level bubble run by the accelerometer + +import pyb +from ST7735 import RED, CYAN, Point +import terminalfont + +ZeroPoint = Point(0, 0) + +class Bubble(object): + """Circle simulating the level bubble.""" + + def __init__(self, aCenter, aSpeed, aRadius, aColor): + self.center = aCenter.clone() + self.pos = aCenter.clone() + self.oldpos = pos.clone() + self.speed = aSpeed + self.radius = aRadius + self.color = aColor + self.accel = pyb.Accel() + + def update( self, aDisplay, aTime ) : + xtilt, ytilt, _ = self.accel.filtered_xyz() +# xtilt = self.accel.x() +# ytilt = self.accel.y() + + xs = (aDisplay.size.x / 2) / 70.0 + ys = (aDisplay.size.y / 2) / 60.0 + + self.oldpos.x = self.pos.x + self.oldpos.y = self.pos.y + self.pos.x = int(self.center.x + xtilt * xs) + self.pos.y = int(self.center.y - ytilt * ys) + s = "x: " + str(xtilt) + " y: " + str(ytilt) + aDisplay.fillrect(ZeroPoint, Point(aDisplay.size.x, 10), 0) + aDisplay.drawstring(ZeroPoint, s, CYAN, terminalfont.terminalfont) +# aTime *= self.speed +# self.pos.x += xtilt * aTime +# self.pos.y -= ytilt * aTime + + self._clamp(aDisplay) + aDisplay.fillcircle(self.oldpos, self.radius, 0) + self._draw(aDisplay, self.color) + + def _draw( self, aDisplay, aColor ) : + aDisplay.fillcircle(self.pos, self.radius, aColor) + + def _clamp( self, aDisplay ) : + l = self.radius + t = l + r = aDisplay.size.x - l + b = aDisplay.size.y - l + self.pos.x = max(l, min(self.pos.x, r)) + self.pos.y = max(t, min(self.pos.y, b)) + +class Level(object): + """Simulate a level by controlling a bubble on the aDisplay + controlled by the accelerometer.""" + def __init__(self, aDisplay): + self.display = aDisplay + center = aDisplay.size.clone() + center.x /= 2 + center.y /= 2 + self.bubble = Bubble(center, 10.0, 5, RED) + + def run( self ) : + self.display.fill(0) + sw = pyb.Switch() + while sw() == False : + pyb.delay(100) + self.bubble.update(self.display, 0.1) diff --git a/main.py b/main.py new file mode 100644 index 0000000..b28b1a2 --- /dev/null +++ b/main.py @@ -0,0 +1,31 @@ +# main.py -- put your code here! + +# import TreatThrower +# import Balance + +# Balance.main() + +from basicfont import * +from seriffont import * +from terminalfont import * +from bombs import bomber +from level import Level + +t = makeg() + +def tst( aColor ): + s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-=_+[]{}l;'<>?,./!@#$%^&*():" + t.drawstring(Point(0, 0), s, aColor, basicfont) + t.drawstring(Point(0, 40), s, aColor, seriffont) + t.drawstring(Point(0, 80), s, aColor, terminalfont) + +# tst(BLUE) + +def s(aRot, aColor): + t.setrotation(aRot) + tst(aColor) + +# b = bomber(t) +t.setrotation(2) +l = Level(t) +l.run()