blob: b711a6b6acead22accaa96fdfa9b8a9f8e96c148 (
plain)
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
|
#include <math.h>
#include "libleds.h"
#include "img_mono.xbm"
static char const PORT = 0;
static char const PINS = 1<<7;
char const is_active(unsigned int const n)
{
/*
* The first led is in the top left corner.
* After that it goes down the column, then up the next and so on.
*
* This means all columns with an even index count down.
* Those with an odd index count up.
*
*
* With a height of 8 the led numbers would look like this:
*
* 00 0F 10 1F 20 ...
* 01 0E 11 1E 21 ...
* 02 0D 12 1D ...
* 03 0C 13 1C ...
* 04 0B 14 1B ...
* 05 0A 15 1A ...
* 06 09 16 19 ...
* 07 08 17 18 ...
*/
unsigned int const bytes_per_row = ceil(img_width / 8.0);
unsigned int col = n / img_height;
unsigned int row = n % img_height;
if (col % 2)
row = img_height - 1 - row;
// calculate byte to access
unsigned int byte = row * bytes_per_row;
byte += col / 8;
unsigned char data = img_bits[byte];
unsigned char mask = 1<<(col % 8);
return data & mask;
}
void led_main()
{
const int length = img_width * img_height;
struct led_color pixel[length];
for (unsigned int i = 0; i < length; i++) {
unsigned char out = is_active(i) ? 0xFF : 0x00;
pixel[i] = (struct led_color){out, out, out};
}
for (unsigned int i = 0; i < length; i++)
led_write_rgb(PORT, PINS, pixel[i]);
}
|