Stap 6: Arduino Software start
int pirPin = 2;int pinSpeaker = 10;
int ledPin = 13;
VOID Setup {}
Serial.begin(9600);
pinMode (pirPin, INPUT);
pinMode (ledPin, OUTPUT);
pinMode (pinSpeaker, OUTPUT);
}
void loop {}
int pirVal = digitalRead(pirPin);
Serial.println ("beginnen te lezen PIR");
analogWrite (ledPin, 0);
delay(2000);
if(pirVal == low) {}
analogWrite (ledPin, 255);
Serial.println ("bewegingsdetectie");
Toon (10, 700, 100);
delay(2000);
}
}
VOID Toon (lange duur, int freq) {}
duur * = 1000;
int periode = (1.0 / freq) * 1000000;
lange elapsed_time = 0;
terwijl (elapsed_time < duur) {}
digitalWrite(pinSpeaker,HIGH);
delayMicroseconds(period / 2);
digitalWrite (pinSpeaker, laag);
delayMicroseconds(period / 2);
elapsed_time += (periode);
}
}