So I am trying to make an arduino message display board using the arduino uno, with the shield. the intermediate display states for message CAKE IS A LIE will look like the following (character ^ stands for an empty position).
^^^C
^^CA
^CAK
CAKE
AKE^
KE^I
E^IS
^IS^
IS^A
S^A^
^A^L
A^LI
^LIE
LIE^
IE^^
E^^^
int get_string_length(const char *str) {
int i = 0;
while(*str++ != '\0') {
++i;
}
return i;
}
constexpr byte empty_glyph_mask = 0xFF;
constexpr int scrolling_interval = 300;
class Display {
private:
int position_to_show = 0;
unsigned long last_update = 0;
public:
bool end = true;
const char *message_to_show;
const char *p;
int u;
void run_message() {
if (last_update + scrolling_interval <= millis()) {
message_to_show++;
p = message_to_show;
u++;
last_update = millis();
if ((u > 3) && (*(message_to_show - number_of_display_positions + 1)== '\0')) {
end = true;
u = 0;
Serial.println(message_to_show);
}
}
else {
show_char(*(p + position_to_show - 3), position_to_show);
}
position_to_show++;
position_to_show %= number_of_display_positions;
}
void show_char(char ch, byte pos) {
byte glyph = empty_glyph_mask;
if (isAlpha(ch)) {
glyph = letter_glyph_masks[ch - (isUpperCase(ch) ? 'A' : 'a') ];
}
digitalWrite(latch_pin, LOW);
shiftOut(data_pin, clock_pin, MSBFIRST, glyph);
shiftOut(data_pin, clock_pin, MSBFIRST, 1 << pos);
digitalWrite(latch_pin, HIGH);
}
void show_glyph(byte glyph_mask, byte position_mask) {
digitalWrite(latch_pin, LOW);
shiftOut(data_pin, clock_pin, MSBFIRST, glyph_mask);
shiftOut(data_pin, clock_pin, MSBFIRST, position_mask);
digitalWrite(latch_pin, HIGH);
}
};
void setup() {
Serial.begin(9600);
pinMode(latch_pin, OUTPUT);
pinMode(clock_pin, OUTPUT);
pinMode(data_pin, OUTPUT);
input.initialize();
}
int i = 0;
void loop() {
input.updateInLoop();
if (display.end) {
display.message_to_show = input.getMessage();
Serial.println(display.message_to_show);
display.end = false;
}
display.run_message();
}
But I have problem with pointers, and I must use pointers. Any help?