Hallo Leute,
ich habe mal wieder folgendes Problem...
Und zwar möchte ich diese Routine umschreiben, so das sie mit "Variablen" Strings arbeiten kann.
Ist das überhaupt möglich?
Hier die Routine die mit statischen Strings arbeitet z.B "Hallo Welt"...
ich habe mal wieder folgendes Problem...
Und zwar möchte ich diese Routine umschreiben, so das sie mit "Variablen" Strings arbeiten kann.
Ist das überhaupt möglich?
Hier die Routine die mit statischen Strings arbeitet z.B "Hallo Welt"...
Code:
void scroll_display(const char *s,uint8_t speed) {
// clear display
ledarray_blank();
int8_t offset = 0 , next_offset = 0;
uint8_t is_started = 0;
uint8_t y=0;
char x=' ';
if(speed==0)
speed=90;
// begin loop and continue until nul character at end of string
while(pgm_read_byte(s) != 0x00){
// have we read a character?
if(is_started) {
// if so, place and shift the character until it is clear of column (COLS-1)
while(next_offset>(COLS-1)){
delay_ms(speed);
// shift the display one place
ledarray_left_shift();
// check the end of the currently displayed characters if it's greater than zero, decrement
// both the offset (character display position), and next_offset(character end position)
if(next_offset > 0) {
offset -= 1;
next_offset -= 1;
}
// display the character at the new position
font_display(x, offset);
}
} else {
// if not, set offset to # of columns -1 ((COLS-1))
offset = COLS-1;
}
// read the next character in the string
x = pgm_read_byte(s++);
// if we have already started, set the current display position to where the last character ended
if(is_started)
offset = next_offset;
// display the character
font_display(x, offset);
// create the new character end position
next_offset = offset + font_width(x)+1;
// set Enable_DCF77_Scan to show we have been through the loop
is_started = 1;
}
// Process the last character. This is neccessary since the while bails as soon as it reads
// the null character. At that point, the last read character has not yet shifted into full
// view. The following while loop shifts the final string character into full view.
while(next_offset>(COLS-1)){
delay_ms(speed);
ledarray_left_shift();
if(next_offset > 0) {
offset -= 1;
next_offset -= 1;
}
font_display(x, offset);
}
delay_ms(speed);
// this final loop shifts the display all the way off.
for(y=0;y<COLS;y++){
ledarray_left_shift();
delay_ms(speed);
}
return;
}