[solved]TVOut sketch question

I've been working with TVout for a few weeks and have really been enjoying it. I have modified some sketch code that I found but would like to make some changes in it that I just can't figure out (I've attached my code). I'm pulling my hair out trying to figure this out.

This sketch shows a series of BMP images, then starts up a spinning cube that keeps running forever.

Question: Would it be possible to make the spinning cube in the sketch only spin for a short period of time, then have the BMPs start over again (and eventually go back to the spinning cube for a short duration)?

Essentially, I want to loop everything, but I can't figure out how to do it.

TVOut.txt (5.47 KB)

Start by putting the BMP stuff in a separate function and the cube stuff (the contents of loop()) into a separate function. Then you can call the BMP function when you want to see the pictures and call the cube function for as long as you want to see the cube.

Like this:

void setup() {
  TV.begin(NTSC, 120, 96);
  intro();
  randomSeed(analogRead(0));
}


void loop() {
  BMP();


  //random cube
  TV.clear_screen();
  TV.delay(0010);
  unsigned long startTime = millis();
  // Repeat for at least five seconds
  while (millis() - startTime < 5000) {
    cube();
  }
}


void BMP() {
  TV.bitmap(0, 0, RocketShip);
  TV.delay(30000);
  TV.clear_screen();
  TV.bitmap(0, 0, ArduinoLogo);
  TV.delay(30000);
  TV.clear_screen();
  TV.bitmap(0, 0, Pong);
  TV.delay(30000);
  TV.clear_screen();
  TV.bitmap(0, 0, SpaceInvaders);
  TV.delay(30000);
  TV.clear_screen();
  TV.bitmap(15, 0, PacMan);
  TV.delay(30000);
  TV.clear_screen();
  TV.bitmap(15, 0, SpyVsSpy);
  TV.delay(30000);
  TV.clear_screen();
  TV.bitmap(15, 0, CMD);
  TV.delay(30000);
  TV.clear_screen();
  TV.bitmap(15, 0, Computer);
  TV.delay(30000);
  TV.clear_screen();
  TV.bitmap(15, 0, WOPR);
  TV.delay(30000);
  TV.clear_screen();
  TV.bitmap(0, 0, Text);
  TV.delay(30000);
  TV.clear_screen();
  TV.bitmap(0, 0, W9SPY);
  TV.delay(30000);
  TV.clear_screen();
  TV.bitmap(0, 0, Radio);
  TV.delay(30000);
  TV.clear_screen();
  TV.bitmap(0, 0, Tower);
  TV.delay(30000);
  TV.clear_screen();
  TV.draw_rect(20, 20, 80, 56, WHITE);
  TV.delay(2000);
}




void cube() {
  int rsteps = random(10, 60);
  switch (random(6)) {
    case 0:
      for (int i = 0; i < rsteps; i++) {
        zrotate(angle);
        printcube();
      }
      break;
    case 1:
      for (int i = 0; i < rsteps; i++) {
        zrotate(2 * PI - angle);
        printcube();
      }
      break;
    case 2:
      for (int i = 0; i < rsteps; i++) {
        xrotate(angle);
        printcube();
      }
      break;
    case 3:
      for (int i = 0; i < rsteps; i++) {
        xrotate(2 * PI - angle);
        printcube();
      }
      break;
    case 4:
      for (int i = 0; i < rsteps; i++) {
        yrotate(angle);
        printcube();
      }
      break;
    case 5:
      for (int i = 0; i < rsteps; i++) {
        yrotate(2 * PI - angle);
        printcube();
      }
      break;
  }
}

Thank you for taking the time to answer my question and to provide a code example.

Honestly, I think that I'm in over my head here. I've tried several different ways to incorporate your code into my sketch and I keep getting error messages. (Newly revised code, using your suggestions, attached).

Error message: Arduino: 1.8.5 (Windows 10), Board: "Arduino/Genuino Uno"

C:\Program Files (x86)\Arduino\DemoNTSC_TESTER\DemoNTSC_TESTER.ino:27:9: warning: narrowing conversion of '(xOff - cSize)' from 'int' to 'float' inside { } [-Wnarrowing]

{xOff - cSize,yOff + cSize,zOff - cSize},

^

C:\Program Files (x86)\Arduino\DemoNTSC_TESTER\DemoNTSC_TESTER.ino:27:22: warning: narrowing conversion of '(yOff + cSize)' from 'int' to 'float' inside { } [-Wnarrowing]

{xOff - cSize,yOff + cSize,zOff - cSize},

^

C:\Program Files (x86)\Arduino\DemoNTSC_TESTER\DemoNTSC_TESTER.ino:27:35: warning: narrowing conversion of '(zOff - cSize)' from 'int' to 'float' inside { } [-Wnarrowing]

{xOff - cSize,yOff + cSize,zOff - cSize},

^

C:\Program Files (x86)\Arduino\DemoNTSC_TESTER\DemoNTSC_TESTER.ino:28:9: warning: narrowing conversion of '(xOff + cSize)' from 'int' to 'float' inside { } [-Wnarrowing]

{xOff + cSize,yOff + cSize,zOff - cSize},

^

C:\Program Files (x86)\Arduino\DemoNTSC_TESTER\DemoNTSC_TESTER.ino:28:22: warning: narrowing conversion of '(yOff + cSize)' from 'int' to 'float' inside { } [-Wnarrowing]

{xOff + cSize,yOff + cSize,zOff - cSize},

^

C:\Program Files (x86)\Arduino\DemoNTSC_TESTER\DemoNTSC_TESTER.ino:28:35: warning: narrowing conversion of '(zOff - cSize)' from 'int' to 'float' inside { } [-Wnarrowing]

{xOff + cSize,yOff + cSize,zOff - cSize},

^

C:\Program Files (x86)\Arduino\DemoNTSC_TESTER\DemoNTSC_TESTER.ino:29:9: warning: narrowing conversion of '(xOff - cSize)' from 'int' to 'float' inside { } [-Wnarrowing]

{xOff - cSize,yOff - cSize,zOff - cSize},

^

C:\Program Files (x86)\Arduino\DemoNTSC_TESTER\DemoNTSC_TESTER.ino:29:22: warning: narrowing conversion of '(yOff - cSize)' from 'int' to 'float' inside { } [-Wnarrowing]

{xOff - cSize,yOff - cSize,zOff - cSize},

^

C:\Program Files (x86)\Arduino\DemoNTSC_TESTER\DemoNTSC_TESTER.ino:29:35: warning: narrowing conversion of '(zOff - cSize)' from 'int' to 'float' inside { } [-Wnarrowing]

{xOff - cSize,yOff - cSize,zOff - cSize},

^

C:\Program Files (x86)\Arduino\DemoNTSC_TESTER\DemoNTSC_TESTER.ino:30:9: warning: narrowing conversion of '(xOff + cSize)' from 'int' to 'float' inside { } [-Wnarrowing]

{xOff + cSize,yOff - cSize,zOff - cSize},

^

C:\Program Files (x86)\Arduino\DemoNTSC_TESTER\DemoNTSC_TESTER.ino:30:22: warning: narrowing conversion of '(yOff - cSize)' from 'int' to 'float' inside { } [-Wnarrowing]

{xOff + cSize,yOff - cSize,zOff - cSize},

^

C:\Program Files (x86)\Arduino\DemoNTSC_TESTER\DemoNTSC_TESTER.ino:30:35: warning: narrowing conversion of '(zOff - cSize)' from 'int' to 'float' inside { } [-Wnarrowing]

{xOff + cSize,yOff - cSize,zOff - cSize},

^

C:\Program Files (x86)\Arduino\DemoNTSC_TESTER\DemoNTSC_TESTER.ino:31:9: warning: narrowing conversion of '(xOff - cSize)' from 'int' to 'float' inside { } [-Wnarrowing]

{xOff - cSize,yOff + cSize,zOff + cSize},

^

C:\Program Files (x86)\Arduino\DemoNTSC_TESTER\DemoNTSC_TESTER.ino:31:22: warning: narrowing conversion of '(yOff + cSize)' from 'int' to 'float' inside { } [-Wnarrowing]

{xOff - cSize,yOff + cSize,zOff + cSize},

^

C:\Program Files (x86)\Arduino\DemoNTSC_TESTER\DemoNTSC_TESTER.ino:31:35: warning: narrowing conversion of '(zOff + cSize)' from 'int' to 'float' inside { } [-Wnarrowing]

{xOff - cSize,yOff + cSize,zOff + cSize},

^

C:\Program Files (x86)\Arduino\DemoNTSC_TESTER\DemoNTSC_TESTER.ino:32:9: warning: narrowing conversion of '(xOff + cSize)' from 'int' to 'float' inside { } [-Wnarrowing]

{xOff + cSize,yOff + cSize,zOff + cSize},

^

C:\Program Files (x86)\Arduino\DemoNTSC_TESTER\DemoNTSC_TESTER.ino:32:22: warning: narrowing conversion of '(yOff + cSize)' from 'int' to 'float' inside { } [-Wnarrowing]

{xOff + cSize,yOff + cSize,zOff + cSize},

^

C:\Program Files (x86)\Arduino\DemoNTSC_TESTER\DemoNTSC_TESTER.ino:32:35: warning: narrowing conversion of '(zOff + cSize)' from 'int' to 'float' inside { } [-Wnarrowing]

{xOff + cSize,yOff + cSize,zOff + cSize},

^

C:\Program Files (x86)\Arduino\DemoNTSC_TESTER\DemoNTSC_TESTER.ino:33:9: warning: narrowing conversion of '(xOff - cSize)' from 'int' to 'float' inside { } [-Wnarrowing]

{xOff - cSize,yOff - cSize,zOff + cSize},

^

C:\Program Files (x86)\Arduino\DemoNTSC_TESTER\DemoNTSC_TESTER.ino:33:22: warning: narrowing conversion of '(yOff - cSize)' from 'int' to 'float' inside { } [-Wnarrowing]

{xOff - cSize,yOff - cSize,zOff + cSize},

^

C:\Program Files (x86)\Arduino\DemoNTSC_TESTER\DemoNTSC_TESTER.ino:33:35: warning: narrowing conversion of '(zOff + cSize)' from 'int' to 'float' inside { } [-Wnarrowing]

{xOff - cSize,yOff - cSize,zOff + cSize},

^

C:\Program Files (x86)\Arduino\DemoNTSC_TESTER\DemoNTSC_TESTER.ino:34:9: warning: narrowing conversion of '(xOff + cSize)' from 'int' to 'float' inside { } [-Wnarrowing]

{xOff + cSize,yOff - cSize,zOff + cSize}

^

C:\Program Files (x86)\Arduino\DemoNTSC_TESTER\DemoNTSC_TESTER.ino:34:22: warning: narrowing conversion of '(yOff - cSize)' from 'int' to 'float' inside { } [-Wnarrowing]

{xOff + cSize,yOff - cSize,zOff + cSize}

^

C:\Program Files (x86)\Arduino\DemoNTSC_TESTER\DemoNTSC_TESTER.ino:34:35: warning: narrowing conversion of '(zOff + cSize)' from 'int' to 'float' inside { } [-Wnarrowing]

{xOff + cSize,yOff - cSize,zOff + cSize}

^

C:\Program Files (x86)\Arduino\DemoNTSC_TESTER\DemoNTSC_TESTER.ino: In function 'void setup()':

DemoNTSC_TESTER:39: error: 'intro' was not declared in this scope

intro();

^

C:\Program Files (x86)\Arduino\DemoNTSC_TESTER\DemoNTSC_TESTER.ino: In function 'void cube()':

DemoNTSC_TESTER:106: error: 'zrotate' was not declared in this scope

zrotate(angle);

^

DemoNTSC_TESTER:107: error: 'printcube' was not declared in this scope

printcube();

^

DemoNTSC_TESTER:112: error: 'zrotate' was not declared in this scope

zrotate(2 * PI - angle);

^

DemoNTSC_TESTER:113: error: 'printcube' was not declared in this scope

printcube();

^

DemoNTSC_TESTER:118: error: 'xrotate' was not declared in this scope

xrotate(angle);

^

DemoNTSC_TESTER:119: error: 'printcube' was not declared in this scope

printcube();

^

DemoNTSC_TESTER:124: error: 'xrotate' was not declared in this scope

xrotate(2 * PI - angle);

^

DemoNTSC_TESTER:125: error: 'printcube' was not declared in this scope

printcube();

^

DemoNTSC_TESTER:130: error: 'yrotate' was not declared in this scope

yrotate(angle);

^

DemoNTSC_TESTER:131: error: 'printcube' was not declared in this scope

printcube();

^

DemoNTSC_TESTER:136: error: 'yrotate' was not declared in this scope

yrotate(2 * PI - angle);

^

DemoNTSC_TESTER:137: error: 'printcube' was not declared in this scope

printcube();

^

C:\Program Files (x86)\Arduino\DemoNTSC_TESTER\DemoNTSC_TESTER.ino: At global scope:

DemoNTSC_TESTER:145: error: expected unqualified-id before 'switch'

switch(random(6)) {

^

exit status 1
'intro' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

TVOut.txt (6.46 KB)