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
- Host: GitHub
- URL: https://github.com/t-vk/ledstripsimulator
- Owner: T-vK
- Created: 2016-07-13T23:36:19.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2021-09-13T11:12:24.000Z (over 3 years ago)
- Last Synced: 2025-04-11T06:18:04.608Z (16 days ago)
- Topics: adafruit-neopixel, javascript, led-strip, simpulator, simulator, ws2812b
- Language: HTML
- Homepage: https://t-vk.github.io/LedStripSimulator/
- Size: 344 KB
- Stars: 29
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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
## 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
```