---
# System prepended metadata

title: 60718 高三(下)  登月小車

---

LCD面板圖片顯示
```javascript=
try:
  def printExcept(e):
    lcd.clear()
    log = str(e)
    sys.print_exception(e)
    data_len, i, colume = 30, 0, 0
    while i < len(log):
      lcd.draw_string(50, 100 + (colume * 20), (log[i : i + data_len] + '\n'), 0x00F8, 0x0000)
      i = i + data_len
      colume = colume + 1

  from time import sleep
  from webai_blockly import Lcd
  from time import sleep
  
  try:
    from webai import *
  except:
    pass
  
  view = Lcd()
  
  # RUN USB MODE
  _deviceID = '3f69d6'
  try:
    print(_onServiceEvent)
    from time import sleep
    sleep(1)
    webai.mqtt.sub(topic=_deviceID + '/SERVICE', callback=_onServiceEvent)
  except:
    pass
  
  
  while True:
    view.displayImg(img=(webai.res.loadImg('mleft.jpg')))
    sleep(0.5)
    view.displayImg(img=(webai.res.loadImg('mright.jpg')))
    sleep(0.5)
  
    sleep(0.001)
except Exception as e:
  printExcept(e)
```
LCD面板圖片顯示 （圖片）
![截圖 2024-03-18 下午3.31.42](https://hackmd.io/_uploads/BkOAedrCa.png)

心得：
LCD面板是常見的顯示技術，具有高解析度、低功耗和薄型設計等優點。其可視角度廣，色彩表現良好，適用於各種設備。然而，LCD面板存在視角依賴性、響應時間較慢和對比度有限等缺點。在暗場景下效果較差。儘管如此，LCD面板仍然是一種成熟且廣泛應用的技術，並且隨著技術的進步，其性能和特性可能會繼續改善。










顏色追蹤

```javascript=
try:
  def printExcept(e):
    lcd.clear()
    log = str(e)
    sys.print_exception(e)
    data_len, i, colume = 30, 0, 0
    while i < len(log):
      lcd.draw_string(50, 100 + (colume * 20), (log[i : i + data_len] + '\n'), 0x00F8, 0x0000)
      i = i + data_len
      colume = colume + 1

  from time import sleep
  from webai_blockly import Camera
  from webai import ColorObject
  from webai_blockly import Lcd
  
  _E7_95_AB_E9_9D_A2 = 0
  _E9_A1_8F_E8_89_B2_E8_B3_87_E8_A8_8A = 0
  
  try:
    from webai import *
  except:
    pass
  
  camera = Camera()
  
  view = Lcd()
  
  def _hex_to_rgb(hex):
    h = hex.lstrip('#')
    return tuple(int(h[i:i+2], 16) for i in (0, 2, 4))
  
  def _rgb_to_hex565(rgb):
    (red, green, blue) = rgb
    hex565 = "0x%0.4X" % ((int(red / 255 * 31) << 11) | (int(green / 255 * 63) << 5) | (int(blue / 255 * 31)))
    board_hex = '0x' + hex565[4:] + hex565[2:4]
    return int(board_hex, 16)
  
  # RUN USB MODE
  _deviceID = '6e54b1'
  try:
    print(_onServiceEvent)
    from time import sleep
    sleep(1)
    webai.mqtt.sub(topic=_deviceID + '/SERVICE', callback=_onServiceEvent)
  except:
    pass
  
  
  while True:
    _E7_95_AB_E9_9D_A2 = camera.snapshot()
    # 可點擊右鍵->小工具，使用顏色小工具選擇顏色
    _E9_A1_8F_E8_89_B2_E8_B3_87_E8_A8_8A = ColorObject.findMax(_E7_95_AB_E9_9D_A2, (0,100,24,128,-128,128))
    if (_E9_A1_8F_E8_89_B2_E8_B3_87_E8_A8_8A.pixels() if _E9_A1_8F_E8_89_B2_E8_B3_87_E8_A8_8A else 0) > 10:
      view.drawString(x=125, y=110, text=b"{var}".format(var='紅色'), color=_rgb_to_hex565(_hex_to_rgb('#ffffff')), scale=2, x_spacing=20, img=_E7_95_AB_E9_9D_A2, display=False)
    view.displayImg(img=_E7_95_AB_E9_9D_A2)
  
    sleep(0.001)
except Exception as e:
  printExcept(e)
```

顏色追蹤 （圖片）
![截圖 2024-03-04 下午3.40.02](https://hackmd.io/_uploads/S1IJjg76a.png)

心得：
顏色追蹤技術是一種在影像處理和電腦視覺領域中常見的技術，能夠快速識別特定顏色的物體，並在即時性要求較高的應用中表現出色。它廣泛應用於機器人導航、遊戲開發、安防監控等領域，具有簡單高效、互動有趣的優勢。然而，多顏色環境和光線不穩定等因素可能影響其準確性，需要不斷調整和優化算法。總的來說，顏色追蹤技術有著廣闊的應用前景，通過持續的研究改進，相信它將在未來發揮更加重要的作用。









小畫家：車的圖案
```javascript=
try:
  def printExcept(e):
    lcd.clear()
    log = str(e)
    sys.print_exception(e)
    data_len, i, colume = 30, 0, 0
    while i < len(log):
      lcd.draw_string(50, 100 + (colume * 20), (log[i : i + data_len] + '\n'), 0x00F8, 0x0000)
      i = i + data_len
      colume = colume + 1

  from webai_blockly import Lcd
  
  try:
    from webai import *
  except:
    pass
  
  view = Lcd()
  
  def _hex_to_rgb(hex):
    h = hex.lstrip('#')
    return tuple(int(h[i:i+2], 16) for i in (0, 2, 4))
  
  def _rgb_to_hex565(rgb):
    (red, green, blue) = rgb
    hex565 = "0x%0.4X" % ((int(red / 255 * 31) << 11) | (int(green / 255 * 63) << 5) | (int(blue / 255 * 31)))
    board_hex = '0x' + hex565[4:] + hex565[2:4]
    return int(board_hex, 16)
  
  # RUN USB MODE
  _deviceID = '6e54b1'
  try:
    print(_onServiceEvent)
    from time import sleep
    sleep(1)
    webai.mqtt.sub(topic=_deviceID + '/SERVICE', callback=_onServiceEvent)
  except:
    pass
  
  
  view.drawLine(x0=88, y0=50, x1=230, y1=50, color=_rgb_to_hex565(_hex_to_rgb('#ffffff')), thickness=3)
  view.drawLine(x0=88, y0=50, x1=88, y1=105, color=_rgb_to_hex565(_hex_to_rgb('#ffffff')), thickness=3)
  view.drawLine(x0=230, y0=50, x1=230, y1=105, color=_rgb_to_hex565(_hex_to_rgb('#ffffff')), thickness=3)
  view.drawLine(x0=40, y0=105, x1=90, y1=105, color=_rgb_to_hex565(_hex_to_rgb('#ffffff')), thickness=3)
  view.drawLine(x0=230, y0=105, x1=280, y1=105, color=_rgb_to_hex565(_hex_to_rgb('#ffffff')), thickness=3)
  view.drawLine(x0=40, y0=105, x1=40, y1=160, color=_rgb_to_hex565(_hex_to_rgb('#ffffff')), thickness=3)
  view.drawLine(x0=280, y0=105, x1=280, y1=160, color=_rgb_to_hex565(_hex_to_rgb('#ffffff')), thickness=3)
  view.drawLine(x0=40, y0=160, x1=280, y1=160, color=_rgb_to_hex565(_hex_to_rgb('#ffffff')), thickness=3)
  view.drawRectangle(x=114, y=67, w=33, h=33, color=_rgb_to_hex565(_hex_to_rgb('#ffffff')), thickness=1, fill=True)
  view.drawRectangle(x=173, y=67, w=33, h=33, color=_rgb_to_hex565(_hex_to_rgb('#ffffff')), thickness=1, fill=True)
  view.drawCircle(x=100, y=157, radius=23, color=_rgb_to_hex565(_hex_to_rgb('#ffffff')), thickness=1, fill=True)
  view.drawCircle(x=100, y=157, radius=15, color=_rgb_to_hex565(_hex_to_rgb('#000000')), thickness=1, fill=True)
  view.drawCircle(x=220, y=157, radius=23, color=_rgb_to_hex565(_hex_to_rgb('#ffffff')), thickness=1, fill=True)
  view.drawCircle(x=220, y=157, radius=15, color=_rgb_to_hex565(_hex_to_rgb('#000000')), thickness=1, fill=True)
  view.drawRectangle(x=280, y=140, w=20, h=10, color=_rgb_to_hex565(_hex_to_rgb('#ffffff')), thickness=3, fill=True)
except Exception as e:
  printExcept(e)
```

小畫家：車 （圖片）
![截圖 2024-03-04 下午3.43.40](https://hackmd.io/_uploads/rknkheQ6T.png)
![IMG_2305](https://hackmd.io/_uploads/BJPpz4n66.jpg)

心得：
面板圖案顯示分析是對顯示器性能的綜合評估。主要包括圖案清晰度、色彩準確性、對比度、視角效應、運動模糊、灰階表現和畫面均勻性等方面。評估圖案的清晰度、色彩準確性和對比度，以確保顯示效果良好且真實。同時，檢查視角效應和運動模糊，確保從各個角度觀看時和快速移動時的表現也符合要求。此外，評估灰階表現和畫面均勻性，以確保面板在顯示不同類型的圖案時均勻且無色彩失真。這些分析有助於確定面板是否達到預期性能水平，並提供改進的方向，以提升顯示品質。









登月小車：原地自轉
```javascript=
try:
  def printExcept(e):
    lcd.clear()
    log = str(e)
    sys.print_exception(e)
    data_len, i, colume = 30, 0, 0
    while i < len(log):
      lcd.draw_string(50, 100 + (colume * 20), (log[i : i + data_len] + '\n'), 0x00F8, 0x0000)
      i = i + data_len
      colume = colume + 1

  from ujson import dumps
  from ujson import loads, dumps
  __on_line = {}
  __on_sheet = {}
  __on_monster = {}
  def _onServiceEvent(topic, msg):
    try:
      data = loads(msg)
      payload = data['payload']
      if data['type'] == 'sheet':
        if data['actionType'] == 'responseWrite':
          __on_sheet['write' + payload['url'] + payload['name']](payload)
        elif data['actionType'] == 'responseFeature':
          __on_sheet[payload['url'] + payload['name']](payload)
        elif data['actionType'] == 'responseData':
          _google_sheet_receive_data()
          __on_sheet[payload['cell']] = payload['value']
      elif data['type'] == 'line':
        if data['actionType'] == 'replyToken' or data['actionType'] == 'channelMsg':
          eval('_on_channel_' + payload['channelID'])(payload)
      elif data['type'] == 'monster':
        if data['actionType'] == 'click':
          eval('on_click_' + payload['monster'] + '()')
      elif data['type'] == 'keyboard':
        eval('_' + data['actionType'] + '_' + payload['keycode'])()
      elif data['type'] == 'value_input':
        _on_value_input_cb(payload['value'])
      elif data['type'] == 'speech_to_text':
        receive_speech_to_text(payload['value'])
    except:
      pass
  from time import sleep
  
  try:
    from webai import *
  except:
    pass
  
  mcar.init()
  def _CAR_FORWARD():
    mcar.forward()
  def _CAR_BACK():
    mcar.backward()
  def _CAR_LEFT_FORWARD():
    mcar.move(0, 100)
  def _CAR_LEFT_BACK():
    mcar.move(0, -100)
  def _CAR_RIGHT_FORWARD():
    mcar.move(100, 0)
  def _CAR_RIGHT_BACK():
    mcar.move(-100, 0)
  def _CAR_TURN_RIGHT():
    mcar.right(100)
  def _CAR_TURN_LEFT():
    mcar.left(100)
  def _CAR_STOP():
    mcar.stop()
  def _CAR_KEEP():
    pass
  
  def on_click_green():
    global mcar
    mcar.l_ratio = 1
    mcar.r_ratio = 1
  
  def on_click_red():
    global mcar
    mcar.l_ratio = 0.75
    mcar.r_ratio = 0.75
  
  def on_click_yellow():
    global mcar
    mcar.l_ratio = 0.5
    mcar.r_ratio = 0.5
  
  # RUN USB MODE
  _deviceID = '3eff8f'
  try:
    print(_onServiceEvent)
    from time import sleep
    sleep(1)
    webai.mqtt.sub(topic=_deviceID + '/SERVICE', callback=_onServiceEvent)
  except:
    pass
  
  
  mcar.l_ratio = 1
  mcar.r_ratio = 1
  webai.mqtt.pub(topic=_deviceID + '/SERVICE', msg=dumps({
      "type": 'monster',
      "actionType": 'talk',
      "payload": {
        "msg": '最快'
      },
      "monster": 'green'
    }))
  webai.mqtt.pub(topic=_deviceID + '/SERVICE', msg=dumps({
      "type": 'monster',
      "actionType": 'talk',
      "payload": {
        "msg": '中'
      },
      "monster": 'red'
    }))
  webai.mqtt.pub(topic=_deviceID + '/SERVICE', msg=dumps({
      "type": 'monster',
      "actionType": 'talk',
      "payload": {
        "msg": '很慢'
      },
      "monster": 'blue'
    }))
  
  
  
  while True:
    _CAR_RIGHT_FORWARD()
  
    sleep(0.001)
except Exception as e:
  printExcept(e)
```
登月小車：原地自轉  圖片
![截圖 2024-04-01 下午3.38.58](https://hackmd.io/_uploads/Byps4Juy0.png)

心得：
製作自走小車是一項富有挑戰性但極具樂趣的DIY項目。在製作過程中，首先需要進行設計規劃，包括選擇材料、電子元件和設計外觀尺寸。接著，學習電路連接和編程控制，確保小車的各個部分正確運作。製作過程中需要不斷測試和調試，以確保功能正常且穩定。製作自走小車不僅可以增進機械、電子和編程技能，還能培養解決問題的能力和創造力。完成一個自走小車後，能感受到巨大的成就感和滿足感。這個過程既具有挑戰性，又充滿了樂趣，是一個值得嘗試的精彩項目。









人臉追蹤
```javascript=
try:
  def printExcept(e):
    lcd.clear()
    log = str(e)
    sys.print_exception(e)
    data_len, i, colume = 30, 0, 0
    while i < len(log):
      lcd.draw_string(50, 100 + (colume * 20), (log[i : i + data_len] + '\n'), 0x00F8, 0x0000)
      i = i + data_len
      colume = colume + 1

  from time import sleep
  from webai_blockly import Camera
  from webai import FaceDetect
  from webai_blockly import Lcd
  
  _E7_95_AB_E9_9D_A2 = 0
  _E4_BA_BA_E8_87_89_E8_B3_87_E8_A8_8A = 0
  
  try:
    from webai import *
  except:
    pass
  
  camera = Camera()
  
  FaceDetect.init(0xd40000)
  
  view = Lcd()
  
  def _hex_to_rgb(hex):
    h = hex.lstrip('#')
    return tuple(int(h[i:i+2], 16) for i in (0, 2, 4))
  
  def _rgb_to_hex565(rgb):
    (red, green, blue) = rgb
    hex565 = "0x%0.4X" % ((int(red / 255 * 31) << 11) | (int(green / 255 * 63) << 5) | (int(blue / 255 * 31)))
    board_hex = '0x' + hex565[4:] + hex565[2:4]
    return int(board_hex, 16)
  
  # RUN USB MODE
  _deviceID = 'Web:AI'
  try:
    print(_onServiceEvent)
    from time import sleep
    sleep(1)
    webai.mqtt.sub(topic=_deviceID + '/SERVICE', callback=_onServiceEvent)
  except:
    pass
  
  
  while True:
    _E7_95_AB_E9_9D_A2 = camera.snapshot()
    _E4_BA_BA_E8_87_89_E8_B3_87_E8_A8_8A = FaceDetect.findMax(_E7_95_AB_E9_9D_A2, areaLimit=100, confidenceLimit=0.65, drawRectangle=True)
    if (_E4_BA_BA_E8_87_89_E8_B3_87_E8_A8_8A['x'] if _E4_BA_BA_E8_87_89_E8_B3_87_E8_A8_8A else 0) == 0 and (_E4_BA_BA_E8_87_89_E8_B3_87_E8_A8_8A['y'] if _E4_BA_BA_E8_87_89_E8_B3_87_E8_A8_8A else 0) == 0:
      view.drawString(x=90, y=40, text=b"{var}".format(var='人臉偵測中'), color=_rgb_to_hex565(_hex_to_rgb('#ffffff')), scale=1.6, x_spacing=16, img=_E7_95_AB_E9_9D_A2, display=False)
    else:
      view.drawString(x=110, y=200, text=b"{var}".format(var=(''.join([str(x) for x in ['(', _E4_BA_BA_E8_87_89_E8_B3_87_E8_A8_8A['x'] if _E4_BA_BA_E8_87_89_E8_B3_87_E8_A8_8A else 0, ',', _E4_BA_BA_E8_87_89_E8_B3_87_E8_A8_8A['y'] if _E4_BA_BA_E8_87_89_E8_B3_87_E8_A8_8A else 0, ')']]))), color=_rgb_to_hex565(_hex_to_rgb('#ffffff')), scale=1.5, x_spacing=6, img=_E7_95_AB_E9_9D_A2, display=False)
    view.displayImg(img=_E7_95_AB_E9_9D_A2)
  
    sleep(0.001)
except Exception as e:
  printExcept(e)
```

人臉追蹤 （圖片）
![截圖 2024-04-01 下午3.41.17](https://hackmd.io/_uploads/Sy_0rkukC.png)


心得：
人臉追蹤技術是一項非常有用和引人入勝的技術。通過檢測和追蹤人臉，可以實現許多應用，如人臉識別、攝像頭對焦、人像攝影等。我對這項技術的心得是，它在實際應用中展現了出色的準確性和穩定性。透過相應的算法和模型，能夠追蹤人臉的位置和移動，即使在光線變化或遮擋的情況下也能保持穩定。此外，人臉追蹤技術還可以進一步擴展，如情緒識別、年齡估計等功能，增加了其應用範圍和價值。然而，也要注意到這項技術可能存在的隱私和安全問題，需要適當的措施來保護用戶的個人信息。總的來說，人臉追蹤技術是一項令人興奮的技術，它有著廣泛的應用前景，同時也需要我們保持警覺，確保其使用的合法性和安全性。









nodemcu開發版＋降壓板連接（亮一秒，暗一秒延伸應用）

```javascript=
void setup()
{
  pinMode( D2 , OUTPUT);
}

void loop()
{
  digitalWrite(D2 , HIGH);
  delay( 1000 );
  digitalWrite(D2 , LOW);
  delay( 1000 );
}
```
![](https://hackmd.io/_uploads/Hyffh0dGp.png)
![IMG_3623-2](https://hackmd.io/_uploads/S1gJixE-C.jpg)
![IMG_3618-2](https://hackmd.io/_uploads/SydBoeNWA.jpg)


心得：
這次我們製作出一台能按照特定軌跡巡跡前行的小車子，車子的主體大部分是現成的，程式編碼、軌跡路徑設計…等等，其實還是要自己動腦思考、如何製作出一套循跡小車能讓他順利按照我們所設定的軌跡走，我們前前後後花了蠻多時間和組員一起討論解決方法，一開始小車沒有按照我們所設定軌跡運行，而是自行到處亂跑一通，但是，經過我和組員討論後的結果，車子終於按照我們所設定的指令執行並運作。

整體看來，雖然製作過程沒有想像中順利，但我從過程中學習到很多團隊合作、如何分工、察覺問題的能力，因為這次整體製作過程我覺得相當地不容易、不簡單，因此我也察覺到組內組員分工、大家一起察覺問題能力的重要性，雖然這次自走車執行指令錯誤的答案，我只找出其中一個問題點，但透過大家的集思廣益，我們讓一次又比上一次更進步～
