Browse Source

Soundsensor getestet

Digitaler und analoger Output getestet
pull/1/head
Johannes Krug 5 years ago
parent
commit
5cb5bdbd77
2 changed files with 76 additions and 0 deletions
  1. 23
    0
      analog_signal_output.ino
  2. 53
    0
      digital_signal_output.ino

+ 23
- 0
analog_signal_output.ino View File

@@ -0,0 +1,23 @@
//www.elegoo.com
//2016.12.9
//analoger ausgang gibt nur den aktuellen wert des potis aus, also nur zum genauen poti einstellen geeignet! ansonsten nutzlos


int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = D0; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor

void setup()
{
pinMode(ledPin,OUTPUT);
Serial.begin(9600);
}
void loop(){
sensorValue = analogRead(sensorPin);
digitalWrite(ledPin, HIGH);
delay(sensorValue);
digitalWrite(ledPin, LOW);
delay(sensorValue);
Serial.println(sensorValue, DEC);
}

+ 53
- 0
digital_signal_output.ino View File

@@ -0,0 +1,53 @@
//www.elegoo.com
//2016.06.13
//digitaler ausgang soundmodul


int Led=D0;//define LED port
int buttonpin=D5; //define switch port
int val;//define digital variable val
int anzahl_loop=0;
int anzahl_high=1;
int anzahl_low=1;
double high_anteil;

void setup()
{
Serial.begin(9600);
pinMode(Led,OUTPUT);//define LED as a output port
pinMode(buttonpin,INPUT);//define switch as a output port
}
void loop()

{ anzahl_loop++;//anzahl der loopdurchlaeufe
val=digitalRead(buttonpin);//read the value of the digital interface 3 assigned to val

if(val==HIGH)//when the switch sensor have signal, LED blink
{
digitalWrite(Led,HIGH);
//Serial.println("HIGH");
anzahl_high++;


}
else
{
digitalWrite(Led,LOW);
//Serial.println(val);
anzahl_low++;
}

if(anzahl_loop==1000){ //100 loops auswerten und den high anteil ermitteln
high_anteil=((double)anzahl_high/(double)anzahl_loop);
if(high_anteil>=0.10){
Serial.println(high_anteil);
}
anzahl_high=1;
anzahl_low=1;
anzahl_loop=0;

}


}

Loading…
Cancel
Save