Arduino Running Message

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?

An array will work fineā€¦

I guess this is requirement of the assignment.
What is input here ?

The input.updateInLoop, there is nothing, but the input.getMessage() holds the last message written in the console/debugger or what is it called..

OK. So 'input' is probably an instance of class you have somehow defined.
Does the program work and you are simply having a problem understanding it or what ?

For help here, you are probably going to have to show your entire code and state what Arduino display shield you are using.

consider

   C
  CA
 CAK
CAKE
AKE 
KE I
E IS
 IS 
IS A
S A 
 A L
A LI
 LIE
LIE 
IE  
E   
   C
  CA
 CAK
CAKE
AKE 
KE I
E IS
 IS 
IS A
S A 
 A L


#define L   4
void
scroll (
    const char *s)
{
    static int idx = 0;
    char buf [80];
    char t [L];
    int  len = strlen (s);

    strcpy (buf, "   ");
    strcat (buf, s);
    strcat (buf, "   ");

    strncpy (t, & buf [idx], L);
    Serial.println (t);
    
    if (len + 2 < ++idx)
        idx = 0;
}


// -----------------------------------------------------------------------------
void loop (void)
{
    scroll ("CAKE IS A LIE");
}

// -----------------------------------------------------------------------------
void setup (void)
{
    Serial.begin (9600);
}

classes are good when reused. sometimes they become a distraction or simple things

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.