Commit 2e729154 by aostap

Add new file

parents
Showing with 116 additions and 0 deletions
#define LED_1 12 // LEDi digitaalsed PIN'id
#define LED_2 11
#define LED_3 10
#define LED_4 9
#define LED_5 8
#define LED_6 7
#define LED_7 6
#define LED_8 5
#define LED_9 4
#define sensorPin A0 // Sensori analoog väljund
unsigned long currentMillis;
const long interval = 300; // Intervall kui kaua LEDid põlevad
unsigned long previousMillis = 0;
int sensorValue = 0;
void ReadSensorValue() // Funktsioon et teisendada väljundi logaritmilisele skaalale
{
sensorValue = analogRead(sensorPin);
// Sensori väljundi konverteerimine logaritmilisele skaalale
float logSensorValue = log(sensorValue);
// väärtuste printimine Serial Monitoris
Serial.println(logSensorValue);
}
void LEDBlinking() // Funktsioon LEDide kontrolliks
{
if (sensorValue > 525)
{
digitalWrite(LED_1, HIGH);
}
if (sensorValue > 550)
{
digitalWrite(LED_2, HIGH);
}
if (sensorValue > 575)
{
digitalWrite(LED_3, HIGH);
}
if (sensorValue > 600)
{
digitalWrite(LED_4, HIGH);
}
if (sensorValue > 625)
{
digitalWrite(LED_5, HIGH);
}
if (sensorValue > 650)
{
digitalWrite(LED_6, HIGH);
}
if (sensorValue > 675)
{
digitalWrite(LED_7, HIGH);
}
if (sensorValue > 700)
{
digitalWrite(LED_8, HIGH);
}
if (sensorValue > 725)
{
digitalWrite(LED_9, HIGH);
}
currentMillis = millis();
if (currentMillis - previousMillis >= interval)
{
previousMillis = currentMillis;
currentMillis = millis();
digitalWrite(LED_9, LOW);
digitalWrite(LED_8, LOW);
digitalWrite(LED_7, LOW);
digitalWrite(LED_6, LOW);
digitalWrite(LED_5, LOW);
digitalWrite(LED_4, LOW);
digitalWrite(LED_3, LOW);
digitalWrite(LED_2, LOW);
digitalWrite(LED_1, LOW);
}
}
void setup()
{
pinMode(LED_1, OUTPUT);
pinMode(LED_2, OUTPUT);
pinMode(LED_3, OUTPUT);
pinMode(LED_4, OUTPUT);
pinMode(LED_5, OUTPUT);
pinMode(LED_6, OUTPUT);
pinMode(LED_7, OUTPUT);
pinMode(LED_8, OUTPUT);
pinMode(LED_9, OUTPUT);
pinMode(sensorPin, INPUT);
Serial.begin(9600);
}
void loop()
{
ReadSensorValue();
LEDBlinking();
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment