Hello
I am outputing in 2 pins: pin_9 and pin_8, when pin_12 is set to HIGH.
When I output in pin_9 only, signal behaves well (image_1 attached)
but when I try to output in pin_8 after pin_9, the signal doesn't come neat (seems like it comes with noise) (image_2 attached)
The upper windows in the images is the signal that activates the arduino in pin_12
the bottom window is the output in pin_9.
I am sensing only the pin_9, so I think I should see the signal as in image_1
and after when I change the sensor to pin_8, I should see a similar signal but 1 microsecond delayed.
Do you know why it happens? why the signal is like that (in image_2) when I try to output in one pin after another?
Note also that the "void loop" runs only once because I stop sensing the signal after 5 milliseconds.
If the code helps:
int trigger = 12;
int pin_number=9;
int time_delay=1; // delay in microseconds
delayMicroseconds(5000); // to clear the signal
}
}
// function to activate the pin
void activate(int x){
digitalWrite(x, HIGH); //set pin_number to HIGH
delayMicroseconds(time_delay);
digitalWrite(x, LOW); //set pin_number to LOW
}
pin_number is a global that starts at 9. On the first pass through loop, it decrements to 8. On the next pass, it decrements to 7. On the next pass, it decrements to 6. Why?
After 5 ms you are not writing the low value because that is in the else. If the HIGH signal in pin 12 persists more than 5 ms then you will be using bad pin numbers as they have decremented.
ok I modified the code, but still does the same thing
that else has no interefence with the images I posted
what I do is:
set pin_9 to HIGH for 1microseconds, then set it to LOW
set pin_8 HIGH for 1 microsecond, then set it to LOW
delay for 5 milliseconds
because I record the signal for only 5 milliseconds, then if I put that delay, the program ends running after finishing the loop
so there is only 1 loop, it is not necessary to be in the code, because I control the trigger from outside
and even if I am wrong and the loop keeps going, it doesn't matter because I record only for 5 milliseconds, so what comes after has no influence
I guess I figured it out, I removed the initialization "pin_number=8;"
and just put "activate( 8 );" after the "activate(pin_numer)" (that is after the activation of pin_9)
image_3 attached
1st window is the signal that triggers into the pin_12
2nd is the signal sensed in pin_9
3rd is the signal sensed in pin_8
the result came better, but still weird:
why does the pin_8 outputing near 5V and in the pin_9 near (below) 4V ?
why when I put a pin going LOW, it does not go to 0V immediately, but goes first through -3V or -4V ??