THE ARDUINO HIGH STRIKER (HAU DEN LUKAS)

Dear Arduinos. :o)

I'm working with friends since a few month on the following project: I want to connect my Arduino "on one side" (INPUT PIN 10) with a light barrier; the "other side" is connected to a remote control (OUT PIN 2-9) from a DVD player. You can find on the DVD we produced 8 chapters from which every second refers to the foregoing chapter (that is you have pairs of chapters: chapter 3 shows a modified version of the "clean" chapter 2; chapter 5 shows a modified version of the "clean" chapter 4 etc.). Last but not least, the remote control is used to control 4 DVD-Players of the same brand. Kind of a high striker...as soon as something crosses the light barrier.

Concerning the programming I work with a function which should control the output and an array to make clear that there's always pairs of videos and, altogether, 6 pairs).

I can't find the error in my programming. Moreover, Arduino starts to upload, but then, nothing happens.

Do you see where the problem could hide?

Big Thanks, Stephan

CODE;

int lightbarrierIN = 10;
int myState = 0;
long Timer;
long DauerNormal = 30000;
long DauerGestoert = 30000;
int numberpairs = 4;
int NowVideo;
int remotePins[][2] = {{2,3},
                               {4,5},
                               {6,7},
                               {8,9}};


void setup()
{
  Serial.begin(9600);
  for (int Info=0; i < numberpairs*2; i++) //
  {
    pinMode(remotePins [Info][0], OUTPUT);
    pinMode(remotePins [Info][1], OUTPUT);
  }
}

void loop()
{
  switch(myState)
  {
    case 0:
      NowVideo = random(0, 3);
      startVideo(NowVideo, 0); //normal video starts
      myState = 1;
    break;
 
    case 1:
      if(millis()-DauerNormal>Timer)
      {
        myState = 0;
      }
         if(digitalRead(lightbarrierIN)==HIGH)
      {
        myState = 2;
      }
    break;
  
    case 2:
      NowVideo = random(0, 3);
      startVideo(NowVideo, 1);
      myState = 3; // distorted video starts
    break;
  
    case 3:
      if(millis()-DauerGestoert>Timer)
      {
        myState = 0; // back to normal
      }
     break;
  }
}

void startVideo(int pairs, int normalORdistorted)
{
  digitalWrite(remotePins[pairs][normalORdistorted],HIGH);
  delay(500);
  digitalWrite(remotePins[pairs][normalORdistorted],LOW);
  Timer = millis();
}

code tags added by moderator

Does this refer to 1 pin, or two:

pinMode ( remotePins [Info][0], OUTPUT);

My guess is that remotePins [ x ] [ y ] would store 2 values, yes?

I didn't think pinMode would assign 2 pins as outputs at one time.

maybe you could try this instead to set up the pins as outputs:

for ( byte Pins = 2; Pins<10; Pins = Pins +1 )
{
pinMode ( Pins, OUTPUT );
}

Also, maybe just a typo in your question,
"I want to connect my Arduino "on one side" (INPUT PIN 12) with a light barrier;"
but pin10 seems to be used vs pin12:

int lightbarrierIN = 10;

Add some Serial.println("message") for debugging. That should give you a clue what your program does step by step in the serial monitor.

My guess is that remotePins [ x ] [ y ] would store 2 values, yes?

No. remotePins is a 2D array. Each element in the array stores one value.

Okay, I guess I don't see how this hits all 8 pins then:

int numberpairs = 4;

int remotePins[][2] = {{2,3},
                               {4,5},
                               {6,7},
                               {8,9}};


void setup()
{
  Serial.begin(9600);
  for (int Info=0; i < numberpairs*2; i++) //
  {
    pinMode(remotePins [Info][0], OUTPUT);
    pinMode(remotePins [Info][1], OUTPUT);
  }
}

(int Info=0; i < numberpairs*2; i++) Info and i would need to the same here, yes?

Okay, I guess I don't see how this hits all 8 pins then

The for loop iterates 8 times, with Info set to 0 to 7. On each iteration, it sets the mode of two pins. That's a total of 16 pins being set - 8 valid and 8 garbage.

The *2 does not belong in the for statement.

Hello Arduinos!

Okay, thanks to your help and few changes in the programming I have stable code here.
Everytime I pass the light barrier, one of the normal videos (1,3,5,7,(9)) moves to the disturbed pair video.

BUT:

a.) I think a made a mistake in using the random function. It choosing only the pairs {2,3},{4,5},{6,7}. The Arduino, after having it work half an hour, never chooses pair {8,9}. I thought always that the random function is 0 indexed, isn't it?

b.) Did I make the right definition here? Before I had it like [][2], but then is miss the vertical values, don't I?

code

int remotePins[4][2] = {{2,3},
{4,5},
{6,7},
{8,9}};

code/

Thank you again for your time and you words. I appreciate it. Meanwhile I will again try to really understand 2D-arrays! :slight_smile:

I thought always that the random function is 0 indexed, isn't it?

The lower bound is inclusive, but the upper bound is exclusive. If you want to be able to generate a 3, the upper bound needs to be 4.

Great, I made it 4 and I works - so cool.
:slight_smile:

Hey Arduinos:

I wanted to ask you again for help in my long time project: The High Striker.

To summarize what's happening: I connected my Arduino to a remote control (by soldering), which enables me to choose between the chapter numbers: 0-9. There is always one video which reponds to the precedent one, this is why I created a 2D array with pairs (2,3;4,5;6,7...)

Now the thing; my code as it is doesn't allow my to adress chapter that demand the use of two inputs (e.g. 10,11,12,...up to 19). Since the DVD I'm using got more chapters than expected, I would like to enlarge the code a little.

Now the question:

Do you see a way (comprehensible for a beginner like me) to bring a pattern which makes it possible to embed these 2-input chapters ?

The code I am working with right now ...:

int lightbarrier = 12;
int myState = 0;
long TimerG;
long TimerN;
long periodNormal = 20000;
long periodDisturbed = 5000;
int pairs = 4; //man könnte hier einfach die Anzahl der Paare ändern, dies würde er dann mit in die For-Schleife nehmen
int Aktuell; // initialisieren
int remotePins[][2] = {{2,3},
                        {4,5},
                        {6,7},
                        {8,9}};


void setup()
{
  Serial.begin(9600);
  for (int i=0; i < pairs; i++) //Es sind stets Paare von zwei Videos
  {
    pinMode(remotePins[i][0], OUTPUT);  //Deklaration aller oben genannten Pins als Output-Pins
    pinMode(remotePins[i][1], OUTPUT);
  }
    pinMode(lightbarrier, INPUT);
}

void loop()
{
  switch(myState)
  {
    case 0: 
      Aktuell = random(0, 4); //number of pairs
      startVideo(Aktuell, 0);
      myState = 1; // played video state
      TimerN = millis();
    break;
  
    case 1: 
      if(millis()-TimerN>periodNormal)
      {
        myState = 0;
      }
      if (digitalRead(lightbarrier)==HIGH)
      {
        myState = 2; // Intervention
      }
    break;
    
    case 2:
      startVideo(Aktuell, 1);
      myState = 3; // played video state
      TimerG = millis();
    break;
    
    case 3:
      if(millis()-TimerG>periodDisturbed)
      {
        myState = 0; // back to state 0
      }
      break;
  }
}

void startVideo(int videoPaar, int gestoertOderNicht) // welches Videopaar wird gesteuert, und welches von diesen beiden wird gestartet (gestört oder normal)
{
  Serial.print(" Choosed pair:");
  Serial.print(remotePins[videoPaar][0]);
  Serial.print(" ,");
  Serial.print(remotePins[videoPaar][1]);
  Serial.println(" ");
  Serial.print("Played is video with pin-number:");
  Serial.print(remotePins[videoPaar][gestoertOderNicht]);
   Serial.print(" ");
  
  digitalWrite(remotePins[videoPaar][gestoertOderNicht],HIGH);
  delay(500);
  digitalWrite(remotePins[videoPaar][gestoertOderNicht],LOW);

}

[\code]

All your "chapter numbers" are just array values, where the array element can hold a value up to 32767. I don't see what the problem is with putting 11, 12, 13, etc. in the array.