Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
aostap
/
Helinivoo
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
2e729154
authored
Dec 19, 2023
by
aostap
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new file
parents
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
116 additions
and
0 deletions
Arduino code
Arduino code
0 → 100644
View file @
2e729154
#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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment