Hallo Zusammen,
ich benötige eure hilfe was das coden für ein kleines Projekt angeht.
Folgender Aufbau:
Ich habe ein Arduino Uno Board, einen Servo und ein Ultrasonic und ein Piezo.
Ich möchte den Ultrasonic auf dem Servo anbringen und folgendes Programmieren.
Der Servo soll bei z.B. 0Grad - 20Grad - 40Grad, 60Grad, 80Grad, 100Grad, 120Grad und 140Grad stehenbleiben.
Genau an diesen Werten soll der Ultrasonic seine Messung erst anfangen.
Außerdem will ich dem System sagen können dass es Werte von der Tastatur einlesen kann. Z.B. A=0Grad und B=20Grad, c=40Grad.........
Und das Resultat soll soll folgendermaßen aussehen. Ich gebe im Serial Motor ein: A B C und dann wieder A. Der Servo bewegt sich.
Ultrasonic misst an diesen Werten und gibt einen Ton raus.
Aber.........wenn er von A nach B geht soll er in den Gradwerten 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19 eben nichts messen und
keinen Ton rausgeben.
Ich habe ein Arduino Audio Code beispiel bei dem er entsprechend der Entfernungsmessung vom Ultrasonic einen Ton rausgibt.
Z.B. 0Grad - ein Holzbalken in 10 cm Entferung und er gibt einen C Ton raus.......
10 Grad - ................................................D Ton raus....
die Töne habe ich vorher deklariert.....also:
#define Not_C 262
#define NiteD 294
...ich habe auch ein Code Beispiel im Internet gefunden aber nun muss nur noch der Servo und meine Wünsche von oben mitreingnommen werden.
#define NOTA_DO 262
#define NOTA_RE 294
#define NOTA_MI 330
#define NOTA_FA 349
#define NOTA_SOL 392
#define NOTA_LA 440
#define NOTA_SI 494
int pinoGatilho = 2;
int pinoEco = 3;
int pinoBuzzer = 9;
int valor = 0;
int nota = 0;
int intervalo_distancia = 7;
void setup() {
pinMode(pinoGatilho, OUTPUT);
pinMode(pinoEco, INPUT);
pinMode(pinoBuzzer, OUTPUT);
}
void loop() {
long duration, inches, cm;
digitalWrite(pinoGatilho, LOW);
delayMicroseconds(2);
digitalWrite(pinoGatilho, HIGH);
delayMicroseconds(5);
digitalWrite(pinoGatilho, LOW);
duration = pulseIn(pinoEco, HIGH);
cm = microsecondsToCentimeters(duration);
if (cm > (intervalo_distancia * 0) && cm < (intervalo_distancia * 1)) {
nota = NOTA_DO;
} else if (cm >= (intervalo_distancia * 1) && cm < (intervalo_distancia * 2)) {
nota = NOTA_RE;
} else if (cm >= (intervalo_distancia * 2) && cm < (intervalo_distancia * 3)) {
nota = NOTA_MI;
} else if (cm >= (intervalo_distancia * 3) && cm < (intervalo_distancia * 4)) {
nota = NOTA_FA;
} else if (cm >= (intervalo_distancia * 4) && cm < (intervalo_distancia * 5)) {
nota = NOTA_SOL;
} else if (cm >= (intervalo_distancia * 5) && cm < (intervalo_distancia * 6)) {
nota = NOTA_LA;
} else if (cm >= (intervalo_distancia * 6) && cm < (intervalo_distancia * 7)) {
nota = NOTA_SI;
} else {
nota = 0;
}
if (nota) {
tone(pinoBuzzer, nota);
} else {
noTone(pinoBuzzer);
}
delay(100);
}
long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}
Ist jemand bereit dazu mir zu helfen?
Viele Dank im voraus
Al