-
Notifications
You must be signed in to change notification settings - Fork 0
/
CGrid.h
58 lines (47 loc) · 1.44 KB
/
CGrid.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once
#include <Adafruit_NeoPixel.h>
#include "CSequencer.h"
#define PIN 10
static uint8_t GridRows = 4;
static uint8_t GridColumns = 8;
class CGrid
{
private:
const CSequencer& _sequencer;
Adafruit_NeoPixel _strip = Adafruit_NeoPixel(32, PIN, NEO_GRB + NEO_KHZ800);
public:
CGrid(const CSequencer& sequencer) : _sequencer(sequencer)
{
}
void Initialize()
{
_strip.begin();
_strip.show();
_strip.setBrightness(31);
}
void Render()
{
auto on = _strip.Color(255, 255, 255);
auto off = _strip.Color(0, 0, 0);
auto position = _sequencer.GetPosition();
for (uint8_t row = 0; row < GridRows; ++row)
{
auto lane = _sequencer.GetZone(0)->GetLane(row);
auto index = lane->CalculateStepIndex(position);
auto offset = row * GridColumns;
for (uint8_t column = 0; column < GridColumns; ++column)
{
auto coordinate = offset + column;
if (column == index)
{
_strip.setPixelColor(coordinate, on);
}
else
{
_strip.setPixelColor(coordinate, off);
}
}
}
_strip.show();
}
};