Anpassung auf Adafrout orig bibo

This commit is contained in:
Robert K 2022-12-29 21:03:15 +01:00
parent 816ef0e170
commit 4eaddf66ba
4 changed files with 435 additions and 1476 deletions

View File

@ -15,31 +15,16 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Adapted by Robert Köpferl 2022 to be used on ESP32 -
* no optimisation towards atmel
*
*/
#include "Adafruit_NeoPixel.h"
#include <Adafruit_NeoPixel.h>
#include "notes.h"
#include "pin-names.h"
//DIO
#define GPIO23 23
#define GPIO22 22
#define GPIO18 18 // SPI CLK
#define GPIO19 19
#define GPIO21 21
//ADIO
#define GPIO25 25
#define GPIO26 26
#define GPIO27 27
#define GPIO32 32
#define GPIO33 33
#define GPIO34 34
#define GPIO35 35
#define GPIO36 36
#define GPIO39 39
#define NELEM(x) (sizeof(x) / sizeof((x)[0]))
#define PIN_WSDATA GPIO21 // LED data
@ -84,7 +69,8 @@ Adafruit_NeoPixel one_d = Adafruit_NeoPixel(NPIXELS, PIN_WSDATA, NEO_GRB | NEO_K
#define TIME_TONE_MOVE 25
#define TIME_TONE_SCORE 50
enum {
enum
{
ST_IDLE = 0,
ST_START_L,
ST_START_R,
@ -131,18 +117,74 @@ static uint8_t boosted; // Set if any user boosted until the ball reaches oppos
static uint8_t tonecount; // Interval counter for sound during move
static uint8_t tuneidx; // Index to the running tune
struct tnote {
struct tnote
{
uint8_t note;
uint16_t duration;
};
/* Tone pitch table for 16MHz crystal */
static const uint16_t tone_pitch[NTONE_PITCH] PROGMEM = {
61155, 57722, 54482, 51424, 48538, 45814, 43242, 40815, 38524, 36362 /* == 220Hz */, 34321, 32395,
30577, 28860, 27240, 25711, 24268, 22906, 21620, 20407, 19261, 18180 /* == 440Hz */, 17160, 16197,
15288, 14429, 13619, 12855, 12133, 11452, 10809, 10203, 9630, 9089 /* == 880Hz */, 8579, 8098,
7643, 7214, 6809, 6427, 6066, 5725, 5404, 5101, 4814, 4544, 4289, 4048,
3821, 3606, 3404, 3213, 3032, 2862, 2701, 2550, 2406, 2271, 2144, 2023,
61155,
57722,
54482,
51424,
48538,
45814,
43242,
40815,
38524,
36362 /* == 220Hz */,
34321,
32395,
30577,
28860,
27240,
25711,
24268,
22906,
21620,
20407,
19261,
18180 /* == 440Hz */,
17160,
16197,
15288,
14429,
13619,
12855,
12133,
11452,
10809,
10203,
9630,
9089 /* == 880Hz */,
8579,
8098,
7643,
7214,
6809,
6427,
6066,
5725,
5404,
5101,
4814,
4544,
4289,
4048,
3821,
3606,
3404,
3213,
3032,
2862,
2701,
2550,
2406,
2271,
2144,
2023,
1910,
};
static const tnote tune_win[] PROGMEM = {
@ -181,11 +223,16 @@ void sound_off()
*/
static inline uint8_t button_is_down(uint8_t pin)
{
switch(pin) {
case PIN_BUT_LS: return !debtmr_ls && !bstate_ls;
case PIN_BUT_RS: return !debtmr_rs && !bstate_rs;
case PIN_BUT_LP: return !debtmr_lp && !bstate_lp;
case PIN_BUT_RP: return !debtmr_rp && !bstate_rp;
switch (pin)
{
case PIN_BUT_LS:
return !debtmr_ls && !bstate_ls;
case PIN_BUT_RS:
return !debtmr_rs && !bstate_rs;
case PIN_BUT_LP:
return !debtmr_lp && !bstate_lp;
case PIN_BUT_RP:
return !debtmr_rp && !bstate_rp;
}
return 0;
}
@ -199,16 +246,20 @@ static inline uint8_t button_is_down(uint8_t pin)
*/
static inline uint8_t do_debounce(uint8_t tdiff, uint8_t *bstate, uint8_t *debtmr, uint8_t pin, uint8_t ev)
{
if(0 == *debtmr) {
if (0 == *debtmr)
{
uint8_t state = digitalRead(pin);
if(state != *bstate) {
if (state != *bstate)
{
*debtmr = TIME_DEBOUNCE;
if (!(*bstate = state))
return ev; // Event on High-to-Low transition of input
// else
// return release_event_value
}
} else {
}
else
{
if (*debtmr >= tdiff)
*debtmr -= tdiff;
else
@ -222,7 +273,8 @@ static inline uint8_t do_debounce(uint8_t tdiff, uint8_t *bstate, uint8_t *debtm
*/
static inline uint8_t do_timer(uint8_t tdiff, uint16_t *tmr, uint8_t ev)
{
if(0 != *tmr) {
if (0 != *tmr)
{
if (*tmr >= tdiff)
*tmr -= tdiff; // Timer countdown
else
@ -245,7 +297,8 @@ static inline void set_tone(uint16_t note, uint16_t duration)
// OCR1A = pgm_read_word(&tone_pitch[note-1]);
// TCCR1A = _BV(COM1A0); /* Set toggle output */
// TCNT1 = 0;
} else
}
else
sound_off();
}
@ -254,12 +307,14 @@ static inline void set_tone(uint16_t note, uint16_t duration)
*/
static inline void tune_next()
{
if(tuneidx < NELEM(tune_win)) {
if (tuneidx < NELEM(tune_win))
{
uint16_t n = pgm_read_byte(&tune_win[tuneidx].note);
uint16_t d = pgm_read_word(&tune_win[tuneidx].duration);
set_tone(n, d);
tuneidx++;
} else
}
else
set_tone(0, 0);
}
@ -268,11 +323,13 @@ static inline void tune_next()
*/
static void draw_sides()
{
for(uint8_t i = 0; i < zone_l-1; i++) {
for (uint8_t i = 0; i < zone_l - 1; i++)
{
one_d.setPixelColor(i, 0, 64, 64);
}
one_d.setPixelColor(0, 0, 64, 64);
for(uint8_t i = 0; i < zone_r-1; i++) {
for (uint8_t i = 0; i < zone_r - 1; i++)
{
one_d.setPixelColor(NPIXELS - 1 - i, 0, 64, 64);
}
one_d.setPixelColor(NPIXELS - 1, 0, 64, 64);
@ -284,7 +341,8 @@ static void draw_sides()
static void draw_ball(int8_t dir, uint8_t pos)
{
uint8_t c = 255;
for(uint8_t i = 0; i < 5 && pos >= 0 && pos < NPIXELS; i++) {
for (uint8_t i = 0; i < 5 && pos >= 0 && pos < NPIXELS; i++)
{
one_d.setPixelColor(pos, c, c, 0);
c >>= 1;
pos -= dir;
@ -298,12 +356,15 @@ static void draw_course(uint8_t v)
{
one_d.clear();
draw_sides();
if(v) {
for(uint8_t i = 0; i < points_l; i++) {
if (v)
{
for (uint8_t i = 0; i < points_l; i++)
{
one_d.setPixelColor(NPIXELS / 2 - 1 - (2 * i + 0), v, 0, 0);
one_d.setPixelColor(NPIXELS / 2 - 1 - (2 * i + 1), v, 0, 0);
}
for(uint8_t i = 0; i < points_r; i++) {
for (uint8_t i = 0; i < points_r; i++)
{
one_d.setPixelColor(NPIXELS / 2 + (2 * i + 0), 0, v, 0);
one_d.setPixelColor(NPIXELS / 2 + (2 * i + 1), 0, v, 0);
}
@ -330,20 +391,23 @@ static void animate_idle_init(void)
static void animate_idle(void)
{
switch(ai_state) {
switch (ai_state)
{
case 0:
case 1:
case 2:
case 3:
/* Rainbow pattern */
for(uint8_t i = 0; i < NPIXELS; i++) {
for (uint8_t i = 0; i < NPIXELS; i++)
{
uint16_t h = ai_h + (i << 4);
if (h >= H_STEPS)
h -= H_STEPS;
//*one_d.setPixelColorHsv(i, h, 255, 128);
}
ai_h += H_STEPS / 60;
if(ai_h >= H_STEPS) {
if (ai_h >= H_STEPS)
{
ai_h -= H_STEPS;
ai_pos = 0;
ai_state++;
@ -354,7 +418,8 @@ static void animate_idle(void)
/* Ball left-to-right */
draw_course(0);
draw_ball(1, ai_pos++);
if(ai_pos >= NPIXELS) {
if (ai_pos >= NPIXELS)
{
ai_state++;
}
break;
@ -363,7 +428,8 @@ static void animate_idle(void)
/* Ball right-to-left */
draw_course(0);
draw_ball(-1, --ai_pos);
if(!ai_pos) {
if (!ai_pos)
{
ai_state++;
}
break;
@ -371,11 +437,13 @@ static void animate_idle(void)
case 10:
/* Score blinkenlights */
draw_course(0);
for(uint8_t i = 0; i < ai_pos; i++) {
for (uint8_t i = 0; i < ai_pos; i++)
{
one_d.setPixelColor(NPIXELS / 2 - 1 - i, 255, 0, 0);
one_d.setPixelColor(NPIXELS / 2 + i, 0, 255, 0);
}
if(++ai_pos >= NPIXELS/2) {
if (++ai_pos >= NPIXELS / 2)
{
ai_state++;
ai_pos = 0;
}
@ -384,11 +452,13 @@ static void animate_idle(void)
case 9:
case 11:
draw_course(0);
for(uint8_t i = 0; i < NPIXELS/2-ai_pos; i++) {
for (uint8_t i = 0; i < NPIXELS / 2 - ai_pos; i++)
{
one_d.setPixelColor(NPIXELS / 2 - 1 - i, 255, 0, 0);
one_d.setPixelColor(NPIXELS / 2 + i, 0, 255, 0);
}
if(++ai_pos >= NPIXELS/2) {
if (++ai_pos >= NPIXELS / 2)
{
ai_state++;
ai_pos = 0;
}
@ -415,35 +485,53 @@ static uint8_t animate_win(uint8_t side)
uint32_t clr;
uint8_t pos;
if(side) {
if (side)
{
clr = Adafruit_NeoPixel::Color(0, 255, 0);
pos = NPIXELS / 2;
} else {
}
else
{
clr = Adafruit_NeoPixel::Color(255, 0, 0);
pos = 0;
}
one_d.clear();
if(aw_state < 20) {
if(aw_state & 0x01) {
for(uint8_t i = 0; i < NPIXELS/2; i++) {
if (aw_state < 20)
{
if (aw_state & 0x01)
{
for (uint8_t i = 0; i < NPIXELS / 2; i++)
{
one_d.setPixelColor(pos + i, clr);
}
}
} else if(aw_state < 50) {
for(uint8_t i = 0; i < aw_state - 20; i++) {
}
else if (aw_state < 50)
{
for (uint8_t i = 0; i < aw_state - 20; i++)
{
one_d.setPixelColor(pos + i, clr);
}
} else if(aw_state < 80) {
for(uint8_t i = aw_state - 50; i < NPIXELS/2; i++) {
}
else if (aw_state < 80)
{
for (uint8_t i = aw_state - 50; i < NPIXELS / 2; i++)
{
one_d.setPixelColor(pos + i, clr);
}
} else if(aw_state < 110) {
for(uint8_t i = 0; i < aw_state - 80; i++) {
}
else if (aw_state < 110)
{
for (uint8_t i = 0; i < aw_state - 80; i++)
{
one_d.setPixelColor(NPIXELS / 2 - 1 - i + pos, clr);
}
} else if(aw_state < 140) {
for(uint8_t i = aw_state - 110; i < NPIXELS/2; i++) {
}
else if (aw_state < 140)
{
for (uint8_t i = aw_state - 110; i < NPIXELS / 2; i++)
{
one_d.setPixelColor(NPIXELS / 2 - 1 - i + pos, clr);
}
}
@ -456,7 +544,8 @@ static uint8_t animate_win(uint8_t side)
*/
static uint8_t is_game_state(uint8_t s)
{
switch(s) {
switch (s)
{
case ST_MOVE_LR: // If you press too soon
case ST_MOVE_RL:
case ST_ZONE_R: // In the zone
@ -493,7 +582,8 @@ static inline void speed_to_timer()
static void set_state(uint8_t newstate)
{
/* State exit actions */
switch(thestate) {
switch (thestate)
{
case ST_IDLE:
case ST_WIN_L:
case ST_WIN_R:
@ -545,7 +635,8 @@ static void set_state(uint8_t newstate)
thestate = newstate;
/* State entry actions */
switch(thestate) {
switch (thestate)
{
case ST_IDLE:
boost_l = boost_r = 0;
zone_l = zone_r = ZONE_SIZE;
@ -622,6 +713,7 @@ void setup()
pinMode(PIN_SOUND, OUTPUT);
one_d.begin(); // Setup IO
// Test rob
one_d.setBrightness(60);
one_d.setPixelColor(6, one_d.Color(200, 200, 0));
one_d.show(); // All leds off
@ -650,14 +742,16 @@ void setup()
*/
#define chk_ev(ev) (events & (ev))
/// @brief Main loop
void loop()
{
uint32_t now;
uint8_t tdiff = (now = millis()) - oldtime;
uint32_t now = millis();
uint8_t tdiff = now - oldtime;
uint8_t events = 0;
/* Handle buttons and timers on (just about) every millisecond */
if(tdiff) {
if (tdiff > 0)
{
oldtime = now;
events |= do_debounce(tdiff, &bstate_ls, &debtmr_ls, PIN_BUT_LS, EV_BUT_LS_PRESS);
events |= do_debounce(tdiff, &bstate_rs, &debtmr_rs, PIN_BUT_RS, EV_BUT_RS_PRESS);
@ -670,7 +764,8 @@ void loop()
do_timer(tdiff, &lockout_r, 0);
}
if(is_game_state(thestate)) {
if (is_game_state(thestate))
{
// If the lockout timer is running, squash the button event
if (lockout_l)
events &= ~EV_BUT_LS_PRESS;
@ -684,14 +779,20 @@ void loop()
if (chk_ev(EV_BUT_RS_PRESS))
lockout_r = TIME_LOCKOUT;
switch(thestate) {
switch (thestate)
{
// Nothing to do
case ST_IDLE:
if(chk_ev(EV_BUT_LS_PRESS)) {
if (chk_ev(EV_BUT_LS_PRESS))
{
set_state(ST_START_L);
} else if(chk_ev(EV_BUT_RS_PRESS)) {
}
else if (chk_ev(EV_BUT_RS_PRESS))
{
set_state(ST_START_R);
} else if(chk_ev(EV_TIMER)) {
}
else if (chk_ev(EV_TIMER))
{
timer = TIME_IDLE;
animate_idle();
}
@ -699,11 +800,16 @@ void loop()
// Game is started, waiting for left player to serve the ball
case ST_START_L:
if(chk_ev(EV_BUT_LS_PRESS)) {
if (chk_ev(EV_BUT_LS_PRESS))
{
set_state(ST_MOVE_LR);
} else if(chk_ev(EV_TIMEOUT)) {
}
else if (chk_ev(EV_TIMEOUT))
{
set_state(ST_IDLE);
} else if(chk_ev(EV_TIMER)) {
}
else if (chk_ev(EV_TIMER))
{
timer = TIME_BALL_BLINK;
if (ballblinkstate)
one_d.setPixelColor(ballpos, 255, 128, 0);
@ -716,11 +822,16 @@ void loop()
// Game is started, waiting for right player to serve the ball
case ST_START_R:
if(chk_ev(EV_BUT_RS_PRESS)) {
if (chk_ev(EV_BUT_RS_PRESS))
{
set_state(ST_MOVE_RL);
} else if(chk_ev(EV_TIMEOUT)) {
}
else if (chk_ev(EV_TIMEOUT))
{
set_state(ST_IDLE);
} else if(chk_ev(EV_TIMER)) {
}
else if (chk_ev(EV_TIMER))
{
timer = TIME_BALL_BLINK;
if (ballblinkstate)
one_d.setPixelColor(ballpos, 255, 128, 0);
@ -733,8 +844,10 @@ void loop()
// Ball is moving left-to-right outside the playback zone
case ST_MOVE_LR:
if(chk_ev(EV_TIMER)) {
if(!--tonecount) {
if (chk_ev(EV_TIMER))
{
if (!--tonecount)
{
set_tone(NOTE_G4, TIME_TONE_MOVE);
tonecount = TONE_INTERVAL;
}
@ -750,8 +863,10 @@ void loop()
// Ball is moving right-to-left outside the playback zone
case ST_MOVE_RL:
if(chk_ev(EV_TIMER)) {
if(!--tonecount) {
if (chk_ev(EV_TIMER))
{
if (!--tonecount)
{
set_tone(NOTE_G4, TIME_TONE_MOVE);
tonecount = TONE_INTERVAL;
}
@ -767,24 +882,31 @@ void loop()
// Ball is in the left playback zone, waiting for hit/score
case ST_ZONE_L:
if(chk_ev(EV_BUT_LS_PRESS)) {
if (chk_ev(EV_BUT_LS_PRESS))
{
set_tone(NOTE_G3, TIME_TONE_BOUNCE);
set_state(ST_MOVE_LR);
// Changing speed is done after the state-change's exit/entry action
if(zone_l > 1 && button_is_down(PIN_BUT_LP)) {
if (zone_l > 1 && button_is_down(PIN_BUT_LP))
{
zone_l--;
boosted = 1;
speed_to_timer();
boost_l++;
}
} else if(chk_ev(EV_TIMER)) {
if(!ballpos) {
}
else if (chk_ev(EV_TIMER))
{
if (!ballpos)
{
set_tone(NOTE_C5, TIME_TONE_SCORE);
if (++points_r >= WIN_POINTS)
set_state(ST_WIN_R);
else
set_state(ST_POINT_R);
} else {
}
else
{
speed_to_timer();
ballpos--;
}
@ -796,24 +918,31 @@ void loop()
// Ball is in the right playback zone, waiting for hit/score
case ST_ZONE_R:
if(chk_ev(EV_BUT_RS_PRESS)) {
if (chk_ev(EV_BUT_RS_PRESS))
{
set_tone(NOTE_G3, TIME_TONE_BOUNCE);
set_state(ST_MOVE_RL);
// Changing speed is done after the state-change's exit/entry action
if(zone_r > 1 && button_is_down(PIN_BUT_RP)) {
if (zone_r > 1 && button_is_down(PIN_BUT_RP))
{
zone_r--;
speed_to_timer();
boosted = 1;
boost_r++;
}
} else if(chk_ev(EV_TIMER)) {
if(ballpos == NPIXELS-1) {
}
else if (chk_ev(EV_TIMER))
{
if (ballpos == NPIXELS - 1)
{
set_tone(NOTE_C5, TIME_TONE_SCORE);
if (++points_l >= WIN_POINTS)
set_state(ST_WIN_L);
else
set_state(ST_POINT_L);
} else {
}
else
{
speed_to_timer();
ballpos++;
}
@ -825,15 +954,21 @@ void loop()
// Left player scored, animate point
case ST_POINT_L:
if(chk_ev(EV_BUT_LS_PRESS)) {
if (chk_ev(EV_BUT_LS_PRESS))
{
set_state(ST_RESUME_L);
} else if(chk_ev(EV_TIMER)) {
}
else if (chk_ev(EV_TIMER))
{
timer = TIME_POINT_BLINK;
draw_course(SHOW_HI);
if(!(pointblinkcount & 0x01)) {
if (!(pointblinkcount & 0x01))
{
one_d.setPixelColor(NPIXELS / 2 - 1 - (2 * (points_l - 1) + 0), 0, 0, 0);
one_d.setPixelColor(NPIXELS / 2 - 1 - (2 * (points_l - 1) + 1), 0, 0, 0);
} else {
}
else
{
one_d.setPixelColor(NPIXELS / 2 - 1 - (2 * (points_l - 1) + 0), 255, 0, 0);
one_d.setPixelColor(NPIXELS / 2 - 1 - (2 * (points_l - 1) + 1), 255, 0, 0);
}
@ -845,15 +980,21 @@ void loop()
// Right player scored, animate point
case ST_POINT_R:
if(chk_ev(EV_BUT_RS_PRESS)) {
if (chk_ev(EV_BUT_RS_PRESS))
{
set_state(ST_RESUME_R);
} else if(chk_ev(EV_TIMER)) {
}
else if (chk_ev(EV_TIMER))
{
timer = TIME_POINT_BLINK;
draw_course(SHOW_HI);
if(!(pointblinkcount & 0x01)) {
if (!(pointblinkcount & 0x01))
{
one_d.setPixelColor(NPIXELS / 2 + (2 * (points_r - 1) + 0), 0, 0, 0);
one_d.setPixelColor(NPIXELS / 2 + (2 * (points_r - 1) + 1), 0, 0, 0);
} else {
}
else
{
one_d.setPixelColor(NPIXELS / 2 + (2 * (points_r - 1) + 0), 0, 255, 0);
one_d.setPixelColor(NPIXELS / 2 + (2 * (points_r - 1) + 1), 0, 255, 0);
}
@ -865,10 +1006,13 @@ void loop()
// Left player previously scored and must serve again (or timeout to auto-serve)
case ST_RESUME_L:
if(chk_ev(EV_BUT_LS_PRESS | EV_TIMEOUT)) {
if (chk_ev(EV_BUT_LS_PRESS | EV_TIMEOUT))
{
set_state(ST_MOVE_LR);
set_tone(NOTE_F3, TIME_TONE_SERVE);
} else if(chk_ev(EV_TIMER)) {
}
else if (chk_ev(EV_TIMER))
{
timer = TIME_BALL_BLINK;
if (ballblinkstate)
one_d.setPixelColor(ballpos, 255, 128, 0);
@ -881,10 +1025,13 @@ void loop()
// Right player previously scored and must serve again (or timeout to auto-serve)
case ST_RESUME_R:
if(chk_ev(EV_BUT_RS_PRESS | EV_TIMEOUT)) {
if (chk_ev(EV_BUT_RS_PRESS | EV_TIMEOUT))
{
set_state(ST_MOVE_RL);
set_tone(NOTE_F3, TIME_TONE_SERVE);
} else if(chk_ev(EV_TIMER)) {
}
else if (chk_ev(EV_TIMER))
{
timer = TIME_BALL_BLINK;
if (ballblinkstate)
one_d.setPixelColor(ballpos, 255, 128, 0);
@ -898,15 +1045,21 @@ void loop()
// A player won the game, animate the winning side
case ST_WIN_L:
case ST_WIN_R:
if(chk_ev(EV_TONETIMER)) {
if (chk_ev(EV_TONETIMER))
{
events &= ~EV_TONETIMER; // Remove the event so we don't get messed up with a set_tone(0, 0) below call
tune_next();
}
if(chk_ev(EV_BUT_LS_PRESS)) {
if (chk_ev(EV_BUT_LS_PRESS))
{
set_state(ST_START_L);
} else if(chk_ev(EV_BUT_RS_PRESS)) {
}
else if (chk_ev(EV_BUT_RS_PRESS))
{
set_state(ST_START_R);
} else if(chk_ev(EV_TIMER)) {
}
else if (chk_ev(EV_TIMER))
{
timer = TIME_WIN_BLINK;
if (!animate_win(thestate == ST_WIN_R))
set_state(ST_IDLE);
@ -923,7 +1076,6 @@ void loop()
/* Alternative is to handle it in each and every state */
if (chk_ev(EV_TONETIMER))
set_tone(0, 0);
}
// vim: syn=cpp

File diff suppressed because it is too large Load Diff

View File

@ -1,97 +0,0 @@
/*--------------------------------------------------------------------
This file is part of the Adafruit NeoPixel library.
NeoPixel is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
NeoPixel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with NeoPixel. If not, see
<http://www.gnu.org/licenses/>.
--------------------------------------------------------------------*/
#ifndef ADAFRUIT_NEOPIXEL_H
#define ADAFRUIT_NEOPIXEL_H
#if (ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#include <pins_arduino.h>
#endif
// 'type' flags for LED pixels (third parameter to constructor):
#define NEO_RGB 0x00 // Wired for RGB data order
#define NEO_GRB 0x01 // Wired for GRB data order
#define NEO_BRG 0x04
#define NEO_COLMASK 0x01
#define NEO_KHZ800 0x02 // 800 KHz datastream
#define NEO_SPDMASK 0x02
// Trinket flash space is tight, v1 NeoPixels aren't handled by default.
// Remove the ifndef/endif to add support -- but code will be bigger.
// Conversely, can comment out the #defines to save space on other MCUs.
#ifndef __AVR_ATtiny85__
#define NEO_KHZ400 0x00 // 400 KHz datastream
#endif
class Adafruit_NeoPixel
{
public:
// Constructor: number of LEDs, pin number, LED type
Adafruit_NeoPixel(uint16_t n, uint8_t p = 6, uint8_t t = NEO_GRB + NEO_KHZ800);
~Adafruit_NeoPixel();
void
begin(void),
show(void),
setPin(uint8_t p),
setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b),
setPixelColor(uint16_t n, uint32_t c),
setPixelColorHsv(uint16_t n, uint16_t h, uint8_t s, uint8_t v),
setBrightness(uint8_t),
clear();
uint8_t
*
getPixels(void) const,
getBrightness(void) const;
uint16_t
numPixels(void) const;
static uint32_t
Color(uint8_t r, uint8_t g, uint8_t b);
uint32_t
getPixelColor(uint16_t n) const;
inline bool
canShow(void) { return (micros() - endTime) >= 50L; }
private:
const uint16_t
numLEDs, // Number of RGB LEDs in strip
numBytes; // Size of 'pixels' buffer below
uint8_t
pin, // Output pin number
brightness,
*pixels, // Holds LED color values (3 bytes each)
rOffset, // Index of red byte within each 3-byte pixel
gOffset, // Index of green byte
bOffset; // Index of blue byte
const uint8_t
type; // Pixel flags (400 vs 800 KHz, RGB vs GRB color)
uint32_t
endTime; // Latch timing reference
#ifdef __AVR__
const volatile uint8_t
*port; // Output PORT register
uint8_t
pinMask; // Output PORT bitmask
#endif
};
#endif // ADAFRUIT_NEOPIXEL_H

View File

@ -5,7 +5,7 @@
#define GPIO22 22
#define GPIO18 18 // SPI CLK
#define GPIO19 19
#define GPIO21 21
#define GPIO21 21 // guter LED-out pin
//ADIO
#define GPIO25 25