|
|
|
|
|
|
|
|
|
|
|
//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; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|