Git Product home page Git Product logo

kiss_ws2812b's Introduction

KISS library for WS2812B

Arduino library for WS2812B โ€“ and potentially similar single-wire-based LED pixels โ€“ that is:

  • Small
  • Simple to use
  • Easy to read and understand, thus fix and extend

Only tested with Arduino Uno, but should work with other AVR Arduino boards.

Motivation

There are a lot of Arduino libraries that allow to control single-wire-based LED pixels with Arduino, some of which include:

Most of these libraries, to me, seem a bit overcomplicated and are hard to read. That and a desire to understand Arduino better have led me to create my own library that hopefully doesn't suffer from these issues. All this said, having the libraries mentioned above as a reference helped me a lot when creating this library.

Installation

Probably the simplest way is to import the library using Arduino IDE by following this tutorial.

For terminal users:

  • Run arduino-cli config dump and find user directory.
  • Copy .cpp and .h files from this library to <user_directory>/libraries/KISS_WS2812B folder.

Usage

Start by including the library:

#include <KISS_WS2812B.h>

Use KISS_WS2812B type to control the LED, it consists of:

  • Constructor:

    KISS_WS2812B(byte pin, unsigned int num_leds);

    The port will be derived from pin automatically.

  • Colors structure:

    struct Color {
        byte r, g, b;
    };

    This structure can be used to create a color with where:

    • r member stands for the amount of red in the color.
    • g member stands for the amount of green in the color.
    • b member stands for the amount of blue in the color.

    Any of these members can have values in the range from 0 to 255. The higher the values, the brighter the color, thus Color {0, 0, 0} stands for black and is identical to turning the specific LED off.

    More about the RGB color model here.

  • send_colors function:

    void send_colors(Color colors[]);

    Expects the length of colors array to be num_leds.

TLDR

Here is a simple example:

#include <KISS_WS2812B.h>

#define NUM_LEDS 64

typedef KISS_WS2812B::Color Color;

KISS_WS2812B leds(4, NUM_LEDS);
Color colors[NUM_LEDS];

void setup() {
}

void loop() {
    for (int pos = 0; pos < NUM_LEDS; ++pos) {
        colors[pos - 1] = Color {0, 0, 0};
        colors[pos] = Color {6, 5, 2};
        leds.send_colors(colors);
        delay(100);
    }
    colors[NUM_LEDS - 1] = Color {0, 0, 0};
    leds.send_colors(colors);
}

Contributing and the future of this project

I will abandon this project as it was made with Arduino that I have borrowed from university and I probably don't have a deep enough passion for Arduino to ever buy one for myself. I do, however, plan to accept PRs if there will ever be any. PRs that follow the existing code style and don't use unnecessary macros should be accepted.

Licence

MIT

kiss_ws2812b's People

Contributors

ramojus avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.