A Python module to generate Arduino code for BowCar.
Project description
BowCar Module for Python
๐ฐ๐ท ํ๊ตญ์ด (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 andlive/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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca9f1256306bb69bbfa9233223999ead99dc72b17bd58555d24b6231e6a8b86e
|
|
| MD5 |
c4f5d182b18b9106fb97563db3398bd6
|
|
| BLAKE2b-256 |
7cf58fcb2afb4d726532fbab0ff0d5dcd104cff5175a78254c251e558d73de99
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
617713fecf9c9af272fb954f8daefb4e42f41eea1172876bc0769bbe46f12b4d
|
|
| MD5 |
dc0457f0be9e192f60a26695f8a0954f
|
|
| BLAKE2b-256 |
919f29871bcd4259af26a3f606159c23fdff7406d1eafa9c2cebef6a0e82a021
|