Skip to content

Commit 55082c4

Browse files
authored
Create XYmap.h
1 parent 0e9e354 commit 55082c4

1 file changed

Lines changed: 77 additions & 0 deletions

File tree

  • GemmaM0_Band_Jacket/DiscoBandCamp
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Helper functions for a two-dimensional XY matrix of pixels.
2+
// Special credit to Mark Kriegsman for RGB Shades Kickstarter 2014-10-18
3+
// https://www.kickstarter.com/projects/macetech/rgb-led-shades
4+
//
5+
// This special 'XY' code lets you program as a plain matrix.
6+
//
7+
// Writing to and reading from the 'holes' in the layout is
8+
// also allowed; holes retain their data, it's just not displayed.
9+
//
10+
// You can also test to see if you're on or off the layout
11+
// like this
12+
// if( XY(x,y) > LAST_VISIBLE_LED ) { ...off the layout...}
13+
//
14+
// X and Y bounds checking is also included, so it is safe
15+
// to just do this without checking x or y in your code:
16+
// leds[ XY(x,y) ] == CRGB::Red;
17+
// All out of bounds coordinates map to the first hidden pixel.
18+
//
19+
// XY(x,y) takes x and y coordinates and returns an LED index number,
20+
// for use like this: leds[ XY(x,y) ] == CRGB::Red;
21+
22+
23+
// Parameters for width and height
24+
const uint8_t kMatrixWidth = 24;
25+
const uint8_t kMatrixHeight = 8;
26+
const uint8_t kBorderWidth = 2; //for swirly
27+
28+
#define NUM_LEDS (kMatrixWidth * kMatrixHeight)
29+
CRGB leds[ NUM_LEDS ];
30+
31+
// This function will return the right 'led index number' for
32+
// a given set of X and Y coordinates on DiscoBandCamp
33+
// This code, plus the supporting 80-byte table is much smaller
34+
// and much faster than trying to calculate the pixel ID with code.
35+
#define LAST_VISIBLE_LED 119
36+
uint8_t XY( uint8_t x, uint8_t y)
37+
{
38+
// any out of bounds address maps to the first hidden pixel
39+
if( (x >= kMatrixWidth) || (y >= kMatrixHeight) ) {
40+
return (LAST_VISIBLE_LED + 1);
41+
}
42+
43+
// On the visual left of DiscoBandCamp, wearers right
44+
// +------------------------------------------
45+
// | 10 9 8 7 6 5 4 3 2 1 0
46+
// | . 20 19 18 17 16 15 14 13 12 11
47+
// | . . 29 28 27 26 25 24 23 22 21
48+
// | . . . 37 36 35 34 33 32 31 30
49+
// | . . . . 44 43 42 41 40 39 38
50+
// | . . . . . 50 49 48 47 46 45
51+
// | . . . . . . 55 54 53 52 51
52+
// | . . . . . . . 59 58 57 56
53+
54+
//this is how DiscoBandCamp works
55+
const uint8_t JacketTable[] = {
56+
10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 145,
57+
153,60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
58+
120,11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 146,
59+
154,80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 182,
60+
121,127,21, 22, 23, 24, 25, 26, 27, 28, 29, 147,
61+
155,89, 88, 87, 86, 85, 84, 83, 82, 81, 176,183,
62+
122,128,133,30, 31, 32, 33, 34, 35, 36, 37, 148,
63+
156,97, 96, 95, 94, 93, 92, 91, 90, 171,177,184,
64+
123,129,134,135,38, 39, 40, 41, 42, 43, 44, 149,
65+
157,104,103,102,101,100,99, 98, 167,172,178,185,
66+
124,130,134,136,139,45, 46, 47, 48, 49, 50, 150,
67+
158,110,109,108,107,106,105,164,168,173,179,186,
68+
125,131,134,137,140,142,51, 52, 53, 54, 55, 151,
69+
159,115,114,113,112,111,162,165,169,174,180,187,
70+
126,132,134,138,141,143,144,56, 57, 58, 59, 152,
71+
160,119,118,117,116,161,163,166,170,175,181,188,
72+
};
73+
74+
uint8_t i = (y * kMatrixWidth) + x;
75+
uint8_t j = JacketTable[i];
76+
return j;
77+
}

0 commit comments

Comments
 (0)