An open API service indexing awesome lists of open source software.

https://github.com/t-vk/ledstripsimulator

Simulates an LED strip and allows very NeoPixel-like access
https://github.com/t-vk/ledstripsimulator

adafruit-neopixel javascript led-strip simpulator simulator ws2812b

Last synced: 16 days ago
JSON representation

Simulates an LED strip and allows very NeoPixel-like access

Awesome Lists containing this project

README

        

# LedStripSimulator
Simulates an LED strip and allows very NeoPixel-like access

## Ready to use online simulator
[Click here for a ready-to-use online simulator](https://t-vk.github.io/LedStripSimulator/)

## Screenshot
![Screenshot](screenshot.jpg)

## Requirements
Your browser needs:
- HTML: HTML5
- CSS: CSS3
- JavaScript: ECMAScript6
The newest version of Firefox/Chrome/Opera/Safari/Edge should work fine.

## Usage
You'll wirte your code in JavaScript. But the syntax of original Adafruit_NeoPixel c++ class is simlulated as good as possible.
Your original C++ code could for example translate like this:
*C++*
``` c++
#define PIN 10;
#define NUM_LEDS = 60;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
strip.begin();
strip.show();

strip.setPixelColor(0, Color(255,0,0));
strip.show();
}
```
*JavaScript*
``` javascript
var PIN = 10;
var NUM_LEDS = 60;
var strip = new Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);

function setup() {
strip.begin();
strip.show();

strip.setPixelColor(0, Color(255,0,0));
strip.show();
}
```

### Ported Arduino functions/callbacks
I implemented the functions `millis()`, `micros()`, `delay()` as well as the callback fucntions `setup()` and `loop()`.
About `delay()`: Use it wisely. It will freeze it's thread while it is running. To prevent UI or whole browser freezing, run your code in a new thread (worker).

# DIY
## Basic setup without the editor and jquery/bootstrap dependency
- Create a new folder
- copy Adafruit_NeoPixel.js into the folder
- copy Adafruit_NeoPixel.css into the folder
- create a new .html file with the following contents:
``` html




//Your code goes here
//For example:
//function setup() {
//
//}
//function loop() {
//
//}


```

#### Full example
The BasicExample.html file contains an example.
``` html




//USER
const PIN = 10
const NUM_LEDS = 60
const BRIGHTNESS = 255

//ws2812b, arduino pro mini
var strip = new Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800)

function setup() {
strip.setBrightness(BRIGHTNESS)
strip.begin()
strip.show()
}

var red = strip.Color(255, 0, 0)
var yellow = strip.Color(255, 255, 0)
var blue = strip.Color(0, 0, 255)
var colors = [red,yellow,blue]
var currentColorIndex = 0

function loop() {
var animationDone = colorWipe(colors[currentColorIndex])
if (animationDone)
currentColorIndex = (currentColorIndex>=colors.length-1 ? 0 : currentColorIndex+1)
}


function colorWipe(color) {
var now = millis()
if (now > colorWipe.lastUpdate+colorWipe.delay) {
strip.setPixelColor(colorWipe.currentLed, color)
strip.show()
colorWipe.currentLed = colorWipe.currentLed>=strip.numPixels()-1 ? 0 : colorWipe.currentLed+1
colorWipe.lastUpdate = now

if (colorWipe.currentLed === 0)
return true;
}
return false
} //c++-like static variables for this fucntion:
colorWipe.delay = 10
colorWipe.lastUpdate = 0
colorWipe.currentLed = 0

```