Hallo, kann ich bei Arduino ein Programm im Programm starten.
Das Programm macht jetzt den gewünschten Ton. Wenn ich auf den Button im Pin 2 drücke.
PROGRAMM 1 :
int d = 2;
int buzzerPin = 8;
int val;
void setup ()
{
Serial.begin(9600);
pinMode(d,INPUT);
pinMode(buzzerPin,OUTPUT);
}
void loop () {
snd(1700,val);
Serial.println('d');
}
void snd (int inp, int vib) {
digitalWrite(buzzerPin,HIGH);
delayMicroseconds(inp+vib);
digitalWrite(buzzerPin,LOW);
delayMicroseconds(inp);
}
Und dieser Ton also dieses Programm soll dann starten wenn der Wert unter 50 ist. Bei diesem Programm
PROGRAMM 2:
int btnPin = 2;
int buzzerPin = 8;
int echoPin = 12; // SRF05 echo pin (digital 2)
int initPin = 13; // SRF05 trigger pin (digital 3)
unsigned long pulseTime = 0; // stores the pulse in Micro Seconds
unsigned long distance = 0; // variable for storing the distance (cm) we'll use distance as a switch for the speaker
//setup
void setup() {
pinMode(buzzerPin, OUTPUT); //set speaker pin to output
pinMode(btnPin, INPUT); //set pushbutton pin to input
pinMode(initPin, OUTPUT); // set init pin 3 as output
pinMode(echoPin, INPUT); // set echo pin 2 as input
Serial.begin(9600); // start the serial port
}
// execute
void loop() {
if (digitalRead(btnPin) == HIGH) //only play when the button is pressed
{
digitalWrite(initPin, HIGH); // send 10 microsecond pulse
delayMicroseconds(10); // wait 10 microseconds before turning off
digitalWrite(initPin, LOW); // stop sending the pulse
pulseTime = pulseIn(echoPin, HIGH); // Look for a return pulse, it should be high as the pulse goes low-high-low
distance = pulseTime/58; // convert the pulse into distance (cm)
// make the sound.
// check the distance, if over 50cm make no sound - send no signal
if (distance < 50) {
// DA SOLL JETZT DAS ANDERE PROGRAMM STARTEN BZW. DER TON AUS DEM ERSTEN PROGRAMM KOMMEN
Serial.println(distance); // print the distance value to the serial port
delay(50); // delay for 50 milliseconds before starting again...
}
}
}
Ich möchte eine Art Theremin bauen. Oder hat wer schon ein fertiges Programm? Grüße Franz