Show Posts
Pages: [1] 2 3
1  Using Arduino / Programming Questions / Re: Problem with a timed threshold..... I think? on: November 15, 2012, 12:12:40 pm
John Wasser your obviously a genius, thank you so much everything seems to be working fine now. Like I said we plan on going this Sunday if you are interested?
2  Using Arduino / Programming Questions / Re: Problem with a timed threshold..... I think? on: November 15, 2012, 11:43:13 am
does this look correct now? is this what you where saying to do?

Code:
// These constants won't change:
const int PWRsensor2 = A2;     // was "analogpin" pin - camera PWR sensor is attached to
const int LDR2 = A3;           // was "analogpin1" pin - LDR
const int PWRled2 = 13;        // was "ledpin" pin - camera PWR button is attached to
const int RECled2 = 9;         // was "ledpin1" pin - camera REC button is attached to
const int PWRsensor1 = A0;     // was "analogpin" pin - camera PWR sensor is attached to
const int LDR1 = A1;           // was "analogpin1" pin - LDR
const int PWRled1 = 12;        // was "ledpin" pin - camera PWR button is attached to
const int RECled1 = 8;         // was "ledpin1" pin - camera REC button is attached to
const int threshold = 400;    // threshold for the Camera PWR
const int ledIsOnLevel = 20;  // threshold for the REC LED
const int blinkTime = 5000;

void startRecording1 ()
{

  Serial.println("                                                 Pressing REC BUTTON on Camera 1");
  digitalWrite(RECled1, HIGH);
  delay(500);
  digitalWrite(RECled1, LOW);
  delay(500);
}
void startRecording2 ()
{

  Serial.println("                                                 Pressing REC BUTTON on Camera 2");
  digitalWrite(RECled2, HIGH);
  delay(500);
  digitalWrite(RECled2, LOW);
  delay(500);
}

//---------------------------

void setup()
{
  pinMode(PWRled1, OUTPUT);   // init Camera 1 PWR button = output:
  pinMode(RECled1, OUTPUT);   // init Camera 1 REC button = output:
  pinMode(PWRled2, OUTPUT);   // init Camera 2 PWR button = output:
  pinMode(RECled2, OUTPUT);   // init Camera REC 2 button = output:
  Serial.begin(9600);         // init serial comms:
}

void loop()

  int PWRValue1 = analogRead(PWRsensor1);  // read camera PWR
  int LDRValue1 = analogRead(LDR1);        // read LDR LED
  int PWRValue2 = analogRead(PWRsensor2);  // read camera PWR
  int LDRValue2 = analogRead(LDR2);        // read LDR LED
  // if the analog value is too low, "Press" the PWR button:

  Serial.println("                         Power Reading Camera 1");
  Serial.println(PWRValue1);
  Serial.println("                         Power Reading Camera 2");
  Serial.println(PWRValue2);
  Serial.println("LDR Reading Camera 1");
  Serial.println(LDRValue1, DEC);
  Serial.println("LDR Reading Camera 2");
  Serial.println(LDRValue2, DEC);
  delay(500);

  // if the analog value is too low, "Press" the PWR button:
  if (PWRValue1 < threshold)
  {
    Serial.println("Pressing PWR on Camera 1 in 2 secs; then delay for 5 secs");
    delay(2000);
    digitalWrite(PWRled1, HIGH);
    delay(500);
    digitalWrite(PWRled1, LOW);
    delay(5000);
    Serial.println("Resuming");

  }
  else
  {
    digitalWrite(PWRled1,LOW);
  }


  if (PWRValue2 < threshold)
  {
    Serial.println("Pressing PWR on Camera 2 in 2 secs; then delay for 5 secs");
    delay(2000);
    digitalWrite(PWRled2, HIGH);
    delay(500);
    digitalWrite(PWRled2, LOW);
    delay(5000);
    Serial.println("Resuming");

  }
  else
  {
    digitalWrite(PWRled2,LOW);


  }

  // if the analog value is too low for 3 seconds on Camera 1, "Press" the REC button:
  bool recording1 = false;
  unsigned long blinkStart = millis();
  while(millis() - blinkStart < blinkTime)
  {
    if(analogRead(LDR1) > ledIsOnLevel)

    {
      recording1 = true;
      Serial.println("                                                  Camera 1 is RECORDING");
      break;
    }
  }

  if(!recording1)
  {
    Serial.println("                                                 Camera 1 is  NOT RECORDING");                                  // r_p     
    startRecording1();
  }





  // if the analog value is too low for 3 seconds on Camera 2, "Press" the REC button:
  bool recording2 = false;
  blinkStart = millis();
  while(millis() - blinkStart < blinkTime)
  {
    if(analogRead(LDR2) > ledIsOnLevel)

    {
      recording2 = true;
      Serial.println("                                             Camera 2 is RECORDING");
      break;
    }
  }

  if(!recording2)
  {
    Serial.println("                                                 Camera 2 is NOT RECORDING");                                   // r_p     
    startRecording2();     
    // print the analog value:
  }                                 // r_p

  Serial.println("End of Loop");
}


3  Using Arduino / Programming Questions / Re: Problem with a timed threshold..... I think? on: November 15, 2012, 11:35:08 am
John Wasser I AM VERY HAPPY TO SEE YOU ON HERE. we are going this Sunday if you are interested. I got my ham radio license and we are using an APRS tracking device this time.
4  Using Arduino / Programming Questions / Re: Problem with a timed threshold..... I think? on: November 15, 2012, 11:33:19 am
will do; sorry i wasnt aware of that and please let me know if theres anything else you need to know or anything. THANK YOU.

Code:
// These constants won't change:
const int PWRsensor2 = A2;     // was "analogpin" pin - camera PWR sensor is attached to
const int LDR2 = A3;           // was "analogpin1" pin - LDR
const int PWRled2 = 13;        // was "ledpin" pin - camera PWR button is attached to
const int RECled2 = 9;         // was "ledpin1" pin - camera REC button is attached to
const int PWRsensor1 = A0;     // was "analogpin" pin - camera PWR sensor is attached to
const int LDR1 = A1;           // was "analogpin1" pin - LDR
const int PWRled1 = 12;        // was "ledpin" pin - camera PWR button is attached to
const int RECled1 = 8;         // was "ledpin1" pin - camera REC button is attached to
const int threshold = 400;    // threshold for the Camera PWR
const int ledIsOnLevel = 20;  // threshold for the REC LED
const int blinkTime = 5000;

void startRecording1 ()
{

  Serial.println("                                                 Pressing REC BUTTON on Camera 1");
  digitalWrite(RECled1, HIGH);
  delay(500);
  digitalWrite(RECled1, LOW);
  delay(500);
}
void startRecording2 ()
{

  Serial.println("                                                 Pressing REC BUTTON on Camera 2");
  digitalWrite(RECled2, HIGH);
  delay(500);
  digitalWrite(RECled2, LOW);
  delay(500);
}

//---------------------------

void setup()
{
  pinMode(PWRled1, OUTPUT);   // init Camera 1 PWR button = output:
  pinMode(RECled1, OUTPUT);   // init Camera 1 REC button = output:
  pinMode(PWRled2, OUTPUT);   // init Camera 2 PWR button = output:
  pinMode(RECled2, OUTPUT);   // init Camera REC 2 button = output:
  Serial.begin(9600);         // init serial comms:
}

void loop()

  int PWRValue1 = analogRead(PWRsensor1);  // read camera PWR
  int LDRValue1 = analogRead(LDR1);        // read LDR LED
  int PWRValue2 = analogRead(PWRsensor2);  // read camera PWR
  int LDRValue2 = analogRead(LDR2);        // read LDR LED
  // if the analog value is too low, "Press" the PWR button:

  Serial.println("                         Power Reading Camera 1");
  Serial.println(PWRValue1);
  Serial.println("                         Power Reading Camera 2");
  Serial.println(PWRValue2);
  Serial.println("LDR Reading Camera 1");
  Serial.println(LDRValue1, DEC);
  Serial.println("LDR Reading Camera 2");
  Serial.println(LDRValue2, DEC);
  delay(500);

  // if the analog value is too low, "Press" the PWR button:
  if (PWRValue1 < threshold)
  {
    Serial.println("Pressing PWR on Camera 1 in 2 secs; then delay for 5 secs");
    delay(2000);
    digitalWrite(PWRled1, HIGH);
    delay(500);
    digitalWrite(PWRled1, LOW);
    delay(5000);
    Serial.println("Resuming");

  }
  else
  {
    digitalWrite(PWRled1,LOW);
  }


  if (PWRValue2 < threshold)
  {
    Serial.println("Pressing PWR on Camera 2 in 2 secs; then delay for 5 secs");
    delay(2000);
    digitalWrite(PWRled2, HIGH);
    delay(500);
    digitalWrite(PWRled2, LOW);
    delay(5000);
    Serial.println("Resuming");

  }
  else
  {
    digitalWrite(PWRled2,LOW);


  }

  // if the analog value is too low for 3 seconds on Camera 1, "Press" the REC button:
  bool recording1 = false;
  unsigned long blinkStart = millis();
  while(millis() - blinkStart < blinkTime)
  {
    if(analogRead(LDR1) > ledIsOnLevel)

    {
      recording1 = true;
      Serial.println("                                                  Camera 1 is RECORDING");
      break;
    }
  }

  if(!recording1)
  {
    Serial.println("                                                 Camera 1 is  NOT RECORDING");                                  // r_p     
    startRecording1();
  }





  // if the analog value is too low for 3 seconds on Camera 1, "Press" the REC button:
  bool recording2 = false;

  while(millis() - blinkStart < blinkTime)
  {
    if(analogRead(LDR2) > ledIsOnLevel)

    {
      recording2 = true;
      Serial.println("                                             Camera 2 is RECORDING");
      break;
    }
  }

  if(!recording2)
  {
    Serial.println("                                                 Camera 2 is NOT RECORDING");                                   // r_p     
    startRecording2();     
    // print the analog value:
  }                                 // r_p

  Serial.println("End of Loop");
}



I think this is what you where saying to do, if not please let me know.
5  Using Arduino / Programming Questions / Problem with a timed threshold..... I think? on: November 15, 2012, 11:09:46 am
Hello, I am trying to have an arduino uno control 2 cameras and ensure that they constantly stay on and constanlty record. I have wired the arduino to internal parts of the camera such as the rec button, the power button, an internal power line and i have setup a LDR to the blinking LED on the camera that flashes when it records. I have had a lot of help with the software and I believe it was working fine; but it has sat in my basement for a few years due to having kids and work, but I am trying to get it back up and running now so I can attach these to a weather balloon this Sunday. I have powered it up but it seems like it is only taking the reading of the blinking LED on the camera for a split second but I would like it to monitor the blinking LED for a few seconds (perhaps anywhere from 5-10) and if the LED does not come on I would then like it to send a signal to the REC Button to record; but like i said it seems to just be taking 1 reading and if it happens to take that reading while the LED is blinking and in the off state it hits the REC button. any help would be GREATLY APPRECIATED. Like I said I don't really know what I'm doing here so if i have left out any information that you may need just let me know. Also I can provide pictures or video or anything you may need or we could even video conference if that makes it easier. Please let me know.

 
// These constants won't change:
const int PWRsensor2 = A2;     // was "analogpin" pin - camera PWR sensor is attached to
const int LDR2 = A3;           // was "analogpin1" pin - LDR
const int PWRled2 = 13;        // was "ledpin" pin - camera PWR button is attached to
const int RECled2 = 9;         // was "ledpin1" pin - camera REC button is attached to
const int PWRsensor1 = A0;     // was "analogpin" pin - camera PWR sensor is attached to
const int LDR1 = A1;           // was "analogpin1" pin - LDR
const int PWRled1 = 12;        // was "ledpin" pin - camera PWR button is attached to
const int RECled1 = 8;         // was "ledpin1" pin - camera REC button is attached to
const int threshold = 400;    // threshold for the Camera PWR
const int ledIsOnLevel = 20;  // threshold for the REC LED
const int blinkTime = 5000;

void startRecording1 ()
{

  Serial.println("                                                 Pressing REC BUTTON on Camera 1");
  digitalWrite(RECled1, HIGH);
  delay(500);
  digitalWrite(RECled1, LOW);
  delay(500);
}
void startRecording2 ()
{

  Serial.println("                                                 Pressing REC BUTTON on Camera 2");
  digitalWrite(RECled2, HIGH);
  delay(500);
  digitalWrite(RECled2, LOW);
  delay(500);
}

//---------------------------

void setup()
{
  pinMode(PWRled1, OUTPUT);   // init Camera 1 PWR button = output:
  pinMode(RECled1, OUTPUT);   // init Camera 1 REC button = output:
  pinMode(PWRled2, OUTPUT);   // init Camera 2 PWR button = output:
  pinMode(RECled2, OUTPUT);   // init Camera REC 2 button = output:
  Serial.begin(9600);         // init serial comms:
}

void loop()

  int PWRValue1 = analogRead(PWRsensor1);  // read camera PWR
  int LDRValue1 = analogRead(LDR1);        // read LDR LED
  int PWRValue2 = analogRead(PWRsensor2);  // read camera PWR
  int LDRValue2 = analogRead(LDR2);        // read LDR LED
  // if the analog value is too low, "Press" the PWR button:

  Serial.println("                         Power Reading Camera 1");
  Serial.println(PWRValue1);
  Serial.println("                         Power Reading Camera 2");
  Serial.println(PWRValue2);
  Serial.println("LDR Reading Camera 1");
  Serial.println(LDRValue1, DEC);
  Serial.println("LDR Reading Camera 2");
  Serial.println(LDRValue2, DEC);
  delay(500);

  // if the analog value is too low, "Press" the PWR button:
  if (PWRValue1 < threshold)
  {
    Serial.println("Pressing PWR on Camera 1 in 2 secs; then delay for 5 secs");
    delay(2000);
    digitalWrite(PWRled1, HIGH);
    delay(500);
    digitalWrite(PWRled1, LOW);
    delay(5000);
    Serial.println("Resuming");

  }
  else
  {
    digitalWrite(PWRled1,LOW);
  }


  if (PWRValue2 < threshold)
  {
    Serial.println("Pressing PWR on Camera 2 in 2 secs; then delay for 5 secs");
    delay(2000);
    digitalWrite(PWRled2, HIGH);
    delay(500);
    digitalWrite(PWRled2, LOW);
    delay(5000);
    Serial.println("Resuming");

  }
  else
  {
    digitalWrite(PWRled2,LOW);


  }

  // if the analog value is too low for 3 seconds on Camera 1, "Press" the REC button:
  bool recording1 = false;
  unsigned long blinkStart = millis();
  while(millis() - blinkStart < blinkTime)
  {
    if(analogRead(LDR1) > ledIsOnLevel)

    {
      recording1 = true;
      Serial.println("                                                  Camera 1 is RECORDING");
      break;
    }
  }

  if(!recording1)
  {
    Serial.println("                                                 Camera 1 is  NOT RECORDING");                                  // r_p     
    startRecording1();
  }

 
 
  // if the analog value is too low for 3 seconds on Camera 1, "Press" the REC button:
  bool recording2 = false;

  while(millis() - blinkStart < blinkTime)
  {
    if(analogRead(LDR2) > ledIsOnLevel)

    {
      recording2 = true;
      Serial.println("                                             Camera 2 is RECORDING");
      break;
    }
  }

  if(!recording2)
  {
    Serial.println("                                                 Camera 2 is NOT RECORDING");                                   // r_p     
    startRecording2();     
    // print the analog value:
  }                                 // r_p

  Serial.println("End of Loop");
}

6  Using Arduino / Programming Questions / Re: Millis - Something out of order? on: December 23, 2011, 07:16:16 pm
I copied the code and moved the indent over but when I compiled it, it highlighted this line

    unsigned long blinkStart = millis();

and said " redeclaration of 'long unsigned int blinkStart'

Code:
if(analogRead(LDR1) > ledIsOnLevel)

    {
      recording1 = true;
      Serial.println("                                                  Camera 1 is RECORDING");
      break;
    }
  }

  if(!recording1)
  {
    Serial.println("                                                 Camera 1 is  NOT RECORDING");                                  // r_p     
    startRecording1();
  }
 



    // if the analog value is too low for 3 seconds on Camera 1, "Press" the REC button:
    bool recording2 = false;
    unsigned long blinkStart = millis();
    while(millis() - blinkStart < blinkTime)
    {
      if(analogRead(LDR2) > ledIsOnLevel)

      {
        recording2 = true;
        Serial.println("                                             Camera 2 is RECORDING");
        break;
      }
    }

    if(!recording2)
    {
      Serial.println("                                                 Camera 2 is NOT RECORDING");                                   // r_p     
      startRecording2();     
      // print the analog value:
    }                                 // r_p
  }
  Serial.println("End of Loop");
}

I don't know if i did somehting wrong or not
7  Using Arduino / Programming Questions / Re: Millis - Something out of order? on: December 23, 2011, 05:05:13 pm
The area of code that you said was not independant like I would seem to want, I had help with that and i don't even know what it says there. can you tell me exactly what i need to change to make it independant? I can't read it nevermind fix it smiley
8  Using Arduino / Programming Questions / Re: Millis - Something out of order? on: December 19, 2011, 09:39:22 pm
Thank you for the advice I have used to auto format and it is much neater now. I have googled "functions" but I couldnt figure out how to set 1 function to different pin numbers smiley-sad  I have put a few more "Serial.println" commands in to try to get a sense of what is going on. The camera power seems to work great and  independantly just like I want. The "RECORD BUTTON" doesn't seem to work unless both cameras stop recording. It looks like it's not even making to "Check to see if camera 2 is recording" part. I have included the "Serial Window" text too. Just wondering what I need to change to make this thing work.

Code:
// These constants won't change:
const int PWRsensor2 = A2;     // was "analogpin" pin - camera PWR sensor is attached to
const int LDR2 = A3;           // was "analogpin1" pin - LDR
const int PWRled2 = 13;        // was "ledpin" pin - camera PWR button is attached to
const int RECled2 = 9;         // was "ledpin1" pin - camera REC button is attached to
const int PWRsensor1 = A0;     // was "analogpin" pin - camera PWR sensor is attached to
const int LDR1 = A1;           // was "analogpin1" pin - LDR
const int PWRled1 = 12;        // was "ledpin" pin - camera PWR button is attached to
const int RECled1 = 8;         // was "ledpin1" pin - camera REC button is attached to
const int threshold = 400;    // threshold for the Camera PWR
const int ledIsOnLevel = 20;  // threshold for the REC LED
const int blinkTime = 5000;

void startRecording1 ()
{

  Serial.println("                                                 Pressing REC BUTTON on Camera 1");
  digitalWrite(RECled1, HIGH);
  delay(500);
  digitalWrite(RECled1, LOW);
  delay(500);
}
void startRecording2 ()
{

  Serial.println("                                                 Pressing REC BUTTON on Camera 2");
  digitalWrite(RECled2, HIGH);
  delay(500);
  digitalWrite(RECled2, LOW);
  delay(500);
}

//---------------------------

void setup()
{
  pinMode(PWRled1, OUTPUT);   // init Camera 1 PWR button = output:
  pinMode(RECled1, OUTPUT);   // init Camera 1 REC button = output:
  pinMode(PWRled2, OUTPUT);   // init Camera 2 PWR button = output:
  pinMode(RECled2, OUTPUT);   // init Camera REC 2 button = output:
  Serial.begin(9600);         // init serial comms:
}

void loop()

  int PWRValue1 = analogRead(PWRsensor1);  // read camera PWR
  int LDRValue1 = analogRead(LDR1);        // read LDR LED
  int PWRValue2 = analogRead(PWRsensor2);  // read camera PWR
  int LDRValue2 = analogRead(LDR2);        // read LDR LED
  // if the analog value is too low, "Press" the PWR button:

  Serial.println("                         Power Reading Camera 1");
  Serial.println(PWRValue1);
  Serial.println("                         Power Reading Camera 2");
  Serial.println(PWRValue2);
  Serial.println("LDR Reading Camera 1");
  Serial.println(LDRValue1, DEC);
  Serial.println("LDR Reading Camera 2");
  Serial.println(LDRValue2, DEC);
  delay(500);

  // if the analog value is too low, "Press" the PWR button:
  if (PWRValue1 < threshold)
  {
    Serial.println("Pressing PWR on Camera 1 in 2 secs; then delay for 5 secs");
    delay(2000);
    digitalWrite(PWRled1, HIGH);
    delay(500);
    digitalWrite(PWRled1, LOW);
    delay(5000);
    Serial.println("Resuming");

  }
  else
  {
    digitalWrite(PWRled1,LOW);
  }


  if (PWRValue2 < threshold)
  {
    Serial.println("Pressing PWR on Camera 2 in 2 secs; then delay for 5 secs");
    delay(2000);
    digitalWrite(PWRled2, HIGH);
    delay(500);
    digitalWrite(PWRled2, LOW);
    delay(5000);
    Serial.println("Resuming");

  }
  else
  {
    digitalWrite(PWRled2,LOW);


  }

  // if the analog value is too low for 3 seconds on Camera 1, "Press" the REC button:
  bool recording1 = false;
  unsigned long blinkStart = millis();
  while(millis() - blinkStart < blinkTime)
  {
    if(analogRead(LDR1) > ledIsOnLevel)

    {
      recording1 = true;
      Serial.println("                                                  Camera 1 is RECORDING");
      break;
    }
  }

  if(!recording1)
  {
    Serial.println("                                                 Camera 1 is  NOT RECORDING");                                  // r_p     
    startRecording1();





    // if the analog value is too low for 3 seconds on Camera 1, "Press" the REC button:
    bool recording2 = false;
    unsigned long blinkStart = millis();
    while(millis() - blinkStart < blinkTime)
    {
      if(analogRead(LDR2) > ledIsOnLevel)

      {
        recording2 = true;
        Serial.println("                                             Camera 2 is RECORDING");
        break;
      }
    }

    if(!recording2)
    {
      Serial.println("                                                 Camera 2 is NOT RECORDING");                                   // r_p     
      startRecording2();     
      // print the analog value:
    }                                 // r_p
  }
  Serial.println("End of Loop");
}







and here is the Serial Window


Code:
Power Reading Camera 1
502
                         Power Reading Camera 2
518
LDR Reading Camera 1
32
LDR Reading Camera 2
500
                                                  Camera 1 is RECORDING
End of Loop
                         Power Reading Camera 1
501
                         Power Reading Camera 2
531
LDR Reading Camera 1
24
LDR Reading Camera 2
13
                                                  Camera 1 is RECORDING
End of Loop
                         Power Reading Camera 1
542
                         Power Reading Camera 2
517
LDR Reading Camera 1
32
LDR Reading Camera 2
501
                                                  Camera 1 is RECORDING
End of Loop
                         Power Reading Camera 1
526
                         Power Reading Camera 2
526
LDR Reading Camera 1
24
LDR Reading Camera 2
13
                                                  Camera 1 is RECORDING
End of Loop
                         Power Reading Camera 1
498
                         Power Reading Camera 2
523
LDR Reading Camera 1
32
LDR Reading Camera 2
504
                                                  Camera 1 is RECORDING
End of Loop
                         Power Reading Camera 1
493
                         Power Reading Camera 2
512
LDR Reading Camera 1
24
LDR Reading Camera 2
14
                                                  Camera 1 is RECORDING
End of Loop
                         Power Reading Camera 1
541
                         Power Reading Camera 2
528
LDR Reading Camera 1
32
LDR Reading Camera 2
504
                                                  Camera 1 is RECORDING
End of Loop
                         Power Reading Camera 1
538
                         Power Reading Camera 2
521
LDR Reading Camera 1
24
LDR Reading Camera 2
13
                                                  Camera 1 is RECORDING
End of Loop
9  Using Arduino / Programming Questions / Re: Millis - Something out of order? on: December 18, 2011, 04:49:35 pm
Thank you, once I fixed those 2 things it seemd to work great. I went ahead and tried to just double it up to add the second camera, but the 2 cameras don't seem to work independantly. I mean if 1 camera stops recording the arduino will not make it start recording again until the other cameras also fails. Can someone tell me where I have gone wrong with the following code please. I think maybe in "bool recording" command, or maybe the "void startRecording1 () or 2?" (can u have 2 of those or is it a different command?) but I'm not sure how to do it any other way.



Code:
// These constants won't change:
const int PWRsensor2 = A2;     // was "analogpin" pin - camera PWR sensor is attached to
const int LDR2 = A3;           // was "analogpin1" pin - LDR
const int PWRled2 = 13;        // was "ledpin" pin - camera PWR button is attached to
const int RECled2 = 9;         // was "ledpin1" pin - camera REC button is attached to
const int PWRsensor1 = A0;     // was "analogpin" pin - camera PWR sensor is attached to
const int LDR1 = A1;           // was "analogpin1" pin - LDR
const int PWRled1 = 12;        // was "ledpin" pin - camera PWR button is attached to
const int RECled1 = 8;         // was "ledpin1" pin - camera REC button is attached to
const int threshold = 400;    // threshold for the Camera PWR
const int ledIsOnLevel = 20;  // threshold for the REC LED
const int blinkTime = 5000;

void startRecording1 ()
{
   
    Serial.println("Pressing REC BUTTON on Camera 1");
    digitalWrite(RECled1, HIGH);
    delay(500);
    digitalWrite(RECled1, LOW);
    delay(500);
}
void startRecording2 ()
{
   
    Serial.println("Pressing REC BUTTON on Camera 2");
    digitalWrite(RECled2, HIGH);
    delay(500);
    digitalWrite(RECled2, LOW);
    delay(500);
}

//---------------------------

void setup()
{
   pinMode(PWRled1, OUTPUT);   // init Camera 1 PWR button = output:
   pinMode(RECled1, OUTPUT);  // init Camera 1 REC button = output:
   pinMode(PWRled2, OUTPUT);   // init Camera 2 PWR button = output:
   pinMode(RECled2, OUTPUT);  // init Camera REC 2 button = output:
   Serial.begin(9600);        // init serial comms:
}

void loop()

  int PWRValue1 = analogRead(PWRsensor1);  // read camera PWR
  int LDRValue1 = analogRead(LDR1);       // read LDR LED
  int PWRValue2 = analogRead(PWRsensor2);  // read camera PWR
  int LDRValue2 = analogRead(LDR2);       // read LDR LED
  // if the analog value is too low, "Press" the PWR button:
 
  Serial.println("Power Reading Camera 1");
  Serial.println(PWRValue1, DEC);
  Serial.println("LDR Reading Camera 1");
  Serial.println(LDRValue1, DEC);
  Serial.println("                    Power Reading Camera 2");
  Serial.println(PWRValue2, DEC);
  Serial.println("                    LDR Reading Camera 2");
  Serial.println(LDRValue2, DEC);
  delay(500);
 
   // if the analog value is too low, "Press" the PWR button:
  if (PWRValue1 < threshold)
  {
    Serial.println("Pressing PWR on Camera 1 in 2 secs; then delay for 5 secs");
    delay(2000);
    digitalWrite(PWRled1, HIGH);
    delay(500);
    digitalWrite(PWRled1, LOW);
    delay(5000);
    Serial.println("Resuming");
 
  }
  else
  {
    digitalWrite(PWRled1,LOW);
   
   
    if (PWRValue2 < threshold)
  {
    Serial.println("Pressing PWR on Camera 2 in 2 secs; then delay for 5 secs");
    delay(2000);
    digitalWrite(PWRled2, HIGH);
    delay(500);
    digitalWrite(PWRled2, LOW);
    delay(5000);
    Serial.println("Resuming");
 
  }
  else
  {
    digitalWrite(PWRled2,LOW);
   
 
  }

  // if the analog value is too low for 3 seconds on Camera 1, "Press" the REC button:
  bool recording = false;
  unsigned long blinkStart = millis();
  while(millis() - blinkStart < blinkTime)
   {
     if(analogRead(LDR1) > ledIsOnLevel)
     
     {
       recording = true;
       break;
     }
   }

  if(!recording)
    {                                   // r_p     
      startRecording1();

// if the analog value is too low for 3 seconds on Camera 1, "Press" the REC button:
  bool recording = false;
  unsigned long blinkStart = millis();
  while(millis() - blinkStart < blinkTime)
   {
     if(analogRead(LDR2) > ledIsOnLevel)
     
     {
       recording = true;
       break;
     }
   }

  if(!recording)
    {                                   // r_p     
      startRecording2();     
   
          }                                 // r_p
}}}

any help would be great thank you
10  Using Arduino / Programming Questions / Re: Millis - Something out of order? on: December 15, 2011, 07:14:48 pm
I Have had a little help and have had the names cleaned up, this is the new code.




Code:
// These constants won't change:
const int PWRsensor = A0;     // was "analogpin" pin - camera PWR sensor is attached to
const int LDR = A1;           // was "analogpin1" pin - LDR
const int PWRled = 12;        // was "ledpin" pin - camera PWR button is attached to
const int RECled = 8;         // was "ledpin1" pin - camera REC button is attached to
const int threshold = 475;    // threshold for the Camera PWR
const int ledIsOnLevel = 15;  // threshold for the REC LED
const int blinkTime = 000;

void startRecording ()
{
   
    Serial.println("Pressing REC BUTTON");
    digitalWrite(RECled, HIGH);
    delay(500);
    digitalWrite(RECled, LOW);
    delay(500);
}

//---------------------------

void setup()
{
   pinMode(PWRled, OUTPUT);   // init Camera PWR button = output:
   pinMode(RECled, OUTPUT);  // init Camera REC button = output:
   Serial.begin(9600);        // init serial comms:
}

void loop()

  int PWRValue = analogRead(PWRsensor);  // read camera PWR
  int LDRValue = analogRead(LDR);       // read LDR LED
  // if the analog value is too low, "Press" the PWR button:
  if (PWRValue < threshold)
  {
    Serial.println("Pressing PWR in 2 secs; then delay for 5 secs");
    delay(2000);
    digitalWrite(PWRled, HIGH);
    delay(500);
    digitalWrite(PWRled, LOW);
    Serial.println(PWRValue, DEC);
    Serial.println(LDRValue, DEC);
    delay(5000);
    Serial.println("Resuming");
    Serial.println(PWRValue, DEC);
    Serial.println(LDRValue, DEC);
  }
  else
  {
    digitalWrite(PWRled,LOW);
   
 
  }

  // if the analog value is too low for 3 second, "Press" the REC button:
  bool recording = false;
  unsigned long blinkStart = millis();
  while(millis() - blinkStart < blinkTime)
   {
     if(analogRead(PWRled) > ledIsOnLevel)
     {
       recording = true;
       break;
     }
   }

  if(!recording)
    {                                   // r_p     
      startRecording();         
      // print the analog value:
      Serial.println(PWRValue, DEC);
      Serial.println(LDRValue, DEC);
    }                                 // r_p
}

But something is definitely not right. It seems like I have done something wrong with the REC BUT. It seems to be pressed every second for some reason> i am trying to have the LDR sensor monitor the blinking led on the front of the camera and I want the arduino to press the REC BUT if the blinking rec LED on the front of the camera stays under a threshold for a set amount of time; but it seems to not really be paying attention to what the blinking rec LED on the front of the camera is doing and it seems to just hit the REC BUT every second or so. This is what the Serial window is displaying

Code:
Pressing REC BUTTON
671
43
Pressing REC BUTTON
672
536
Pressing REC BUTTON
671
19
Pressing REC BUTTON
672
11
Pressing REC BUTTON
672
536
Pressing REC BUTTON
671
19
Pressing REC BUTTON
671
537
Pressing REC BUTTON
672
18
Pressing REC BUTTON
672
11
Pressing REC BUTTON
672
536
Pressing REC BUTTON
671
19
Pressing REC BUTTON
671
536
Pressing REC BUTTON
671
18
Pressing REC BUTTON
672
11
Pressing REC BUTTON
671
536
Pressing REC BUTTON
672
18
Pressing REC BUTTON
672
536
Pressing REC BUTTON
671
18
Pressing REC BUTTON
671
11
Pressing REC BUTTON
672
535
Pressing REC BUTTON
672
18
Pressing REC BUTTON
672
536
Pressing REC BUTTON
672
18
Pressing REC BUTTON
672
11
Pressing REC BUTTON
671
535
Pressing REC BUTTON
671
17
Pressing REC BUTTON
Can you suggest anything that I need to change or rearrange?
11  Using Arduino / Programming Questions / Millis - Something out of order? on: December 13, 2011, 12:37:59 pm
I am trying to have an arduino turn on and ensure a camcorder is continously recording, I have been getting a lot of help from these forums, and I think I may have put something in the wrong order in the code. For the "Record" function I am trying to have a LDR monitor a blinking LED. I am trying to make the LDR watch the blink of the LED and if it goes under a threshold for a set amount of time (which i thought was this - const int blinkTime = 3000;) I was trying to make it press the "Record" button, but it seems that it is pressing the "record" button right away and then pausing for that amount of time. I'm wondering if someone can tell me where I went wrong here please?


Code:
// These constants won't change:
const int analogPin = A0;    // pin that the camera PWR sensor is attached to
const int analogPin1 = A1;    // pin that the LDR is connected to
const int ledPin = 12;       // pin that the camera PWR button is attached to
const int ledPin1 = 8;        // pin that the camera REC button is attached to
const int threshold = 475;   // an arbitrary threshold level for the Camera PWR
const int ledIsOnLevel = 15;  // an arbitrary threshold level for the REC LED
const int blinkTime = 3000;
void startRecording ()
{
    Serial.println("Pressing REC BUTTON");
    digitalWrite(ledPin1, HIGH);
    delay(500);
    digitalWrite(ledPin1, LOW);
    delay(500);
  }
 


void setup() {
   pinMode(ledPin, OUTPUT);  // initialize the Camera PWR button as an output:
   pinMode(ledPin1, OUTPUT);  // initialize the Camera REC button as an output:
 
  Serial.begin(9600);        // initialize serial communications:
}

void loop() {
  // read the value of the camera PWR:
  int analogValue = analogRead(analogPin);
  // read the value of the LDR LED:
  int analogValue1 = analogRead(analogPin1);
 

  // if the analog value is too low, "Press" the PWR button:
  if (analogValue < threshold) {
    Serial.println("Pressing PWR in 2 seconds; then delay for 5 seconds");
    delay(2000);
    digitalWrite(ledPin, HIGH);
    delay(500);
    digitalWrite(ledPin, LOW);
    delay(5000);
  }
  else {
    digitalWrite(ledPin,LOW);
  }


// if the analog value is too low for 3 second, "Press" the REC button:
  bool recording = false;
unsigned long blinkStart = millis();
while(millis() - blinkStart < blinkTime)
{
   if(analogRead(ledPin) > ledIsOnLevel)
   {
     recording = true;
     break;
  }
}

if(!recording)
  startRecording();
   
   

  // print the analog value:
  Serial.println(analogValue, DEC);
  Serial.println(analogValue1, DEC);

}
12  Using Arduino / Programming Questions / Re: Need a little guidance with "If Statement" please on: December 10, 2011, 12:38:45 pm
WOW!! It appears as though the arduino is doing what I had hoped it would!! Thank you guys soo much for all the help. Especially for taking the time to help such a beginner like myself who sometimes doesnt understand the simplest of directions.
13  Using Arduino / Programming Questions / Re: Need a little guidance with "If Statement" please on: December 10, 2011, 11:15:02 am
right, I just didn't know how. I posted an example of what I tried but it didn't work. I should have been more clear, I'm actually trying to find out how to do that.
14  Using Arduino / Programming Questions / Re: Need a little guidance with "If Statement" please on: December 10, 2011, 10:42:14 am
Thank you for the millis command! smiley I originally wanted to use millis but I didn't know how. Also I'm sorry about the names but I don't know what I'm allowed to change them to or exactly what I am allowed to change and what I'm not allowed to change, I am trying to stumble my way through this and what I do have so far is basically just copied and pasted from tutorials. I THINK I have entered the code u wrote into the sketch correctly but I think i maybe need to define the "startRecording" command. I tried to list it at the top with the other "int" similiar to this

Code:
startRecording();
    digitalWrite(ledPin, HIGH);
    delay(500);
    digitalWrite(ledPin, LOW);
    delay(5000);

but that wasn't right. here it what it now looks like

Code:
// These constants won't change:
const int analogPin = A0;    // pin that the camera PWR sensor is attached to
const int analogPin1 = A1;    // pin that the LDR is connected to
const int ledPin = 12;       // pin that the camera PWR button is attached to
const int ledPin1 = 8;        // pin that the camera REC button is attached to
const int threshold = 475;   // an arbitrary threshold level for the Camera PWR
const int ledIsOnLevel = 100;  // an arbitrary threshold level for the REC LED
const int blinkTime = 3000;

void setup() {
   pinMode(ledPin, OUTPUT);  // initialize the Camera PWR button as an output:
   pinMode(ledPin1, OUTPUT);  // initialize the Camera REC button as an output:
 
  Serial.begin(9600);        // initialize serial communications:
}

void loop() {
  // read the value of the camera PWR:
  int analogValue = analogRead(analogPin);
  // read the value of the LDR LED:
  int analogValue1 = analogRead(analogPin1);
 

  // if the analog value is too low, "Press" the PWR button:
  if (analogValue < threshold) {
    Serial.println("Pressing PWR in 2 seconds; then delay for 5 seconds");
    delay(2000);
    digitalWrite(ledPin, HIGH);
    delay(500);
    digitalWrite(ledPin, LOW);
    delay(5000);
  }
  else {
    digitalWrite(ledPin,LOW);
  }


// if the analog value is too low for 3 second, "Press" the REC button:
  bool recording = false;
unsigned long blinkStart = millis();
while(millis() - blinkStart < blinkTime)
{
   if(analogRead(ledPin) > ledIsOnLevel)
   {
     recording = true;
     break;
  }
}

if(!recording)
  startRecording();
   
    digitalWrite(ledPin1, HIGH);
    delay(500);
    digitalWrite(ledPin1, LOW);
    delay(500);
  }
  else {
    digitalWrite(ledPin1,LOW);
  }

  // print the analog value:
  Serial.println(analogValue, DEC);
  Serial.println(analogValue1, DEC);

}

'startRecording' was not declared in this scope.

I'm sure it must be frustrating to work with me, but I do appreciate this help thank you
15  Using Arduino / Programming Questions / Need a little guidance with "If Statement" please on: December 10, 2011, 09:50:16 am
I'm trying to have a LDR monitor a blinking LED on a camera to let the Arduino know if it is recording or not. I am trying to have the arduino take 5 readings at different times to make sure it is not just taking a reading while the LED is off in the middle of a blink. I would like it to take a reading and if it is below the set threshold I would like it to take another reading and so on. If the reading is above the set threshold I would like it to stop taking readings and continue the program loop starting the "reading counter" back at 0.


Code:
void loop() {
  // read the value of the camera PWR:
  int analogValue = analogRead(analogPin);
  // read the value of the LDR LED:
  int analogValue1 = analogRead(analogPin1);
 

  // if the analog value is too low, "Press" the PWR button:
  if (analogValue < threshold) {
    Serial.println("Pressing PWR in 2 seconds; then delay for 5 seconds");
    delay(2000);
    digitalWrite(ledPin, HIGH);
    delay(500);
    digitalWrite(ledPin, LOW);
    delay(5000);
  }
  else {
    digitalWrite(ledPin,LOW);
  }


// if the analog value is too low, "Press" the REC button:
  if (analogValue1 < threshold1) {
    Serial.println("LED detection failed 1st check");
    Serial.println(analogValue1, DEC);
    delay(1700);
   
    analogValue1 = analogRead(analogPin1);
        if (analogValue1 < threshold1)
    Serial.println("LED detection failed 2nd check");
    Serial.println(analogValue1, DEC);
    delay(1700);
   

    analogValue1 = analogRead(analogPin1);
    if (analogValue1 < threshold1)
    Serial.println("LED detection failed 3rd check");
    Serial.println(analogValue1, DEC);
    delay(1700);
   
   
    analogValue1 = analogRead(analogPin1);
    if (analogValue1 < threshold1)
    Serial.println("LED detection failed 4th check");
    Serial.println(analogValue1, DEC);
    delay(1700);
   
   
    analogValue1 = analogRead(analogPin1);
    if (analogValue1 < threshold1)
    Serial.println("LED detection failed 5th check, pressing REC BUT in 2 seconds");
    Serial.println(analogValue1, DEC);
    delay(2000);
   
   
    digitalWrite(ledPin1, HIGH);
    delay(500);
    digitalWrite(ledPin1, LOW);
    delay(500);
  }
  else {
    digitalWrite(ledPin1,LOW);
  }

I believe i need some sort of code to do something similiar to this:

if (analogValue1 > threshold1) goto beginning of loop

but i'm just not to sure of how to write it. Any help or suggestions would be greatly appreciated. Thank you
Pages: [1] 2 3