Skip to main content

A Python module to generate Arduino code for BowCar.

Project description

BowCar Module for Python

ํ•œ๊ตญ์–ด | English


๐Ÿ‡ฐ๐Ÿ‡ท ํ•œ๊ตญ์–ด (Korean)

BowCar๋Š” ํŒŒ์ด์ฌ์„ ์ด์šฉํ•ด ์•„๋‘์ด๋…ธ ๊ธฐ๋ฐ˜์˜ ๋ฐ”์šฐ์นด ํ•˜๋“œ์›จ์–ด๋ฅผ ์ œ์–ดํ•˜๊ณ  ํ•™์Šตํ•˜๊ธฐ ์œ„ํ•œ ๋ชจ๋“ˆ์ž…๋‹ˆ๋‹ค.

๋น ๋ฅธ ์‹œ์ž‘ (Quick Start)

์ด ๋ชจ๋“ˆ์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” Arduino CLI ์„ค์น˜๊ฐ€ ํ•„์ˆ˜์ž…๋‹ˆ๋‹ค.

pip install bowcar

API ๋ ˆํผ๋Ÿฐ์Šค (๋ช…๋ น์–ด ๋ชฉ๋ก)

0. ์‹œ๊ฐ„ ์ œ์–ด

ํ•จ์ˆ˜ ์„ค๋ช…
BowCar.delay(time) time(ms)๋งŒํผ ํ”„๋กœ๊ทธ๋žจ์„ ์ง€์—ฐ์‹œํ‚ต๋‹ˆ๋‹ค.

1. LED ๋ฐ ๋„ค์˜คํ”ฝ์…€ ์ œ์–ด

ํ•จ์ˆ˜ ์„ค๋ช…
BowCar.red(status) ๋นจ๊ฐ„์ƒ‰ LED๋ฅผ ์ œ์–ดํ•ฉ๋‹ˆ๋‹ค. (status: 'on'/'off')
BowCar.blue(status) ํŒŒ๋ž€์ƒ‰ LED๋ฅผ ์ œ์–ดํ•ฉ๋‹ˆ๋‹ค. (status: 'on'/'off')
BowCar.all_light(status) ๋ชจ๋“  LED๋ฅผ ์ œ์–ดํ•ฉ๋‹ˆ๋‹ค. (status: 'on'/'off')
BowCar.neopixel(index, r, g, b) ํŠน์ • ์ธ๋ฑ์Šค(0๋ถ€ํ„ฐ 3๊นŒ์ง€)์˜ ๋„ค์˜คํ”ฝ์…€ ์ƒ‰์ƒ์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. (r,g,b: 0~255)
BowCar.neopixel_all(r, g, b) ๋ชจ๋“  ๋„ค์˜คํ”ฝ์…€์˜ ์ƒ‰์ƒ์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
BowCar.neopixel_clear() ๋ชจ๋“  ๋„ค์˜คํ”ฝ์…€์„ ๋•๋‹ˆ๋‹ค.
BowCar.neopixel_brightness(val) ๋„ค์˜คํ”ฝ์…€์˜ ๋ฐ๊ธฐ๋ฅผ ์กฐ์ ˆํ•ฉ๋‹ˆ๋‹ค. (0~255)

2. ๋ชจํ„ฐ ์ œ์–ด

ํ•จ์ˆ˜ ์„ค๋ช…
BowCar.motor(left, right) ์™ผ์ชฝ/์˜ค๋ฅธ์ชฝ ๋ชจํ„ฐ ์†๋„ ๋ฐ ๋ฐฉํ–ฅ์„ ์ œ์–ดํ•ฉ๋‹ˆ๋‹ค. (-255 ~ 255)
์–‘์ˆ˜: ์ „์ง„, ์Œ์ˆ˜: ํ›„์ง„, 0: ์ •์ง€

3. ์„ผ์„œ ๊ฐ’ ์ฝ๊ธฐ

ํ•จ์ˆ˜ ์„ค๋ช…
BowCar.get_button(button) ๋ฒ„ํŠผ ์ƒํƒœ๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. (button: 'u', 'd', 'l', 'r')
BowCar.is_button_pressed(btn) ๋ฒ„ํŠผ์ด ๋ˆŒ๋ ธ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. (True/False)
BowCar.get_light() ์กฐ๋„ ์„ผ์„œ ๊ฐ’์„ ์ฝ์–ด์˜ต๋‹ˆ๋‹ค. (0~1023)
BowCar.get_sound() ์†Œ๋ฆฌ ์„ผ์„œ ๊ฐ’์„ ์ฝ์–ด์˜ต๋‹ˆ๋‹ค. (0~1023)
BowCar.get_line(dir) ๋ผ์ธ ์„ผ์„œ ๊ฐ’์„ ์ฝ์–ด์˜ต๋‹ˆ๋‹ค. (dir: 'l', 'r')
BowCar.get_distance() ์ดˆ์ŒํŒŒ ์„ผ์„œ ๊ฑฐ๋ฆฌ ๊ฐ’์„ ์ฝ์–ด์˜ต๋‹ˆ๋‹ค. (cm)

4. ์„ผ์„œ ์กฐ๊ฑด ํ™•์ธ

๋ชจ๋“  ์กฐ๊ฑด ํ•จ์ˆ˜๋Š” threshold(์ž„๊ณ„๊ฐ’)์™€ condition(์กฐ๊ฑด: '>', '<')์„ ์ธ์ž๋กœ ๋ฐ›์Šต๋‹ˆ๋‹ค.

ํ•จ์ˆ˜ ์„ค๋ช…
BowCar.check_light(th, cond) ์กฐ๋„ ์„ผ์„œ ์กฐ๊ฑด ํ™•์ธ
BowCar.check_sound(th, cond) ์†Œ๋ฆฌ ์„ผ์„œ ์กฐ๊ฑด ํ™•์ธ
BowCar.check_line(dir, th, cond) ๋ผ์ธ ์„ผ์„œ ์กฐ๊ฑด ํ™•์ธ
BowCar.check_distance(th, cond) ๊ฑฐ๋ฆฌ ์„ผ์„œ ์กฐ๊ฑด ํ™•์ธ

5. ์ฝ”๋“œ ์ƒ์„ฑ ์ œ์–ด๋ฌธ (Upload ๋ชจ๋“œ ์ „์šฉ)

ํ•จ์ˆ˜ ์„ค๋ช…
bfor("์ดˆ๊ธฐํ™”; ์กฐ๊ฑด; ๋ณ€ํ™”") C++ ์Šคํƒ€์ผ์˜ for๋ฌธ์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
bwhile("์กฐ๊ฑด") while๋ฌธ์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
bif("์กฐ๊ฑด"), belif, belse if-else ์กฐ๊ฑด๋ฌธ์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
bbreak() ๋ฐ˜๋ณต๋ฌธ์„ ํƒˆ์ถœํ•ฉ๋‹ˆ๋‹ค.
set_value(type, name, val) ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๊ฑฐ๋‚˜ ๊ฐ’์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
set_array(type, name, values) ๋ฐฐ์—ด์„ ์„ ์–ธํ•˜๊ณ  ์ดˆ๊ธฐํ™”ํ•ฉ๋‹ˆ๋‹ค. (values: list)
set_array_value(name, index, value) ๋ฐฐ์—ด์˜ ํŠน์ • ์ธ๋ฑ์Šค ๊ฐ’์„ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค.

์‚ฌ์šฉ ์˜ˆ์‹œ

๐Ÿ’ก Tip: ๋” ๋งŽ์€ ์˜ˆ์ œ ์ฝ”๋“œ๋Š” examples/ ๋””๋ ‰ํ† ๋ฆฌ ํ•˜์œ„์˜ upload/(ํŒŒ์ด์ฌ ์ฝ”๋“œ๋ฅผ ์•„๋‘์ด๋…ธ์— ์—…๋กœ๋“œ)์™€ live/(์ปดํ“จํ„ฐ์™€ ์ง์ ‘ ์—ฐ๊ฒฐํ•˜์—ฌ ์‹ค์‹œ๊ฐ„ ์ œ์–ด) ํด๋”์—์„œ ํ™•์ธํ•˜๊ณ  ์ง์ ‘ ์‹คํ–‰ํ•ด ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค!

1. ๊ธฐ๋ณธ ์ œ์–ด (LED, ๋ชจํ„ฐ, ์‹œ๊ฐ„)

from bowcar import UploadBowCar

car = UploadBowCar()

# LED ์ผœ๊ธฐ/๋„๊ธฐ
car.red('on')
car.delay(1000)
car.red('off')

# ๋ชจํ„ฐ ์ œ์–ด (์ „์ง„, ํ›„์ง„, ์ •์ง€)
car.motor(100, 100)   # ์ „์ง„
car.delay(1000)
car.motor(-100, -100) # ํ›„์ง„
car.delay(1000)
car.motor(0, 0)       # ์ •์ง€

car.upload_code()

2. ์„ผ์„œ ํ™œ์šฉ ๋ฐ ์กฐ๊ฑด๋ฌธ

from bowcar import UploadBowCar

car = UploadBowCar()

# ๋ฌดํ•œ ๋ฐ˜๋ณต (loop)
with car.bwhile("True"):
    # ๋ฒ„ํŠผ์ด ๋ˆŒ๋ ธ๋Š”์ง€ ํ™•์ธ
    with car.bif("is_button_pressed('u')"):
        car.all_light('on')

    # ์กฐ๋„ ์„ผ์„œ ๊ฐ’์ด 500๋ณด๋‹ค ์ž‘์œผ๋ฉด (์–ด๋‘์šฐ๋ฉด)
    with car.belif("check_light(500, '<')"):
        car.red('on')

    with car.belse():
        car.all_light('off')

car.upload_code()

3. ๋„ค์˜คํ”ฝ์…€ ์ œ์–ด

from bowcar import UploadBowCar

car = UploadBowCar()

# ์ „์ฒด ๋นจ๊ฐ„์ƒ‰ ์„ค์ •
car.neopixel_all(255, 0, 0)
car.delay(1000)

# ๊ฐœ๋ณ„ ์ œ์–ด (0๋ฒˆ: ์ดˆ๋ก, 1๋ฒˆ: ํŒŒ๋ž‘)
car.neopixel(0, 0, 255, 0)
car.neopixel(1, 0, 0, 255)
car.delay(1000)

# ๋ฐ๊ธฐ ์กฐ์ ˆ
car.neopixel_brightness(50) # ๋ฐ๊ธฐ 50์œผ๋กœ ์„ค์ •

# ๋„๊ธฐ
car.neopixel_clear()

car.upload_code()

4. ๋ฐฐ์—ด ์‚ฌ์šฉํ•˜๊ธฐ (Array Usage)

from bowcar import UploadBowCar

car = UploadBowCar()

# 1. ๋ฐฐ์—ด ์„ ์–ธ ๋ฐ ์ดˆ๊ธฐํ™”
# int myArr[] = {10, 20, 30};
car.set_array("int", "myArr", [10, 20, 30])

# 2. ๋ฐฐ์—ด ๊ฐ’ ์‚ฌ์šฉ
# for(int i=0; i<3; i++) { ... }
with car.bfor("int i=0; i<3; i++"):
    # ๋„ค์˜คํ”ฝ์…€ ๋ฐ๊ธฐ๋ฅผ ๋ฐฐ์—ด ๊ฐ’์œผ๋กœ ์„ค์ •
    car.neopixel_brightness("myArr[i]")
    car.delay(1000)

# 3. ๋ฐฐ์—ด ๊ฐ’ ๋ณ€๊ฒฝ
# myArr[0] = 100;
car.set_array_value("myArr", 0, 100)

car.upload_code()

๐Ÿ‡บ๐Ÿ‡ธ English

BowCar is a Python module for controlling and learning with the Arduino-based BowCar hardware.

Quick Start

Arduino CLI is required to use this module.

pip install bowcar

API Reference

0. Time Control

Function Description
BowCar.delay(time) Delays the program for time milliseconds.

1. LED & NeoPixel Control

Function Description
BowCar.red(status) Controls Red LED. (status: 'on'/'off')
BowCar.blue(status) Controls Blue LED. (status: 'on'/'off')
BowCar.all_light(status) Controls all LEDs. (status: 'on'/'off')
BowCar.neopixel(idx, r, g, b) Sets color of specific NeoPixel (idx: from 0 to 3). (0~255)
BowCar.neopixel_all(r, g, b) Sets color of all NeoPixels.
BowCar.neopixel_clear() Turns off all NeoPixels.
BowCar.neopixel_brightness(val) Sets brightness of NeoPixels. (0~255)

2. Motor Control

Function Description
BowCar.motor(left, right) Controls motor speed and direction. (-255 ~ 255)
Positive: Forward, Negative: Backward, 0: Stop

3. Read Sensors

Function Description
BowCar.get_button(button) Gets button status. (button: 'u', 'd', 'l', 'r')
BowCar.is_button_pressed(btn) Checks if button is pressed. (True/False)
BowCar.get_light() Reads light sensor value. (0~1023)
BowCar.get_sound() Reads sound sensor value. (0~1023)
BowCar.get_line(dir) Reads line sensor value. (dir: 'l', 'r')
BowCar.get_distance() Reads ultrasonic sensor distance. (cm)

4. Check Sensor Conditions

All check functions take threshold and condition ('>', '<') as arguments.

Function Description
BowCar.check_light(th, cond) Checks light sensor condition.
BowCar.check_sound(th, cond) Checks sound sensor condition.
BowCar.check_line(dir, th, cond) Checks line sensor condition.
BowCar.check_distance(th, cond) Checks distance sensor condition.

5. Code Generation Control (Upload Mode Only)

Function Description
bfor("init; cond; step") Generates C++ style for loop.
bwhile("condition") Generates while loop.
bif("cond"), belif, belse Generates if-else statements.
bbreak() Generates break statement.
set_value(type, name, val) Declares variable or sets value.
set_array(type, name, values) Declares and initializes an array. (values: list)
set_array_value(name, index, value) Modifies a specific index value of an array.

Usage Examples

๐Ÿ’ก Tip: Check out the examples/ directory (upload/ for standalone execution and live/ for real-time control via PC) for more runnable example scripts!

1. Basic Control (LED, Motor, Time)

from bowcar import UploadBowCar

car = UploadBowCar()

# LED Control
car.red('on')
car.delay(1000)
car.red('off')

# Motor Control (Forward, Backward, Stop)
car.motor(100, 100)   # Forward
car.delay(1000)
car.motor(-100, -100) # Backward
car.delay(1000)
car.motor(0, 0)       # Stop

car.upload_code()

2. Sensors & Conditions

from bowcar import UploadBowCar

car = UploadBowCar()

# Infinite Loop
with car.bwhile("True"):
    # Check if button is pressed
    with car.bif("is_button_pressed('u')"):
        car.all_light('on')

    # Check light sensor (if darker than threshold 500)
    with car.belif("check_light(500, '<')"):
        car.red('on')

    with car.belse():
        car.all_light('off')

car.upload_code()

3. NeoPixel Control

from bowcar import UploadBowCar

car = UploadBowCar()

# Set all to Red
car.neopixel_all(255, 0, 0)
car.delay(1000)

# Individual Control (0: Green, 1: Blue)
car.neopixel(0, 0, 255, 0)
car.neopixel(1, 0, 0, 255)
car.delay(1000)

# Set Brightness
car.neopixel_brightness(50)

# Clear
car.neopixel_clear()

car.upload_code()

4. Using Arrays

from bowcar import UploadBowCar

car = UploadBowCar()

# 1. Declare and initialize array
# int myArr[] = {10, 20, 30};
car.set_array("int", "myArr", [10, 20, 30])

# 2. Use array values
# for(int i=0; i<3; i++) { ... }
with car.bfor("int i=0; i<3; i++"):
    # Set NeoPixel brightness using array value
    car.neopixel_brightness("myArr[i]")
    car.delay(1000)

# 3. Modify array value
# myArr[0] = 100;
car.set_array_value("myArr", 0, 100)

car.upload_code()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bowcar-1.3.2.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bowcar-1.3.2-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file bowcar-1.3.2.tar.gz.

File metadata

  • Download URL: bowcar-1.3.2.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for bowcar-1.3.2.tar.gz
Algorithm Hash digest
SHA256 ca9f1256306bb69bbfa9233223999ead99dc72b17bd58555d24b6231e6a8b86e
MD5 c4f5d182b18b9106fb97563db3398bd6
BLAKE2b-256 7cf58fcb2afb4d726532fbab0ff0d5dcd104cff5175a78254c251e558d73de99

See more details on using hashes here.

File details

Details for the file bowcar-1.3.2-py3-none-any.whl.

File metadata

  • Download URL: bowcar-1.3.2-py3-none-any.whl
  • Upload date:
  • Size: 17.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for bowcar-1.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 617713fecf9c9af272fb954f8daefb4e42f41eea1172876bc0769bbe46f12b4d
MD5 dc0457f0be9e192f60a26695f8a0954f
BLAKE2b-256 919f29871bcd4259af26a3f606159c23fdff7406d1eafa9c2cebef6a0e82a021

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page