Pages: 1 [2]   Go Down
Author Topic: Bizarre phenomenon happening! Trying to use camera flash w/ Optocouplers & SCR  (Read 2418 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 2
Posts: 98
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 106
Posts: 6378
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Jr. Member
**
Karma: 2
Posts: 98
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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;
   
  }


  }
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 106
Posts: 6378
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
Logged

Pages: 1 [2]   Go Up
Jump to: