6
6
Ketturi 2016
7
7
*/
8
8
9
- #include < pgmspace.h>
10
- #include < SPI.h>
11
9
#include " bitmap.h" // Image data from kukkaconvert.exe by wuffe goes here, put in PROGMEM to save ram
12
10
#include " hardware.h" // Hardware definitions
11
+ #include < pgmspace.h>
12
+ #include < SPI.h>
13
13
14
14
// ESP8266 stuff
15
15
#include < ESP8266WiFi.h>
@@ -28,47 +28,60 @@ byte pwm = 50; //sets initial brightness
28
28
const unsigned int rowOnTime = 1000 ; // how long one row is lit, uS
29
29
const unsigned int framerate = 5000 ; // milliseconds between frames, slows display down to readable speed
30
30
unsigned long previousMillis = 0 ;
31
- int frame = 0 ;
31
+ unsigned int frame = 0 ;
32
32
33
- void setup () { // Set pins to outputs and inits other stuff
34
- pinMode (16 , SPECIAL); // Set GPIO16 to default function, controls reset
35
-
36
- // Important, do not remove these, or updating over wifi wont work!
37
- // *******************************
38
- setWiFi (); // Start WiFiManager
39
- otaUpdate (); // Enable ota updates
40
- // *******************************
33
+ void selectRow (byte RowAdrs) { // Selects which row gets illuminated, 4Bit address
34
+ for (int b = 0 ; b < 4 ; b++) {
35
+ if ((0x01 & RowAdrs) < 0x01 )
36
+ digitalWrite (rowAdrsPin[b], LOW);
37
+ else
38
+ digitalWrite (rowAdrsPin[b], HIGH);
39
+ RowAdrs >>= 1 ;
40
+ }
41
+ }
41
42
42
- pinMode (0 , FUNCTION_0);
43
- pinMode (1 , FUNCTION_3);
44
- pinMode (2 , FUNCTION_0);
45
- pinMode (3 , FUNCTION_3);
46
- pinMode (4 , FUNCTION_0);
47
- pinMode (5 , FUNCTION_0);
48
- pinMode (13 , FUNCTION_2);
49
- pinMode (14 , FUNCTION_2);
50
- pinMode (15 , FUNCTION_2);
43
+ void shiftOut32 (unsigned long input) { // 32Bit shift out with HW SPI, sends data in 8bit pieces to shift register
44
+ SPI.beginTransaction (SPISettings (SPISPEED, LSBFIRST, SPI_MODE0)); // 25Mhz, LSBFIRST, clock polarity and phase
45
+ SPI.transfer (input >> 0 );
46
+ SPI.transfer (input >> 8 );
47
+ SPI.transfer (input >> 16 );
48
+ SPI.transfer (input >> 24 );
49
+ SPI.endTransaction ();
50
+ }
51
51
52
- pinMode (latchPin, OUTPUT);
53
- pinMode (enablePin, OUTPUT);
54
- digitalWrite (enablePin, HIGH);
52
+ // getRowWord by wuffe, converts bitmap array to display lines
53
+ const unsigned long getRowWord (const unsigned int x, unsigned const int y, const unsigned int width, const unsigned long * data) {
54
+ // NB: x's remainders may be slow to calculate, if compiler can't deduce beforehand
55
+ // what value "width" will get when function is called.
56
+ const unsigned int xa = x % width;
57
+ const unsigned int xb = (x + 32 ) % width;
58
+ const unsigned int ya = y % 12 ;
59
+ const unsigned int shift = xa % 32 ;
55
60
56
- for (int i = 0 ; i < 4 ; i++) {
57
- pinMode (rowAdrsPin[i], OUTPUT);
58
- }
61
+ const unsigned int aPtr = ya + (xa / 32 ) * 12 ;
62
+ const unsigned int bPtr = ya + (xb / 32 ) * 12 ;
59
63
60
- analogWrite (pwmPin, pwm); // Set initial brightness
61
- SPI.begin ();
62
- Serial.setDebugOutput (false ); // Stop all serial communication as serial pins are used for display
63
- Serial.end ();
64
+ // Conditional to prevent 32-bit variable being shifted with 32 (not defined, not in C anyhow).
65
+ return shift == 0 ? data[aPtr] : ((data[aPtr] << shift) | (data[bPtr] >> (32 - shift)));
66
+ // return shift == 0 ? pgm_read_dword(data + aPtr) : ((pgm_read_dword(data + aPtr) << shift) | (pgm_read_dword(data + bPtr) >> (bits - shift)));
64
67
}
65
68
66
- void loop () { // loops constantly
67
- ArduinoOTA.handle (); // Checks for incoming update, please don't remove!
68
- refreshDisplay ();
69
+ void sendColumn (int col, byte row) { // Toggles control lines and outputs display data.
70
+ digitalWrite (latchPin, LOW);
71
+ shiftOut32 (getRowWord (col + 96 , row, imageWidth, imageData)); // last panel
72
+ shiftOut32 (getRowWord (col + 64 , row, imageWidth, imageData)); // third panel
73
+ shiftOut32 (getRowWord (col + 32 , row, imageWidth, imageData)); // second panel
74
+ shiftOut32 (getRowWord (col , row, imageWidth, imageData)); // first panel
75
+ digitalWrite (latchPin, HIGH);
76
+
77
+ digitalWrite (enablePin, LOW);
78
+ /* Delay for leds being enabled, affects how bright display is.
79
+ ESP8266 does WiFi and TCP/IP task during delays*/
80
+ delayMicroseconds (rowOnTime);
81
+ digitalWrite (enablePin, HIGH);
69
82
}
70
83
71
- void refreshDisplay () { // Updates whole display
84
+ void refreshDisplay () {
72
85
#if (ANIMATION) // shows single frames crating animation
73
86
unsigned long currentMillis = millis ();
74
87
if (currentMillis - previousMillis >= framerate) { // crude timer for frame rate.
@@ -101,57 +114,6 @@ void refreshDisplay() { //Updates whole display
101
114
#endif
102
115
}
103
116
104
- void sendColumn (int col, byte row) { // Toggles control lines and outputs display data.
105
- digitalWrite (latchPin, LOW);
106
- shiftOut32 (getRowWord (col + 96 , row, imageWidth, imageData)); // last panel
107
- shiftOut32 (getRowWord (col + 64 , row, imageWidth, imageData)); // third panel
108
- shiftOut32 (getRowWord (col + 32 , row, imageWidth, imageData)); // second panel
109
- shiftOut32 (getRowWord (col , row, imageWidth, imageData)); // first panel
110
- digitalWrite (latchPin, HIGH);
111
-
112
- digitalWrite (enablePin, LOW);
113
- /* Delay for leds being enabled, affects how bright display is.
114
- ESP8266 does WiFi and TCP/IP task during delays*/
115
- delayMicroseconds (rowOnTime);
116
- digitalWrite (enablePin, HIGH);
117
- }
118
-
119
- void selectRow (byte RowAdrs) { // Selects which row gets illuminated, 4Bit address
120
- for (int b = 0 ; b < 4 ; b++) {
121
- if ((0x01 & RowAdrs) < 0x01 )
122
- digitalWrite (rowAdrsPin[b], LOW);
123
- else
124
- digitalWrite (rowAdrsPin[b], HIGH);
125
- multiRow >>= 1 ;
126
- }
127
- }
128
-
129
- void shiftOut32 (unsigned long input) { // 32Bit shift out with HW SPI, sends data in 8bit pieces to shift register
130
- SPI.beginTransaction (SPISettings (SPISPEED, LSBFIRST, SPI_MODE0)); // 25Mhz, LSBFIRST, clock polarity and phase
131
- SPI.transfer (input >> 0 );
132
- SPI.transfer (input >> 8 );
133
- SPI.transfer (input >> 16 );
134
- SPI.transfer (input >> 24 );
135
- SPI.endTransaction ();
136
- }
137
-
138
- // getRowWord by wuffe, converts bitmap array to display lines
139
- const unsigned long getRowWord (const unsigned int x, unsigned const int y, const unsigned int width, const unsigned long * data) {
140
- // NB: x's remainders may be slow to calculate, if compiler can't deduce beforehand
141
- // what value "width" will get when function is called.
142
- const unsigned int xa = x % width;
143
- const unsigned int xb = (x + 32 ) % width;
144
- const unsigned int ya = y % 12 ;
145
- const unsigned int shift = xa % 32 ;
146
-
147
- const unsigned int aPtr = ya + (xa / 32 ) * 12 ;
148
- const unsigned int bPtr = ya + (xb / 32 ) * 12 ;
149
-
150
- // Conditional to prevent 32-bit variable being shifted with 32 (not defined, not in C anyhow).
151
- return shift == 0 ? data[aPtr] : ((data[aPtr] << shift) | (data[bPtr] >> (32 - shift)));
152
- // return shift == 0 ? pgm_read_dword(data + aPtr) : ((pgm_read_dword(data + aPtr) << shift) | (pgm_read_dword(data + bPtr) >> (bits - shift)));
153
- }
154
-
155
117
void otaUpdate () { // Handless over the air updating from Arduino IDE
156
118
WiFi.mode (WIFI_STA);
157
119
WiFi.begin ();
@@ -164,4 +126,42 @@ void setWiFi() { //If no wifi AP is found, create one, and serve user a config p
164
126
WiFiManager wifiManager;
165
127
wifiManager.setTimeout (180 ); // In 3 minutes continue normaly even if no wlan detected.
166
128
wifiManager.autoConnect (" FoxMatrix" ); // Start WiFiManager with spesified AP name.
129
+ }
130
+
131
+ void setup () { // Set pins to outputs and inits other stuff
132
+ pinMode (16 , SPECIAL); // Set GPIO16 to default function, controls reset
133
+
134
+ // Important, do not remove these, or updating over wifi wont work!
135
+ // *******************************
136
+ setWiFi (); // Start WiFiManager
137
+ otaUpdate (); // Enable ota updates
138
+ // *******************************
139
+
140
+ pinMode (0 , FUNCTION_0);
141
+ pinMode (1 , FUNCTION_3);
142
+ pinMode (2 , FUNCTION_0);
143
+ pinMode (3 , FUNCTION_3);
144
+ pinMode (4 , FUNCTION_0);
145
+ pinMode (5 , FUNCTION_0);
146
+ pinMode (13 , FUNCTION_2);
147
+ pinMode (14 , FUNCTION_2);
148
+ pinMode (15 , FUNCTION_2);
149
+
150
+ pinMode (latchPin, OUTPUT);
151
+ pinMode (enablePin, OUTPUT);
152
+ digitalWrite (enablePin, HIGH);
153
+
154
+ for (int i = 0 ; i < 4 ; i++) {
155
+ pinMode (rowAdrsPin[i], OUTPUT);
156
+ }
157
+
158
+ analogWrite (pwmPin, pwm); // Set initial brightness
159
+ SPI.begin ();
160
+ Serial.setDebugOutput (false ); // Stop all serial communication as serial pins are used for display
161
+ Serial.end ();
162
+ }
163
+
164
+ void loop () { // loops constantly
165
+ ArduinoOTA.handle (); // Checks for incoming update, please don't remove!
166
+ refreshDisplay ();
167
167
}
0 commit comments