Made MD* libraries (Parola, MAX72XX) project specific, to be able to use the newest software version from github.
This commit is contained in:
264
lib/MD_MAX72XX/examples/MD_MAX72xx_PushWheel/Font_Data.h
Normal file
264
lib/MD_MAX72XX/examples/MD_MAX72xx_PushWheel/Font_Data.h
Normal file
@@ -0,0 +1,264 @@
|
||||
// Data file for user example user defined fonts
|
||||
#ifndef FONTDATA_H
|
||||
#define FONTDATA_H
|
||||
|
||||
const uint8_t numeric7Seg[] PROGMEM = {
|
||||
0, // 0
|
||||
0, // 1
|
||||
0, // 2
|
||||
0, // 3
|
||||
0, // 4
|
||||
0, // 5
|
||||
0, // 6
|
||||
0, // 7
|
||||
0, // 8
|
||||
0, // 9
|
||||
0, // 10
|
||||
0, // 11
|
||||
0, // 12
|
||||
0, // 13
|
||||
0, // 14
|
||||
0, // 15
|
||||
0, // 16
|
||||
0, // 17
|
||||
0, // 18
|
||||
0, // 19
|
||||
0, // 20
|
||||
0, // 21
|
||||
0, // 22
|
||||
0, // 23
|
||||
0, // 24
|
||||
0, // 25
|
||||
0, // 26
|
||||
0, // 27
|
||||
0, // 28
|
||||
0, // 29
|
||||
0, // 30
|
||||
0, // 31
|
||||
1, 0, // 32 - 'Space'
|
||||
0, // 33 - '!'
|
||||
0, // 34 - '"'
|
||||
0, // 35 - '#'
|
||||
0, // 36 - '$'
|
||||
0, // 37 - '%'
|
||||
0, // 38 - '&'
|
||||
0, // 39 - '''
|
||||
0, // 40 - '('
|
||||
0, // 41 - ')'
|
||||
0, // 42 - '*'
|
||||
0, // 43 - '+'
|
||||
0, // 44 - ','
|
||||
0, // 45 - '-'
|
||||
1, 64, // 46 - '.'
|
||||
0, // 47 - '/'
|
||||
5, 127, 65, 65, 65, 127, // 48 - '0'
|
||||
5, 0, 0, 127, 0, 0, // 49 - '1'
|
||||
5, 121, 73, 73, 73, 79, // 50 - '2'
|
||||
5, 73, 73, 73, 73, 127, // 51 - '3'
|
||||
5, 15, 8, 8, 8, 127, // 52 - '4'
|
||||
5, 79, 73, 73, 73, 121, // 53 - '5'
|
||||
5, 127, 73, 73, 73, 121, // 54 - '6'
|
||||
5, 1, 1, 1, 1, 127, // 55 - '7'
|
||||
5, 127, 73, 73, 73, 127, // 56 - '8'
|
||||
5, 79, 73, 73, 73, 127, // 57 - '9'
|
||||
1, 20, // 58 - ':'
|
||||
0, // 59 - ';'
|
||||
0, // 60 - '<'
|
||||
0, // 61 - '='
|
||||
0, // 62 - '>'
|
||||
0, // 63 - '?'
|
||||
0, // 64 - '@'
|
||||
5, 127, 9, 9, 9, 127, // 65 - 'A'
|
||||
5, 127, 73, 73, 73, 54, // 66 - 'B'
|
||||
5, 127, 65, 65, 65, 65, // 67 - 'C'
|
||||
5, 127, 65, 65, 65, 62, // 68 - 'D'
|
||||
5, 127, 73, 73, 73, 73, // 69 - 'E'
|
||||
5, 127, 9, 9, 9, 9, // 70 - 'F'
|
||||
0, // 71 - 'G'
|
||||
0, // 72 - 'H'
|
||||
0, // 73 - 'I'
|
||||
0, // 74 - 'J'
|
||||
0, // 75 - 'K'
|
||||
0, // 76 - 'L'
|
||||
0, // 77 - 'M'
|
||||
0, // 78 - 'N'
|
||||
0, // 79 - 'O'
|
||||
0, // 80 - 'P'
|
||||
0, // 81 - 'Q'
|
||||
0, // 82 - 'R'
|
||||
0, // 83 - 'S'
|
||||
0, // 84 - 'T'
|
||||
0, // 85 - 'U'
|
||||
0, // 86 - 'V'
|
||||
0, // 87 - 'W'
|
||||
0, // 88 - 'X'
|
||||
0, // 89 - 'Y'
|
||||
0, // 90 - 'Z'
|
||||
0, // 91 - '['
|
||||
0, // 92 - '\'
|
||||
0, // 93 - ']'
|
||||
0, // 94 - '^'
|
||||
0, // 95 - '_'
|
||||
0, // 96 - '`'
|
||||
5, 127, 9, 9, 9, 127, // 97 - 'a'
|
||||
5, 127, 73, 73, 73, 54, // 98 - 'b'
|
||||
5, 127, 65, 65, 65, 65, // 99 - 'c'
|
||||
5, 127, 65, 65, 65, 62, // 100 - 'd'
|
||||
5, 127, 73, 73, 73, 73, // 101 - 'e'
|
||||
5, 127, 9, 9, 9, 9, // 102 - 'f'
|
||||
0, // 103 - 'g'
|
||||
0, // 104 - 'h'
|
||||
0, // 105 - 'i'
|
||||
0, // 106 - 'j'
|
||||
0, // 107 - 'k'
|
||||
0, // 108 - 'l'
|
||||
0, // 109 - 'm'
|
||||
0, // 110 - 'n'
|
||||
0, // 111 - 'o'
|
||||
0, // 112 - 'p'
|
||||
0, // 113 - 'q'
|
||||
0, // 114 - 'r'
|
||||
0, // 115 - 's'
|
||||
0, // 116 - 't'
|
||||
0, // 117 - 'u'
|
||||
0, // 118 - 'v'
|
||||
0, // 119 - 'w'
|
||||
0, // 120 - 'x'
|
||||
0, // 121 - 'y'
|
||||
0, // 122 - 'z'
|
||||
0, // 123 - '{'
|
||||
1, 127, // 124 - '|'
|
||||
0, // 125
|
||||
0, // 126
|
||||
0, // 127
|
||||
0, // 128
|
||||
0, // 129
|
||||
0, // 130
|
||||
0, // 131
|
||||
0, // 132
|
||||
0, // 133
|
||||
0, // 134
|
||||
0, // 135
|
||||
0, // 136
|
||||
0, // 137
|
||||
0, // 138
|
||||
0, // 139
|
||||
0, // 140
|
||||
0, // 141
|
||||
0, // 142
|
||||
0, // 143
|
||||
0, // 144
|
||||
0, // 145
|
||||
0, // 146
|
||||
0, // 147
|
||||
0, // 148
|
||||
0, // 149
|
||||
0, // 150
|
||||
0, // 151
|
||||
0, // 152
|
||||
0, // 153
|
||||
0, // 154
|
||||
0, // 155
|
||||
0, // 156
|
||||
0, // 157
|
||||
0, // 158
|
||||
0, // 159
|
||||
0, // 160
|
||||
0, // 161
|
||||
0, // 162
|
||||
0, // 163
|
||||
0, // 164
|
||||
0, // 165
|
||||
0, // 166
|
||||
0, // 167
|
||||
0, // 168
|
||||
0, // 169
|
||||
0, // 170
|
||||
0, // 171
|
||||
0, // 172
|
||||
0, // 173
|
||||
0, // 174
|
||||
0, // 175
|
||||
0, // 176
|
||||
0, // 177
|
||||
0, // 178
|
||||
0, // 179
|
||||
0, // 180
|
||||
0, // 181
|
||||
0, // 182
|
||||
0, // 183
|
||||
0, // 184
|
||||
0, // 185
|
||||
0, // 186
|
||||
0, // 187
|
||||
0, // 188
|
||||
0, // 189
|
||||
0, // 190
|
||||
0, // 191
|
||||
0, // 192
|
||||
0, // 193
|
||||
0, // 194
|
||||
0, // 195
|
||||
0, // 196
|
||||
0, // 197
|
||||
0, // 198
|
||||
0, // 199
|
||||
0, // 200
|
||||
0, // 201
|
||||
0, // 202
|
||||
0, // 203
|
||||
0, // 204
|
||||
0, // 205
|
||||
0, // 206
|
||||
0, // 207
|
||||
0, // 208
|
||||
0, // 209
|
||||
0, // 210
|
||||
0, // 211
|
||||
0, // 212
|
||||
0, // 213
|
||||
0, // 214
|
||||
0, // 215
|
||||
0, // 216
|
||||
0, // 217
|
||||
0, // 218
|
||||
0, // 219
|
||||
0, // 220
|
||||
0, // 221
|
||||
0, // 222
|
||||
0, // 223
|
||||
0, // 224
|
||||
0, // 225
|
||||
0, // 226
|
||||
0, // 227
|
||||
0, // 228
|
||||
0, // 229
|
||||
0, // 230
|
||||
0, // 231
|
||||
0, // 232
|
||||
0, // 233
|
||||
0, // 234
|
||||
0, // 235
|
||||
0, // 236
|
||||
0, // 237
|
||||
0, // 238
|
||||
0, // 239
|
||||
0, // 240
|
||||
0, // 241
|
||||
0, // 242
|
||||
0, // 243
|
||||
0, // 244
|
||||
0, // 245
|
||||
0, // 246
|
||||
0, // 247
|
||||
0, // 248
|
||||
0, // 249
|
||||
0, // 250
|
||||
0, // 251
|
||||
0, // 252
|
||||
0, // 253
|
||||
0, // 254
|
||||
0, // 255
|
||||
};
|
||||
|
||||
#endif
|
@@ -0,0 +1,225 @@
|
||||
// Use the MD_MAX72XX library to create an mechanical pushwheel type display
|
||||
// When numbers change they are scrolled up or down as if on a cylinder
|
||||
//
|
||||
// 'Speed' displayed is read from pot on SPEED_IN analog in.
|
||||
|
||||
#include <MD_MAX72xx.h>
|
||||
#include <SPI.h>
|
||||
#include "Font_Data.h"
|
||||
|
||||
#define DEBUG 0
|
||||
|
||||
#if DEBUG
|
||||
#define PRINT(s, v) { Serial.print(F(s)); Serial.print(v); }
|
||||
#define PRINTX(s, v) { Serial.print(F(s)); Serial.print(v, HEX); }
|
||||
#define PRINTS(s) Serial.print(F(s));
|
||||
#else
|
||||
#define PRINT(s, v)
|
||||
#define PRINTS(s)
|
||||
#endif
|
||||
|
||||
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
|
||||
|
||||
// Define the number of devices we have in the chain and the hardware interface
|
||||
// NOTE: These pin numbers will probably not work with your hardware and may
|
||||
// need to be adapted
|
||||
#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
|
||||
#define MAX_DEVICES 4
|
||||
|
||||
#define CLK_PIN 13 // or SCK
|
||||
#define DATA_PIN 11 // or MOSI
|
||||
#define CS_PIN 10 // or SS
|
||||
|
||||
// SPI hardware interface
|
||||
MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
|
||||
// Arbitrary pins
|
||||
//MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
|
||||
|
||||
// Analog input pin for the input value
|
||||
#define SPEED_IN A5
|
||||
|
||||
// Display and animation parameters
|
||||
#define CHAR_SPACING 1 // pixels between characters
|
||||
#define CHAR_COLS 5 // should match the fixed width character columns
|
||||
#define ANIMATION_FRAME_DELAY 30 // in milliseconds
|
||||
|
||||
// Structure to hold the data for each character to be displayed and animated
|
||||
// this could be expanded to include other character specific data (eg, column
|
||||
// where it starts if display is spaced irregularly).
|
||||
struct digitData
|
||||
{
|
||||
uint8_t oldValue, newValue; // ASCII value for the character
|
||||
uint8_t index; // animation progression index
|
||||
uint32_t timeLastFrame; // time the last frame started animating
|
||||
uint8_t charCols; // number of valid cols in the charMap
|
||||
uint8_t charMap[CHAR_COLS]; // character font bitmap
|
||||
};
|
||||
|
||||
void updateDisplay(uint16_t numDigits, struct digitData *d)
|
||||
// do the necessary to display current bitmap buffer to the LED display
|
||||
{
|
||||
uint8_t curCol = 0;
|
||||
|
||||
mx.control(MD_MAX72XX::UPDATE, MD_MAX72XX::OFF);
|
||||
mx.clear();
|
||||
|
||||
for (int8_t i = numDigits - 1; i >= 0; i--)
|
||||
{
|
||||
for (int8_t j = d[i].charCols - 1; j >= 0; j--)
|
||||
{
|
||||
mx.setColumn(curCol++, d[i].charMap[j]);
|
||||
}
|
||||
curCol += CHAR_SPACING;
|
||||
}
|
||||
|
||||
mx.control(MD_MAX72XX::UPDATE, MD_MAX72XX::ON);
|
||||
}
|
||||
|
||||
boolean displayValue(uint16_t value)
|
||||
// Display the required value on the LED matrix and return true if an animation is current
|
||||
// Finite state machine will ignore new values while animations are underway.
|
||||
// Needs to be called repeatedly to ensure animations are completed smoothly.
|
||||
{
|
||||
const uint8_t DIGITS_SIZE = 3;
|
||||
static struct digitData digit[DIGITS_SIZE];
|
||||
|
||||
const uint8_t ST_INIT = 0, ST_WAIT = 1, ST_ANIM = 2;
|
||||
static uint8_t state = ST_INIT;
|
||||
|
||||
// finite state machine to control what we do
|
||||
switch(state)
|
||||
{
|
||||
case ST_INIT: // Initialize the display - done once only on first call
|
||||
PRINTS("\nST_INIT");
|
||||
for (int8_t i = DIGITS_SIZE - 1; i >= 0; i--)
|
||||
{
|
||||
// separate digits
|
||||
digit[i].oldValue = '0' + value % 10;
|
||||
value = value / 10;
|
||||
}
|
||||
|
||||
// Display the starting number
|
||||
for (int8_t i = DIGITS_SIZE - 1; i >= 0; i--)
|
||||
{
|
||||
digit[i].charCols = mx.getChar(digit[i].oldValue, CHAR_COLS, digit[i].charMap);
|
||||
}
|
||||
updateDisplay(DIGITS_SIZE, digit);
|
||||
|
||||
// Now we wait for a change
|
||||
state = ST_WAIT;
|
||||
break;
|
||||
|
||||
case ST_WAIT: // not animating - save new value digits and check if we need to animate
|
||||
PRINTS("\nST_WAIT");
|
||||
for (int8_t i = DIGITS_SIZE - 1; i >= 0; i--)
|
||||
{
|
||||
// separate digits
|
||||
digit[i].newValue = '0' + value % 10;
|
||||
value = value / 10;
|
||||
|
||||
if (digit[i].newValue != digit[i].oldValue)
|
||||
{
|
||||
// a change has been found - we will be animating something
|
||||
state = ST_ANIM;
|
||||
// initialize animation parameters for this digit
|
||||
digit[i].index = 0;
|
||||
digit[i].timeLastFrame = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (state == ST_WAIT) // no changes - keep waiting
|
||||
break;
|
||||
// else fall through as we need to animate from now
|
||||
|
||||
case ST_ANIM: // currently animating a change
|
||||
// work out the new intermediate bitmap for each character
|
||||
// 1. Get the 'new' character bitmap into temp buffer
|
||||
// 2. Shift this buffer down or up by current index amount
|
||||
// 3. Shift the current character by one pixel up or down
|
||||
// 4. Combine the new partial character and the existing character to produce a frame
|
||||
for (int8_t i = DIGITS_SIZE - 1; i >= 0; i--)
|
||||
{
|
||||
if ((digit[i].newValue != digit[i].oldValue) && // values are different
|
||||
(millis() - digit[i].timeLastFrame >= ANIMATION_FRAME_DELAY)) // timer has expired
|
||||
{
|
||||
uint8_t newChar[CHAR_COLS] = { 0 };
|
||||
|
||||
PRINT("\nST_ANIM Digit ", i);
|
||||
PRINT(" from '", (char)digit[i].oldValue);
|
||||
PRINT("' to '", (char)digit[i].newValue);
|
||||
PRINT("' index ", digit[i].index);
|
||||
|
||||
mx.getChar(digit[i].newValue, CHAR_COLS, newChar);
|
||||
if (((digit[i].newValue > digit[i].oldValue) || // incrementing
|
||||
(digit[i].oldValue == '9' && digit[i].newValue == '0')) && // wrapping around on increase
|
||||
!(digit[i].oldValue == '0' && digit[i].newValue == '9')) // not wrapping around on decrease
|
||||
{
|
||||
// scroll down
|
||||
for (uint8_t j = 0; j < digit[i].charCols; j++)
|
||||
{
|
||||
newChar[j] = newChar[j] >> (COL_SIZE - 1 - digit[i].index);
|
||||
digit[i].charMap[j] = digit[i].charMap[j] << 1;
|
||||
digit[i].charMap[j] |= newChar[j];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// scroll up
|
||||
for (uint8_t j = 0; j < digit[i].charCols; j++)
|
||||
{
|
||||
newChar[j] = newChar[j] << (COL_SIZE - 1 - digit[i].index);
|
||||
digit[i].charMap[j] = digit[i].charMap[j] >> 1;
|
||||
digit[i].charMap[j] |= newChar[j];
|
||||
}
|
||||
}
|
||||
|
||||
// set new parameters for next animation and check if we are done
|
||||
digit[i].index++;
|
||||
digit[i].timeLastFrame = millis();
|
||||
if (digit[i].index >= COL_SIZE )
|
||||
digit[i].oldValue = digit[i].newValue; // done animating
|
||||
}
|
||||
}
|
||||
|
||||
updateDisplay(DIGITS_SIZE, digit); // show new display
|
||||
|
||||
// are we done animating?
|
||||
{
|
||||
boolean allDone = true;
|
||||
|
||||
for (uint8_t i = 0; allDone && (i < DIGITS_SIZE); i++)
|
||||
{
|
||||
allDone = allDone && (digit[i].oldValue == digit[i].newValue);
|
||||
}
|
||||
|
||||
if (allDone) state = ST_WAIT;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
state = 0;
|
||||
}
|
||||
|
||||
return(state == ST_WAIT); // animation has ended
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
#if DEBUG
|
||||
Serial.begin(57600);
|
||||
#endif // DEBUG
|
||||
PRINTS("\n[MD_MAX72xx PushWheel]")
|
||||
|
||||
mx.begin();
|
||||
mx.setFont(numeric7Seg);
|
||||
|
||||
pinMode(SPEED_IN, INPUT);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
int16_t value = analogRead(SPEED_IN)/10; // remove jitters
|
||||
|
||||
displayValue(value);
|
||||
}
|
||||
|
Reference in New Issue
Block a user