Swiftでレゴを動かそう!

7.6K Views

March 24, 24

スライド概要

try! Swift Tokyo 2024のワークショップ「Swiftでレゴを動かそう!」後半の資料です。

profile-image

SwiftとLEGOとBluetooth LEが好きなプログラマ

シェア

またはPlayer版

埋め込む »CMSなどでJSが使えない場合

関連スライド

各ページのテキスト
1.

Swiftでレゴを動かそう! Getting started with controlling LEGO using Swift Group Work Part

2.

自己紹介 Self Introduction 大庭 慎一郎(Shinichiro Oba) ID: @ooba or @bricklife The 1st iOS App Developer at Mercari LEGO Lover

3.

僕が書いたレゴ プログラミング本 LEGO Programming Books I Wrote

4.

今日やること Today's Agenda Core Bluetoothの基礎を学ぶ Learning the Basics of Core Bluetooth LEGO Wireless Protocolでレゴを動かす Controlling LEGO with LEGO Wireless Protocol 自分のモデルを作って遊ぶ! Create and Play with Your Own Models!

5.

IDE Swift Playgrounds Xcode

6.

学習に使うプロジェクト Project for Learning https://github.com/bricklife/LEGO-CoreBluetooth-Programming-Workshop/ releases/tag/starting-point

7.

レゴ エデュケーション SPIKE ベーシックセット LEGO Education SPIKE Essential Set

8.

Powered by 株式会社アフレル様から無償貸与

9.

Unbox!

10.

ハブ Hub マイコン内蔵 Microcontroller Embedded Bluetooth LEで接続可能 Connectable via Bluetooth LE 加速度センサーやジャイロセンサーを内蔵 with Accelerometer and Gyroscope Sensors

11.

ハブがBluetooth LEのペリフェラルになる Hub acts as a Bluetooth LE Peripheral Service "Turn Motor" Write UUID: 00001623-1212-EFDE-1623-785FEABCD123 Characteristic UUID: 00001624-1212-EFDE-1623-785FEABCD123 Notify "Detected Red" Peripheral

12.

モーター、マトリクスライト、カラーセンサー Motor, Color Matrix Light, and Color Sensor

14.

そのほかのパーツ Other Parts

15.

めちゃめちゃ便利なパーツ The Most Useful Part

16.

Core Bluetoothの世界へ Into the World of Core Bluetooth

17.

Core Bluetoothの世界 The World of Core Bluetooth Service UUID: 00001623-1212-EFDE-1623-785FEABCD123 Write Characteristic UUID: 00001624-1212-EFDE-1623-785FEABCD123 Notify Central Peripheral

18.

Core Bluetoothの世界 The World of Core Bluetooth CBService CBUUID: 00001623-1212-EFDE-1623-785FEABCD123 Write CBCharacteristic CBUUID: 00001624-1212-EFDE-1623-785FEABCD123 Notify CBCentralManager CBPeripheral

19.

Write

20.

Read

21.

Notify

22.

CBPeripheralとCBCharacteristicの取得方法 How to Retrieve CBPeripheral and CBCharacteristic 0. Advertising (from Peripheral) 1. Scan 2. Connect 3. Discover Service 4. Discover Characteristic

23.

0. Advertising (from Peripheral)

24.

1. Scan

25.

1. Scan Response

26.

2. Connect

27.

2. Connect Response

28.

3. Discover Service

29.

3. Discover Service Response

30.

4. Discover Characteristic

31.

4. Discover Characteristic Response

32.

モーターを回してみよう! Let's Turn Motor!

33.

5. Write

34.

モーターAのパワーを50%にするメッセージ Message to Set Motor A's Power to 50% [0x08, 0x00, 0x81, 0x00, 0x11, 0x51, 0x00, 0x32] どこが「50」かわかりますか? Where does '50' mean? パワーを「0」にしてみましょう Let's set the power to '0'

35.

モーターAのパワーを50%にするメッセージ Message to Set Motor A's Power to 50% [0x08, 0x00, 0x81, 0x00, 0x11, 0x51, 0x00, 0x32] Port: A (0x00) Power: 50%

36.

モーターAを360度回すメッセージ Message to Rotate Motor A by 360 degrees [0x0e, 0x00, 0x81, 0x00, 0x11, 0x0b, 0x68, 0x01, 0x00, 0x00, 0x32, 0x64, 0x7f, 0x03] 360

37.

6. Enable Notification

38.

6. Notify

39.

カラーセンサーを使ってみる Try using the Color Sensor [0x0a, 0x00, 0x41, 0x01, 0x05, 0x01, 0x00, 0x00, 0x00, 0x01] Port: B (0x01) Mode: 5

41.

LEGO Wireless Protocol https://lego.github.io/lego-ble-wireless-protocol-docs/

43.

LWPKit https://github.com/bricklife/LWPKit/ Swift Package for LEGO Wireless Protocol Decoding and Encoding

44.

Build Time!

45.

LEGO Wireless Protocol対応パーツ LEGO Wireless Protocol Compatible Parts

46.

ポートありパーツ Parts with Ports WeDo 2.0 2006 2013 2016 2017 2018 SPIKE Prime 2019 SPIKE Essential 2021 2020 2019

47.

ポートに接続できるパーツ Parts that can be connected to Ports

48.

ポートなし Parts without Ports 2020 2018 2021 2018 2022

49.

LEGO Wireless Protocol対応セット LEGO Wireless Protocol Compatible Sets

50.

Move Hub

51.

Hub

52.

Hub

53.

Technic Hub

54.

Technic Hub x2

55.

Duplo Train

56.

LEGO Mario

57.

レゴ エデュケーション SPIKE ベーシック LEGO Education SPIKE Essential

58.

Presentation Time

59.

Thank you!