Scrolling text forward and back with an analog input

Hi. Have been working with arduino for 1 year now and made a couple of projects successfully. that's all god so far.
but me new project really gives me trouble. :stuck_out_tongue:

Iv'e bought myself 1 video experimenter kit for use with my home built underwater ROW.
now I want to have a text scrolling fourth and back in the bottom of my video feed using an analog value as a guideline.
the whole text string is as follows but only 20 letters or so will be visible at one time:

....N..........NW.........W..........SW.........S..........SE.........E..........NE.........

I would like to map this to an analog value of 0 to 359 as that is what i expect returning from my digital compass.
the code i have is from the demo overlay for the kit and i feel that it's a starting point but not sure how to get it right:

#include <TVout.h>
#include <fontALL.h>

#define W 136
#define H 96

TVout tv;
unsigned char x,y;
unsigned char originx = 5;
unsigned char originy = 80;
unsigned char plotx = originx;
unsigned char ploty = 40;
char s[32];
unsigned int n = 0;
int index = 0;
int messageLen = 92;
char message[] = "....N..........NW.........W..........SW.........S..........SE.........E..........NE.........";
char saveChar;

void setup()  {
  tv.begin(PAL, W, H);
  initOverlay();
  tv.select_font(font6x8);
  tv.fill(0);
  drawGraph();

}

// Initialize ATMega registers for video overlay capability.
// Must be called after tv.begin().
void initOverlay() {
  TCCR1A = 0;
  // Enable timer1.  ICES0 is set to 0 for falling edge detection on input capture pin.
  TCCR1B = _BV(CS10);

  // Enable input capture interrupt
  TIMSK1 |= _BV(ICIE1);

  // Enable external interrupt INT0 on pin 2 with falling edge.
  EIMSK = _BV(INT0);
  EICRA = _BV(ISC11);
}

// Required to reset the scan line when the vertical sync occurs
ISR(INT0_vect) {
  display.scanLine = 0;
}


void loop() {
  saveChar = message[index+22];
  message[index+22] = '\0';

  for(int x=6;x>=0;x--) {
    if (x<6) {
      tv.delay_frame(1);
    } 
    tv.print(x, 87, message+index);

    for(byte y=87;y<96;y++) {
      tv.draw_line(0, y, 5, y, 0);
      tv.draw_line(128, y, 134, y, 0);
    }

  }

  message[index+22] = saveChar;      // here the print out of the text begins but how to get it scrolling fourth and back and even stop when alignet to input ???
  index++;
  if (index > 92) {
    index = 0;
  }

 


  
 
}

void drawGraph() {
  tv.draw_line(originx, 15, originx, originy, 1);
  tv.draw_line(originx, originy, 120, originy, 1);
  for(byte y=originy;y>15;y -= 4) {
    tv.set_pixel(originx-1, y, 1);
    tv.set_pixel(originx-2, y, 1);
  }
  for(byte x=originx;x<120;x += 4) {
    tv.set_pixel(x, originy+1, 1);
    tv.set_pixel(x, originy+2, 1);
  }
}

I would really appreciated some help here.... feel rather stock with this
Best regards

Please modify your post, select the code and press the # button so it gets tagged properly. Looks so much better.

Easiest way is to make the string a longer so the characters that got wrapped are in place allready

"......NE........N..........NW.........W..........SW.........S..........SE.........E..........NE.........N..........NW...."

                 ^ = 0 degrees                                                                           ^ = 360 degrees

If you now have 0 degrees you display the string from position 0,
and if you have 359 degrees the string is long enough to fill the display properly

something like this

char message[] = "........N..........NW.........W..........SW.........S..........SE..........E..........NE.........N..........NW......";

void setup() 
{
  Serial.begin(115200);
  Serial.println("Start...");

  printDir(0);
  printDir(359);

  for (int i=0; i<3590; i++)
  {
    printDir(i);
  }
}

void loop() 
{
}

void printDir(int idx)
{
  idx = (idx%360)/4;
  char part[21];
  strncpy(part, &message[idx], 20);
  part[20] = '\0';
  Serial.println(part);
  delay(10);
}

Fantastic I must say.
the solution you came up with..... :slight_smile:

I only spent 10 minutes to rewrite it to fit my setup..... Thank you so much.....
and think of it... I spent 4 day coming nowhere ...
IT IS WORKING.... :stuck_out_tongue_closed_eyes:
Again Thank You.... :slight_smile: