Giter Club home page Giter Club logo

tinyws2812b's Introduction

TinyWS2812B

by David Augustat

TinyWS2812B is a minimalist and easy to use Arduino library for controlling WS2812B addressable LEDs.

It works with all Atmega328-based Arduino microcontrollers including Arduino Uno, Nano and Pro Mini (5V).
The library is extremely small: It uses less than 1 kb of your Arduino's program storage space, which is about 3%.

Download the Library:

DOWNLOAD LIBRARY HERE
Download this ZIP file and install it using the Arduino IDE:
Sketch -> Include Library -> Add .ZIP Library... -> Select this ZIP file

How to use the Library:

Include the library in your sketch:

#include <TinyWS2812B.h>

Create an instance of TinyWS2812B:

TinyWS2812B myLeds(int dataPin, int numberOfLEDs);

//Example: Use Pin 2 as the data pin for the WS2812B-LEDs and use 20 LEDs
TinyWS2812B myLEDs(2, 20);

Set the color of an LED:
Position starting with "0" as the position of the first LED.
Color values are from 0 (off) to 255 (full brightness).

myLEDs.setColor(int position, byte red, byte green, byte blue);

//Example: Set the color of the fifth LED to red:
myLEDs.setColor(4, 255, 0, 0);

Update the LEDs:
Has to be called to apply the changes to the LEDs.

myLEDs.updateLEDs();

Example: Set all LEDs to green

// include the library:
#include <TinyWS2812B.h>

// create an instance:
TinyWS2812B myLEDs(4, 20);

void setup() {
  // use a for-loop to cycle through every position of the LED string:
  for(int pos = 0; pos<20; pos++){
    // set the color of the LED at the current position to green:
    myLEDs.setColor(pos, 0, 255, 0);
  }
  // update the LEDs:
  myLEDs.updateLeds();
}

void loop() {
  //nothing here
}

Example: Chasing LED Animation

//include the library:
#include <TinyWS2812B.h>

// store number of LEDs in a variable:
int numberOfLEDs = 20;
// create an instance of TinyWS2812B:
TinyWS2812B myLEDs(2, numberOfLEDs);

void setup() {
 //nothing here
}

void loop() {
  // use a for-loop to cycle through every LED:
  for(int pos = 0; pos<numberOfLEDs; pos++){
    // turn the previous LED off and set the current LED to white:
    myLEDs.setColor(pos-1, 0, 0, 0);
    myLEDs.setColor(pos, 255, 255, 255);
    // update the LEDs:
    myLEDs.updateLeds();
    // wait 100ms until next shift of the LED:
    delay(100);
  }
  // turn the last LED off at the end:
  myLEDs.setColor(numberOfLEDs-1, 0, 0, 0);
}

Licensing

This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.

When you use or redistribute this library, you MUST credit me using following link: https://github.com/derAndroidPro/TinyWS2812B

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.