Här är koden:
Kod: Markera allt
void setup() {
pinMode(1, OUTPUT);
}
void led() {
int value = analogRead(2);
if (value>700)
{digitalWrite(1, HIGH);
delay(500);}
else
{digitalWrite(1, LOW);}
}
void loop() {
led();
}
Kod: Markera allt
void setup() {
pinMode(1, OUTPUT);
}
void led() {
int value = analogRead(2);
if (value>700)
{digitalWrite(1, HIGH);
delay(500);}
else
{digitalWrite(1, LOW);}
}
void loop() {
led();
}
Kod: Markera allt
// Connect the MEMS AUD output to the first analog pin
int mic = 1;
// Variables to find the peak-to-peak amplitude of AUD output
const int sampleTime = 50;
int micOut;
int micOutput;
void setup() {
pinMode(1, OUTPUT);
}
void loop() {
micOutput = findPTPAmp();
blinkLed(micOutput);
}
// Find the Peak-to-Peak Amplitude Function
int findPTPAmp(){
// Time variables to find the peak-to-peak amplitude
unsigned long startTime= millis(); // Start of sample window
unsigned int PTPAmp = 0;
// Signal variables to find the peak-to-peak amplitude
unsigned int maxAmp = 0;
unsigned int minAmp = 1023;
// Find the max and min of the mic output within the 50 ms timeframe
while(millis() - startTime < sampleTime)
{
micOut = analogRead(mic);
if( micOut < 1023) //prevent erroneous readings
{
if (micOut > maxAmp)
{
maxAmp = micOut; //save only the max reading
}
else if (micOut < minAmp)
{
minAmp = micOut; //save only the min reading
}
}
}
PTPAmp = maxAmp - minAmp; // (max amp) - (min amp) = peak-to-peak amplitude
return PTPAmp;
}
void blinkLed(int value) {
if(value>200) {
digitalWrite(1, HIGH);
delay(500);
digitalWrite(1, LOW);
}
}