Code Maintenance & Programming Rules

 This guide outlines essential best practices spanning code style, architectural design, debugging, testing, performance, and portability—all aimed at reducing the long-term cognitive load of code maintenance. 🎨 1. Style Code is written for humans to read, and only incidentally for computers to execute. Variable Naming : Use descriptive names for global variables, and short names for local variables. Precision and Consistency : Use active names for functions (e.g., calculateTotal ). Above all, keep your coding style consistent throughout the project. Structure & Expressions : Use a consistent indentation and brace ( {} ) style to show program structure visually. Use the natural form for expressions. Use parentheses to make the semantics unambiguous. Break up overly complex expressions to keep them clear. Side Effects & Macros : Beware of functions with side effects. Avoid function-like macros; if unavoidable, parenthesize the macro body and arguments carefully. Magic Numbe...

Arduino控制WS2812三色燈條

本文用到的材料為:
  • WS2812B LED 燈條 x 1
  • Arduino UNO x 1
  • 杜邦線公對公 x 3

安裝 FastLED 程式庫
打開Arduino 的程式庫管理工具(草稿碼 ==> 匯入程式庫 ==> 管理程式庫)

搜尋FastLED

安裝好FastLED就可以看到內建的範例程式


Arduino電路

  • LED燈條 5V 接 Arduion 5V
  • LED燈條 GND 接 Arduion GND
  • LED燈條 ID 接 Arduion Pin 5

接好電路後,筆者使用【檔案 ==> 範例 ==> FastLED ==> ColorPalette】來試試看,ColorPalette的Demo影片如下:

因為程式裡設定使用 50 顆 LED,所以此燈條沒有全部亮。

若您覺得文章寫得不錯,請點選文章上的廣告,來支持小編,謝謝。

If you like this post, please click the ads on the blog or buy me a coffee. Thank you very much.

留言

這個網誌中的熱門文章