Bloggerでシンタックスハイライト

Visual Studio Codeから Bloggerの「作成ビュー」にコピペすれば、書式ごと色がついた状態でペーストされるので簡単で良い。

time.sleep(wait)
lcd.invertDisplay(True)   # 画面の色を反転する。表示内容は消えない。
time.sleep(1)
lcd.invertDisplay(False)  # 色反転を元に戻す


ソースコードが長くてスクロールバーを出したいときには、Visual Studio Codeからペーストした後で、Bloggerの「HTML ビュー」にして、ペーストしたコードを

  <code style="height: 20em; overflow: scroll; border: 1px solid; "></code> 

 なんかで囲んでしまえば良い。<code> じゃなくて <div> でも良い。


lcd = LCD()                            # LCDを初期化してバックライト点灯
color = lcd.color.BLACK
lcd.fillScreen(color)                  # 画面の塗りつぶし

wait = 4
x, y = 0, 0
lcd.drawString("Font test テスト", x, y)       # 日本語は表示できない

y += lcd.fontHeight(0)                         # fontHeightで現在設定されているフォントの高さが得られる。引数が何なのか不明
                                               # 引数に何を指定しても結果は変わらないようにみえる
lcd.drawString("0123456789", x, y)

y += lcd.fontHeight(0)
font = 1                                         # Font 1は 6x8ドットフォント
lcd.drawString("Font 1 0123456789", x, y, font)  
y += 8
font = 2                                         # Font 2は 16ドットフォント
lcd.drawString("Font 2 0123456789", x, y, font)  
y += 16
font = 4                                         # Font 4は 26ドットフォント
color, bgcolor = lcd.color.BLACK, lcd.color.GREEN
lcd.setTextColor(color, bgcolor)                 # 文字色の設定 文字色, 背景色
lcd.drawString("Font 4 01234", x, y, font)  
y += 26
font = 6                                         # Font 6は数字だけ表示 48ドットフォント
color, bgcolor = lcd.color.WHITE, lcd.color.BLUE
lcd.setTextColor(color, bgcolor)
lcd.drawString("Font 6 01234", x, y, font)  
y += 48
font = 7                                         # Font 7は 7セグ風フォント 数字だけ表示 48ドット
color=lcd.color.GREEN
lcd.setTextColor(color)
lcd.drawString("7 01234", x, y, font)  
y+=48
font=8 # Font 8は数字だけ表示 高さ75ドットくらい 8が最大
color, bgcolor = lcd.color565(255, 120, 100), lcd.color.GREEN  # color565で24bitカラーから16bitカラーへ変換できる
lcd.setTextColor(color, bgcolor)
lcd.drawString("8 0123", x, y, font)  
                                    # Font 0, 3, 5は表示されない

# setTextSize(倍率)  文字サイズの設定
time.sleep(wait)
color, bgcolor = lcd.color.WHITE, lcd.color.BLACK
lcd.setTextColor(color)
lcd.fillScreen(bgcolor)
x, y = 3, 1
font = 0
lcd.setTextFont(font) # 描画時にフォントを指定しないときのフォントを設定する
lcd.drawString("Font0 0123", x, y)     # フォントの指定は省略できる
y+=lcd.fontHeight(0)
lcd.setTextSize(2)                     # 文字サイズの設定 2倍になる
lcd.drawString("Font0 0123", x, y)
y+=lcd.fontHeight(0)                   # fontHeightは TextSizeの倍率も反映される
lcd.setTextFont(2)
lcd.setTextSize(1)                     # 文字サイズの設定 1倍になる
lcd.drawString("Font2 0123", x, y)
y+=lcd.fontHeight(0)
lcd.setTextSize(2)                     # 文字サイズの設定 2倍になる
lcd.drawString("Font2 0123", x, y)
y+=lcd.fontHeight(0)
lcd.setTextSize(3)                     # 文字サイズの設定 3倍になる
lcd.drawString("Font2 0123", x, y)

# setRotation(向き) 描画向きの設定(画面の回転)
time.sleep(wait)
lcd.fillScreen(lcd.color.BLACK)
lcd.setTextSize(1)
x, y = 0, 0
lcd.setTextFont(4)
lcd.setRotation(0)                          # 描画向きの設定(画面の回転) 0~7
                                            # 向きの設定を変えても表示内容は保持する
lcd.drawString("Rotation(0) 0123", x, y)
lcd.setRotation(1)
lcd.drawString("Rotation(1) 0123", x, y)
lcd.setRotation(2)
lcd.drawString("Rotation(2) 0123", x, y)
lcd.setRotation(3)
lcd.drawString("Rotation(3) 0123", x, y)
y += lcd.fontHeight(0)
x += lcd.fontHeight(0)
lcd.setRotation(4)                          # 鏡像にもできる
lcd.drawString("Rotation(4) 01", x, y)
lcd.setRotation(5)
lcd.drawString("Rotation(5) 01", x, y)
lcd.setRotation(6)
lcd.drawString("Rotation(6) 01", x, y)
lcd.setRotation(7)
lcd.drawString("Rotation(7) 01", x, y)
lcd.setRotation(3)                          # 描画向きを元に戻す
rotation = lcd.getRotation()                # getRotation()で現在のRotationを取得できる

x, y = lcd.width // 2, lcd.height // 2      # heightと widthで画面サイズを取得できる
                                            # "//"は結果を整数で返す割り算
lcd.setTextDatum(lcd.datum.CC_DATUM)               # 文字位置を指定する基準の設定 CC_DATUM(中央)を指定して
lcd.drawString("Rotation " + str(rotation), x, y)  # 画面中央の座標に文字を表示すると、ど真ん中に表示される
datum = lcd.getTextDatum()                         # getTextDatum()で現在のDatumを取得できる
y += lcd.fontHeight(0)
lcd.drawString("Datum " + str(datum), x, y)
lcd.setTextDatum(lcd.datum.TL_DATUM)               # 基準点を左上に戻す

time.sleep(wait)
lcd.invertDisplay(True)   # 画面の色を反転する。表示内容は消えない。
time.sleep(1)
lcd.invertDisplay(False)  # 色反転を元に戻す

# 文字表示関数いろいろ fontは省略できる
time.sleep(wait)
lcd.fillScreen(lcd.color.BLACK)
x, y = lcd.width // 2, 0
#color, bgcolor = lcd.color.WHITE, lcd.color.BLACK
font = 4
lcd.drawChar(ord("a"), x, y, font)               # 一文字表示
y += lcd.fontHeight(0)
lcd.drawString("drawString", x, y, font)         # 文字列表示
y += lcd.fontHeight(0)
lcd.drawRightString("RightString", x, y, font)   # 文字列の右端を基準に表示
y += lcd.fontHeight(0)
lcd.drawCentreString("CentreString", x, y, font) # 文字列と中心を基準に表示
lcd.drawFastVLine(x, 0, lcd.height, lcd.color.RED) # 基準位置に線を引く

こんな感じになります。

このブログの人気の投稿

windowsで「インターネット接続の共有」の設定

月刊 I/O 記事リスト 1976~1989

X68000実機のROMを保存