Ich habe noch kurz an dem hier gebastelt...geht das so auch?
(last euch nicht verwirren ich habe noch paar Sachen dazu geschrieben)
//* +V connection of the Sensor attached to +5V
//* GND connection of the Sensor attached to ground
//* SIG connection of the Sensor attached to digital pin 7
//* SIG connection of the Sensor2 attached to digital pin 8
//* Relais SIG on digital pin 9
//* Poti SIG on digital pin 10
#include <Wire.h> // DigitalPoti
int ug = 5; // UNTERGRENZE in cm
int og = 30; // OBERGRENZE in cm
const int potiPin = 10;
const int pingPin = 7;
const int pingPin2= 8;
const int relais = 9;
int protzentsensor = 0;
int schrittepoti = 0;
boolean pause = false;
boolean next = false;
boolean last = false;
boolean play = false;
boolean isplaying = true;
boolean sensor1hand = false;
boolean sensor2hand = false;
int maxhoehe;
int maxhoehe2;
void setup() {
pinMode(relais,OUTPUT);
Wire.begin(); //DigitalPoti
//Kalibrierung am Start zur Ermittlung der Maximalen höhe
//(falls man direkt unter der Decke ist oder so, schließlich sind viele Decken keine 4m hoch ;D )
long duration3, cm3;
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
pinMode(pingPin, INPUT);
duration3 = pulseIn(pingPin, HIGH);
cm3 = microsecondsToCentimeters(duration3);
long duration4, cm4;
pinMode(pingPin2, OUTPUT);
digitalWrite(pingPin2, LOW);
delayMicroseconds(2);
digitalWrite(pingPin2, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin2, LOW);
pinMode(pingPin2, INPUT);
duration4 = pulseIn(pingPin2, HIGH);
cm4 = microsecondsToCentimeters(duration4);
maxhoehe = cm3-10;
maxhoehe2 = cm4-10;
}
byte val = 50; //DigitalPoti
void loop()
{
// DigitalPoti
Wire.beginTransmission(44); // transmit to device #44 (0x2c)---> Datasheet
Wire.write(byte(0x00));
Wire.write(val);
Wire.endTransmission();
//SonarSensor1
long duration, cm;
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
cm = microsecondsToCentimeters(duration);
//SonarSensor2
long duration2, cm2;
pinMode(pingPin2, OUTPUT);
digitalWrite(pingPin2, LOW);
delayMicroseconds(2);
digitalWrite(pingPin2, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin2, LOW);
pinMode(pingPin2, INPUT);
duration2 = pulseIn(pingPin2, HIGH);
cm2 = microsecondsToCentimeters(duration2);
// Reaktion auf Entfernung: Lautstärkeregulierung
if ( cm||cm2 > ug && cm||cm2 < og ){
int protzentsensor1 = 100/(og-ug)*(cm-ug);
int protzentsensor2 = 100/(og-ug)*(cm2-ug);
protzentsensor = protzentsensor1/protzentsensor2*2 ;// Durschnitt der beiden Sensoren
}
schrittepoti = 2,56*protzentsensor;
val = schrittepoti;
// Pause / Play Steuerung
if (cm||cm2 < ug && isplaying == true){
pause = true;
}
if (cm||cm2 > ug && isplaying == false){
play = true;
}
// Relais Befehle zur Klinkenschaltung
if (pause == true ) {
digitalWrite(relais, HIGH);
delay(50);
digitalWrite(relais, LOW);
delay(50);
pause = false;
isplaying = false;
}
if (play == true ) {
digitalWrite(relais, HIGH);
delay(50);
digitalWrite(relais, LOW);
delay(50);
play = false;
isplaying = true;
}
if (next == true ) {
digitalWrite(relais, HIGH);
delay(50);
digitalWrite(relais, LOW);
delay(50);
digitalWrite(relais, HIGH);
delay(50);
digitalWrite(relais, LOW);
delay(50);
next = false;
}if (last == true ) {
digitalWrite(relais, HIGH);
delay(50);
digitalWrite(relais, LOW);
delay(50);
digitalWrite(relais, HIGH);
delay(50);
digitalWrite(relais, LOW);
delay(50);
digitalWrite(relais, HIGH);
delay(50);
digitalWrite(relais, LOW);
delay(50);
last = false;
}
// Vorwärts/Rückwärts -Steuerung und Erkennung
if (cm && cm2 > og){
if (cm < maxhoehe)
sensor1hand = true;
delay(100);
sensor1hand = false;
}
if (cm2 < maxhoehe2){
sensor2hand = true;
delay(100);
sensor2hand = false;
}
}
//Bearbeitung....
// if ... sensor 1 zuerst und dann sensor 2, dann next = true
// if ... sensor 2 zuerst und dann sensor 1, dann last = true
long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;
}
Wie ihr in dem Komentar der letzten Zeilen seht habe ich ein "neues" Problem wozu ich bisher noch keine Idee habe...ihr?
Danke!
LG Max