Arduino Program:
int redled = 4;
int IRsensor = 0;
unsigned int A = 440;
double alpha = 0.75;
int period = 20;
double change = 0.0;
int IRsensor = 0;
unsigned int A = 440;
double alpha = 0.75;
int period = 20;
double change = 0.0;
int greenPin = 8;
int buzzer = 7;
int clock = 998;
int sec = 0;
void setup()
{
int buzzer = 7;
int clock = 998;
int sec = 0;
void setup()
{
pinMode(redled, OUTPUT);
pinMode(greenPin, OUTPUT);
}
void loop()
{
static double oldValue = 0;
static double oldChange = 0;
int rawValue = analogRead(IRsensor);
double value = alpha * oldValue + (1 - alpha) * rawValue;
change = value - oldValue;
digitalWrite(redled, (change < 0.0 && oldChange > 0.0));
oldValue = value;
oldChange = change;
delay(period);
Serial.print(rawValue);
Serial.print(",");
Serial.println(value);
}
}
void loop()
{
static double oldValue = 0;
static double oldChange = 0;
int rawValue = analogRead(IRsensor);
double value = alpha * oldValue + (1 - alpha) * rawValue;
change = value - oldValue;
digitalWrite(redled, (change < 0.0 && oldChange > 0.0));
oldValue = value;
oldChange = change;
delay(period);
Serial.print(rawValue);
Serial.print(",");
Serial.println(value);
}
void loop()
{
delay(clock);
sec = sec + 1;
if (sec <= 30)
{
digitalWrite(greenPin, HIGH);
}
if (sec == 30)
{
tone(buzzer,A);
}
if (sec > 30 && sec < 60)
{
noTone(buzzer);
digitalWrite(greenPin, LOW);
}
if (sec == 59)
{
sec = 0;
{
delay(clock);
sec = sec + 1;
if (sec <= 30)
{
digitalWrite(greenPin, HIGH);
}
if (sec == 30)
{
tone(buzzer,A);
}
if (sec > 30 && sec < 60)
{
noTone(buzzer);
digitalWrite(greenPin, LOW);
}
if (sec == 59)
{
sec = 0;
No comments:
Post a Comment