Go Down

Topic: Bizarre phenomenon happening! Trying to use camera flash w/ Optocouplers & SCR (Read 3 times) previous topic - next topic

carl1864

Does anyone know what is most likely causing such a large delay as described above?

westfw

Most likely source of unexpected delay would be use of "Serial.print()"
Post your code...

carl1864

This is my code, I have a potentiometer to control the threshold, and I have a 2 way switch (which controls the switch case statement).  When I have the switch in one direction it lights an LED so I can test out the threshold and get things just right, when I'm satisfied with the threshold, I switch the switch the other way to activate the flash.

Code: [Select]
int threshold;
int current;
int setting;
int potpin = 0;
int flashpin = 13;
int mic = 5;
int switch1 = 3;
int testpin = 12;

void setup() {
  // put your setup code here, to run once:

}

void loop()
{
  threshold = analogRead(potpin);
  threshold = map(threshold, 0, 1023, 0, 2000);
  current = analogRead(mic);
  setting = digitalRead(switch1);
    switch (setting) {
    case LOW:
        threshold = analogRead(potpin);
        threshold = map(threshold, 0, 1023, 0, 2000);
        current = analogRead(mic);
        if (current > threshold) {digitalWrite(testpin, HIGH);
        delay(100);}
          else digitalWrite(testpin, LOW);
      break;
    case HIGH:
        threshold = analogRead(potpin);
        threshold = map(threshold, 0, 1023, 0, 2000);
        current = analogRead(mic);
        if (current > threshold) {digitalWrite(flashpin, HIGH);
        delay(100);
        digitalWrite(flashpin, LOW);}
         
      break;
   
  }


  }

westfw

Hmm.  I don't see any unintentional delays in there, but I think you should add code to setup() to make the pins you do digitalWrite() on be outputs...  This might explain some of the weird triggering you were seeing, since you'd have some of your pins essentially floating...

Go Up