Hi all.
I'm trying to get a LOW output signal from the Uno to trigger a sound effect on the Adafruit sound board. The board needs to have the pin connected to ground in order to trigger. With all grounds being the same, is sending a LOW (0V) signal directly to the pin the same as connecting it to the ground(- end of the DC)?
Here is my code:
int triggerpin = 10; //set the output of Pin 10 on the A to the Trigger of the Sensor
int echopin = 11; //set the input of the echo from the sensor to pin 11.
int PlaySound = 12; //set the output to the soundcard to Pin 12
long Duration; //sets variable for echo time measurement
long Distance; //Sets a variable for Distance Measurement
int DoorClosed; //sets/checks status of door being open or closed; 1 is closed
void setup() {
pinMode(triggerpin, OUTPUT); //sets triggerpin to output
pinMode(echopin, INPUT); // sets echopin to input
pinMode(PlaySound, OUTPUT); //sets PlaySound to output
Serial.begin(9600);
DoorClosed = 1;
digitalWrite(PlaySound, HIGH); //sets the sound trigger to HIGH (off)
}
void loop() {
digitalWrite(triggerpin, LOW);
delayMicroseconds(2); //wait 2 uS
digitalWrite(triggerpin, HIGH); //sets triggerpin to HIGH, starts the ball rolling
delayMicroseconds(10); //wait 10 uS
Duration = pulseIn(echopin, HIGH); //high triggered when sensor hears the echo back
Distance = (Duration / 2) * 0.014; //multiply one-way duration by the speed of sound in inches per microsecond,
Serial.println(Distance); //displays the distance on the readout.
//Distance is distance in inches
if (Distance < 5) { //sets the position of the door
DoorClosed = 1;
}
else
{
DoorClosed = 0;
}
if (Distance > 4 && DoorClosed == 1 ) {
digitalWrite(PlaySound, LOW); // send a LOW signal to the sound card, triggering the SFX.
delay(250); //wait .25 seconds, timing is milliseconds
digitalWrite(PlaySound, HIGH); //resets to HIGH to only play the sound once.
}
else
{
Serial.println(PlaySound);
Serial.println( "No change in door position" ); //reports status of door, back to top. }
}
}
When I'm looking at the output on the monitor, it does everything I'm asking it to do, but the sound card doesn't see the output as being connected to ground. What more do I need?
Thanks!
Jeff