-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
85 lines (79 loc) · 2.22 KB
/
main.c
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//
// MAX7219 demo program
//
// Copyright (c) 2018 BitBank Software, Inc.
// Written by Larry Bank
// email: [email protected]
// Project started 3/10/2018
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
//
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <max7219.h>
// If you have a 7-segment (n-digit) device, leave this
// otherwise if you have an set of 8x8 arrays, comment this out
#define SEVEN_SEGMENT
int main(int argc, char* argv[])
{
int rc, iPitch;
#ifndef SEVEN_SEGMENT
int i, j;
char cTemp[64];
#endif
uint8_t bImg[40*8];
int iNumControllers, iSegmentMode;
iPitch = 40; // bytes per line of image
memset(bImg, 0, iPitch*8);
#ifdef SEVEN_SEGMENT
iNumControllers = 1;
iSegmentMode = 1;
#else
iNumControllers = 4; // assume 4 x 8x8 array
iSegmentMode = 0;
#endif
// Initialize the library
// num controllers, BCD mode, SPI channel, GPIO pin number for CS
rc = maxInit(iNumControllers, iSegmentMode, 0, 22);
if (rc != 0)
{
printf("Problem initializing max7219\n");
return 0;
}
maxSetIntensity(4);
#ifdef SEVEN_SEGMENT
maxSegmentString("3.1415926");
usleep(4000000);
#else
// Display a message and scroll it to the left (2 iterations)
for (i=0; i<2; i++)
{
sprintf(cTemp,"BitBank MAX7219 library scroll test #%02d 10:05 ", i);
maxDrawString(cTemp, bImg, iPitch, 1); // draw narrow digits
for (j=0; j<iPitch*8; j++)
{
maxSendImage(bImg, iPitch);
maxScrollBitmap(bImg, iPitch, 1);
usleep(40000);
} // for each pixel to scroll
} // for each iteration
#endif // SEVEN_SEGMENT
// Quit library and free resources
maxShutdown();
return 0;
} /* main() */