コミティア151
2025/02/16(日)開催
https://gyazo.com/1fe8a27ed8ec62a1a04379a664f814d1
https://x.com/retoruto_carry/status/1890942609406767358
コード
AIに指示して書かせた
code:java
#include <FastLED.h>
// **ハードウェア設定**
constexpr uint8_t LED_TAPE_PIN = 6; // LEDテープの制御ピン
constexpr uint8_t LED_BULB_PIN = 5; // LED電球の制御ピン
constexpr uint16_t LED_TAPE_COUNT = 75; // LEDテープのLED数
constexpr uint8_t LED_BULB_COUNT = 5; // LED電球のLED数
constexpr uint16_t TOTAL_LED_COUNT = LED_TAPE_COUNT + LED_BULB_COUNT; // 全LED数
// **動作設定**
constexpr uint16_t DEBOUNCE_DELAY = 200; // ボタンのデバウンス時間 (ms)
constexpr uint8_t BRIGHTNESS = 120; // LEDの最大輝度
constexpr uint16_t UPDATE_INTERVAL = 200; // ルーレットの色変更間隔 (ms)
constexpr uint8_t FADE_SPEED = 10; // フェード速度
// **LED 配列**
CRGB ledsTapeLED_TAPE_COUNT; // LEDテープ用
CRGB ledsBulbLED_BULB_COUNT; // LED電球用
// **プリセットカラーリスト**
constexpr CRGB COLOR_LIST[] = {
CRGB(255, 70, 70), // 鮮やかな赤
CRGB(70, 255, 70), // 鮮やかな緑
CRGB(70, 110, 255), // 深い青
CRGB(160, 70, 255), // 鮮やかな紫
CRGB(230, 230, 230) // ソフトホワイト
};
// **状態管理**
volatile bool isRouletteActive = true; // ルーレットの動作状態
CRGB currentColor; // 現在の色 (フェード用)
CRGB targetColor; // 次にフェードする色
uint8_t colorIndex = 0; // 現在のカラーインデックス
bool lastButtonState = HIGH; // 前回のボタン状態
unsigned long lastDebounceTime = 0; // デバウンス用のタイムスタンプ
unsigned long lastUpdateTime = 0; // ルーレット更新のタイムスタンプ
/** LEDの初期化 */
void initializeLEDs() {
FastLED.addLeds<WS2812B, LED_TAPE_PIN, GRB>(ledsTape, LED_TAPE_COUNT); // LEDテープ(GRB)
FastLED.addLeds<WS2812B, LED_BULB_PIN, RGB>(ledsBulb, LED_BULB_COUNT); // LED電球(RGB)
FastLED.setBrightness(BRIGHTNESS);
FastLED.clear();
FastLED.show();
}
/** 初期化処理 */
void setup() {
pinMode(7, INPUT_PULLUP); // ボタンピンの設定 (プルアップ)
Serial.begin(9600);
initializeLEDs(); // LEDの初期化
// 最初のカラーをランダムで設定
targetColor = COLOR_LISTrandom(5);
currentColor = targetColor;
}
/** メインループ */
void loop() {
handleButtonPress(); // ボタン入力の処理
// ルーレットがONのときに一定間隔で色を変更
if (isRouletteActive && millis() - lastUpdateTime > UPDATE_INTERVAL) {
updateRouletteColor();
lastUpdateTime = millis();
}
fadeToTargetColor(); // 色のフェード処理
updateLEDs(); // LEDの更新
}
/** ボタンの押下を検知し、ルーレットのON/OFFを切り替える */
void handleButtonPress() {
bool buttonState = digitalRead(7);
// ボタンが押された瞬間を検知(HIGH → LOW)
if (buttonState == LOW && lastButtonState == HIGH) {
unsigned long currentTime = millis();
if (currentTime - lastDebounceTime > DEBOUNCE_DELAY) {
isRouletteActive = !isRouletteActive; // ルーレットの状態を切り替え
lastDebounceTime = currentTime;
}
}
lastButtonState = buttonState;
}
/** ルーレットの色をランダムに更新する */
void updateRouletteColor() {
uint8_t newColorIndex;
do {
newColorIndex = random(5); // 0~4のランダムカラー
} while (newColorIndex == colorIndex); // 直前と同じ色は選ばない
colorIndex = newColorIndex;
targetColor = COLOR_LISTcolorIndex; // 新しい色を設定
}
/** 目標の色に向かってフェードする */
void fadeToTargetColor() {
currentColor = blend(currentColor, targetColor, FADE_SPEED);
fill_solid(ledsTape, LED_TAPE_COUNT, currentColor);
fill_solid(ledsBulb, LED_BULB_COUNT, currentColor);
}
/** LEDの更新を実行する */
void updateLEDs() {
FastLED.show();
FastLED.delay(1); // **LEDの同期を確保**
}https://gyazo.com/ca0c1a3113a657207d70c90ed34b4927
部品
https://gyazo.com/e739a698d47ce91b91262ca863346b26
https://gyazo.com/a1bac480b4f89d73096e92310ae88aa4
https://gyazo.com/fe4af63376086d1ae024089a4dd84f8f
制作過程
3日で作った
アイデア
https://gyazo.com/24389a4be3807165f6403a5769159592
https://gyazo.com/72bbd0a0818f8ad8173035fb78affa4c
モックアップ
https://gyazo.com/4738b5878f8aed43d49b3c864192f9b1
https://gyazo.com/8a8a2f553188d90acc9a2fb5a8fe9ab6
https://gyazo.com/d0dba995a58ec04282c969f92e69f1d8
100均(セリア)と東急ハンズで部品調達
みんなで工作
https://gyazo.com/8c0e05b9174bb8a8af3d4bf7aff88a71
https://gyazo.com/46bbec83535e37485092a377bac22f15
https://gyazo.com/d541739c44cf1bcdb8ff6e09e8ed3a3f
https://gyazo.com/6edc11659acee1f25240271444e6ca54
https://gyazo.com/400a3fb9803cb7471cfe3cff062a048e
電子工作
https://x.com/retoruto_carry/status/1890763502878327000
https://gyazo.com/7de6a886a58ac5fba24ed83ef0bb4ea3
https://gyazo.com/b02a046a7e9abbb7ab586e6033b50b9f
https://x.com/retoruto_carry/status/1890763502878327000
https://gyazo.com/4aaa10ec20c3838ce65a26a79e337ed2