Go Down

Topic: Countdown for an interactive VJ setup! (Read 938 times) previous topic - next topic

PSneep

Hiya! I'm building a custom interactive VJ setup using a Teensy, Arduino code, 2 USB HD camera's, some immensely huge big red buttons and the VJ software Resolume. It's pretty much done, though it needs one more tweek.

As it is now, when someone presses a big red button the Teensy produces a random letter or number, which Resolume interprets as a hotkey to initiate a certain channel of video footage and effects. Dandy! (see the code below)

However, the crowd seems to think the big red buttons are a little more scary than I thought they would. To encourage usage of the buttons I want to make a fancy instruction video that shows the crowd what's what. This video should start playing after let's say, no-one has pressed any of the buttons for about 3 minutes.

So long story short, this is what the Teensy needs to do in addition to the functionality as it is at the moment:

Start counting.
If a button is pressed: reset the counter, start counting again.
If the counter reaches 3 minutes, print a "/", where the "/" will be assigned to the instruction video in Resolume. Also: stop the counter.

I'm having trouble with actually coming up with some concrete usable code. Can anyone lend me a hand on this?

Code: [Select]
// Defining first category of random keys
const byte randomLetters = 26;
char* letters[randomLetters] = {
  "a", "b", "c", "d", "e", "f", "g", "h", "i",
  "j", "k", "l", "m", "n", "o", "p", "q", "r",
  "s", "t","u","v","w","x","y","z"};
 
char* oldResult = 0;
 
// Defining second category of random keys
  const byte randomNumbers = 10;
char* numbers[randomNumbers] = {
  "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"};
 
// Hello buttons, we will use you. Ha!
int button1 = 0;
int button2 = 1;
int button3 = 2;
int button4 = 3;
int button5 = 4;
int button6 = 5;

//----------------------------------------SETUP

void setup(){
  Serial.begin(9600);
  randomSeed(analogRead(0));
  pinMode(button1,INPUT_PULLUP);
  pinMode(button2,INPUT_PULLUP);
  pinMode(button3,INPUT_PULLUP);
  pinMode(button4,INPUT_PULLUP);
  pinMode(button5,INPUT_PULLUP);
  pinMode(button6,INPUT_PULLUP);
  delay(500);
}

//----------------------------------------LOOP

void loop ()
    {
    char* currentResult;

    if(digitalRead(button1) == LOW)  //read buttonpress on button1

       {
   //generate a random letter, print it to the Mac:
   
    do {//randomize, but make sure we don't get the same result twice in a row
        currentResult = letters[random(0,randomLetters)];
        } while (currentResult == oldResult);
    oldResult = currentResult;
    Keyboard.print(currentResult);
    Keyboard.print("");
   
    delay(250); //little delay so we only get 1 letter at a time
  }
 

if(digitalRead(button2) == LOW) //read buttonpress on button2

  {
    do {//randomize, but make sure we don't get the same result twice in a row
        currentResult = letters[random(0,randomLetters)];
        } while (currentResult == oldResult);
    oldResult = currentResult;
    Keyboard.print(currentResult);
    Keyboard.print("");
    delay(250);
  }
 
 
if(digitalRead(button4) == LOW) //read buttonpress on button4

  {
    do {//randomize, but make sure we don't get the same result twice in a row
        currentResult = letters[random(0,randomLetters)];
        } while (currentResult == oldResult);
    oldResult = currentResult;
    Keyboard.print(currentResult);
    Keyboard.print("");
    delay(250);
  }
 
if(digitalRead(button5) == LOW) //read buttonpress on button5

  {
    do {//randomize, but make sure we don't get the same result twice in a row
        currentResult = letters[random(0,randomLetters)];
        } while (currentResult == oldResult);
    oldResult = currentResult;
    Keyboard.print(currentResult);
    Keyboard.print("");
    delay(250);
  }
 
 
  if(digitalRead(button6) == LOW) //read buttonpress on button6

  {
    do {//randomize, but make sure we don't get the same result twice in a row
        currentResult = letters[random(0,randomLetters)];
        } while (currentResult == oldResult);
    oldResult = currentResult;
    Keyboard.print(currentResult);
    Keyboard.print("");
    delay(250);
  }


if(digitalRead(button3) == LOW) //read buttonpress on button3
  {
   //generate a random number, print it to the Mac
    do {//randomize, but make sure we don't get the same result twice in a row
        currentResult = numbers[random(0,randomNumbers)];
        } while (currentResult == oldResult);
    oldResult = currentResult;
    Keyboard.print(currentResult);
    Keyboard.print("");
    delay(250);
  }

}









Go Up