Added C-implementation for NeoPixel.
Changed a few colors/animation settings for demo purposes. Signed-off-by: Dirk Jahnke <dirk@familie-jahnke.de>
This commit is contained in:
parent
2479cc62fd
commit
b79d6dfd48
|
@ -1,16 +1,16 @@
|
||||||
[
|
[
|
||||||
{"led": 0, "mode": "on", "ticks": 10},
|
{"led": 0, "mode": "on", "ticks": 2},
|
||||||
{"led": 0, "mode": "off", "ticks": 10},
|
{"led": 0, "mode": "off", "ticks": 2},
|
||||||
{"led": 1, "mode": "on", "ticks": 20},
|
{"led": 1, "mode": "on", "ticks": 4},
|
||||||
{"led": 1, "mode": "off", "ticks": 20},
|
{"led": 1, "mode": "off", "ticks": 4},
|
||||||
{"led": 2, "mode": "on", "ticks": 40},
|
{"led": 2, "mode": "on", "ticks": 8},
|
||||||
{"led": 2, "mode": "off", "ticks": 40},
|
{"led": 2, "mode": "off", "ticks": 8},
|
||||||
{"led": 3, "mode": "on", "ticks": 80},
|
{"led": 3, "mode": "on", "ticks": 16},
|
||||||
{"led": 3, "mode": "off", "ticks": 80},
|
{"led": 3, "mode": "off", "ticks": 16},
|
||||||
{"led": 4, "mode": "on", "ticks": 160},
|
{"led": 4, "mode": "on", "ticks": 32},
|
||||||
{"led": 4, "mode": "off", "ticks": 160},
|
{"led": 4, "mode": "off", "ticks": 32},
|
||||||
{"led": 5, "mode": "on", "ticks": 320},
|
{"led": 5, "mode": "on", "ticks": 64},
|
||||||
{"led": 5, "mode": "off", "ticks": 320},
|
{"led": 5, "mode": "off", "ticks": 64},
|
||||||
{"led": 6, "mode": "on", "ticks": 640},
|
{"led": 6, "mode": "on", "ticks": 128},
|
||||||
{"led": 6, "mode": "off", "ticks": 640}
|
{"led": 6, "mode": "off", "ticks": 128}
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
[
|
[
|
||||||
{"name": "off", "red": 0, "green": 0, "blue": 0},
|
{"name": "off", "red": 0, "green": 0, "blue": 0},
|
||||||
{"name": "candle", "red": 50, "green": 40, "blue": 10},
|
{"name": "candle", "red": 30, "green": 15, "blue": 4},
|
||||||
{"name": "red", "red": 50, "green": 5, "blue": 5},
|
{"name": "red", "red": 50, "green": 5, "blue": 5},
|
||||||
{"name": "green", "red": 5, "green": 50, "blue": 5},
|
{"name": "green", "red": 5, "green": 50, "blue": 5},
|
||||||
{"name": "blue", "red": 5, "green": 5, "blue": 50},
|
{"name": "blue", "red": 5, "green": 5, "blue": 80},
|
||||||
{"name": "warmWhite", "red": 80, "green": 80, "blue": 40},
|
{"name": "yellow", "red": 50, "green": 50, "blue": 5},
|
||||||
|
{"name": "violet", "red": 50, "green": 5, "blue": 80},
|
||||||
|
{"name": "warmWhite", "red": 90, "green": 90, "blue": 30},
|
||||||
{"name": "coldWhite", "red": 80, "green": 80, "blue": 100},
|
{"name": "coldWhite", "red": 80, "green": 80, "blue": 100},
|
||||||
{"name": "brightWhite", "red": 255, "green": 255, "blue": 255}
|
{"name": "brightWhite", "red": 255, "green": 255, "blue": 255}
|
||||||
]
|
]
|
||||||
|
|
|
@ -4,6 +4,6 @@
|
||||||
{"level": "EG", "room": "Bad", "id": "eg-bad", "onColor": "red"},
|
{"level": "EG", "room": "Bad", "id": "eg-bad", "onColor": "red"},
|
||||||
{"level": "EG", "room": "Kueche", "id": "eg-kueche", "onColor": "green"},
|
{"level": "EG", "room": "Kueche", "id": "eg-kueche", "onColor": "green"},
|
||||||
{"level": "EG", "room": "Flur", "id": "eg-flur", "onColor": "blue"},
|
{"level": "EG", "room": "Flur", "id": "eg-flur", "onColor": "blue"},
|
||||||
{"level": "OG", "room": "Wohnzimmer", "id": "og-wozi", "onColor": "candle"},
|
{"level": "OG", "room": "Wohnzimmer", "id": "og-wozi", "onColor": "yellow"},
|
||||||
{"level": "OG", "room": "Buero", "id": "og-office", "onColor": "coldWhite"}
|
{"level": "OG", "room": "Buero", "id": "og-office", "onColor": "violet"}
|
||||||
]
|
]
|
||||||
|
|
|
@ -0,0 +1,81 @@
|
||||||
|
#include "mgos_bitbang.h"
|
||||||
|
#include "mgos_gpio.h"
|
||||||
|
#include "mgos_system.h"
|
||||||
|
|
||||||
|
enum NeoPixel_ColorOrder {
|
||||||
|
RGB = 0,
|
||||||
|
GRB = 1,
|
||||||
|
BGR = 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
#define MAX_LEDS 100
|
||||||
|
static uint8_t NeoPixel_pin = 0;
|
||||||
|
static uint8_t NeoPixel_numPixels = 0;
|
||||||
|
static uint8_t NeoPixel_leds[3 * MAX_LEDS];
|
||||||
|
static NeoPixel_ColorOrder NeoPixel_colorOrder = RGB;
|
||||||
|
|
||||||
|
// ## **`NeoPixel_create(pin, numPixels, order)`**
|
||||||
|
// Create and return a NeoPixel strip object. Example:
|
||||||
|
// ```javascript
|
||||||
|
// let pin = 5, numPixels = 16, colorOrder = NeoPixel.GRB;
|
||||||
|
// let strip = NeoPixel.create(pin, numPixels, colorOrder);
|
||||||
|
// strip.setPixel(0 /* pixel */, 12, 34, 56);
|
||||||
|
// strip.show();
|
||||||
|
//
|
||||||
|
// strip.clear();
|
||||||
|
// strip.setPixel(1 /* pixel */, 12, 34, 56);
|
||||||
|
// strip.show();
|
||||||
|
// ```
|
||||||
|
void NeoPixel_create(uint8_t, pin, uint8_t numPixels, enum NeoPixel_ColorOrder order) {
|
||||||
|
mgos_gpio_init();
|
||||||
|
NeoPixel_pin = pin;
|
||||||
|
NeoPixel_numPixels = numPixels;
|
||||||
|
NeoPixel_colorOrder = order;
|
||||||
|
// GPIO.set_mode(pin, GPIO.MODE_OUTPUT);
|
||||||
|
mgos_gpio_set_mode(pin, MGOS_GPIO_MODE_OUTPUT);
|
||||||
|
// GPIO.write(pin, 0); // Keep in reset.
|
||||||
|
mgos_gpio_write(pin, false);
|
||||||
|
NeoPixel_clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ## **`NeoPixel_clear()`**
|
||||||
|
// Clear in-memory values of the pixels.
|
||||||
|
void NeoPixel_clear() {
|
||||||
|
for (int i=0; i<NeoPixel_numPixels * 3; ++i) {
|
||||||
|
NeoPixel_leds[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ## **`NeoPixel_set(i, r, g, b)`**
|
||||||
|
// Set i-th's pixel's RGB value.
|
||||||
|
// Note that this only affects in-memory value of the pixel.
|
||||||
|
void NeoPixel_set(uint8_t pixel, uint8_t red, uint8_t green, uint8_t blue) {
|
||||||
|
uint8_t v0, v1, v2;
|
||||||
|
if (NeoPixel_colorOrder == RGB) {
|
||||||
|
v0 = red; v1 = green; v2 = blue;
|
||||||
|
} else if (NeoPixel_colorOrder == GRB) {
|
||||||
|
v0 = green; v1 = red; v2 = blue;
|
||||||
|
} else if (NeoPixel_colorOrder == BGR) {
|
||||||
|
v0 = blue; v1 = green; v2 = red;
|
||||||
|
} else return;
|
||||||
|
NeoPixel_leds[pixel] = v0;
|
||||||
|
NeoPixel_leds[pixel+1] = v1;
|
||||||
|
NeoPixel_leds[pixel+2] = v2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ## **`NeoPixel_show()`**
|
||||||
|
// Output values of the pixels.
|
||||||
|
void NeoPixel_show() {
|
||||||
|
// GPIO.write(this.pin, 0);
|
||||||
|
mgos_gpio_write(pin, false);
|
||||||
|
// Sys.usleep(60);
|
||||||
|
mgos_usleep(60);
|
||||||
|
// BitBang.write(this.pin, BitBang.DELAY_100NSEC, 3, 8, 8, 6, this.data, this.len);
|
||||||
|
mgos_bitbang_write_bits(NeoPixel_pin, DELAY_100NSEC, 3, 8, 8, 6, NeoPixel_leds, NeoPixel_numPixels);
|
||||||
|
// GPIO.write(this.pin, 0);
|
||||||
|
mgos_gpio_write(pin, false);
|
||||||
|
// Sys.usleep(60);
|
||||||
|
mgos_usleep(60);
|
||||||
|
// GPIO.write(this.pin, 1);
|
||||||
|
mgos_gpio_write(pin, true);
|
||||||
|
}
|
Loading…
Reference in New Issue