Created
June 22, 2022 15:26
-
-
Save Adeykin/c4500a2cc8958a4af21b7b97d04b9304 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "GyverTimers.h" | |
#define CLK 2 | |
#define DIO 3 | |
#include "GyverTM1637.h" | |
const int analogInPin = A0; | |
const int threshold = 580; | |
const int lowThreshold = 500; | |
const long int sleepTime = 600; | |
const long int workTime = 10; | |
int outputPin = 8; | |
int sensorValue = 0; | |
GyverTM1637 disp(CLK, DIO); | |
int turnsCounter = 0; | |
bool showValue = true; | |
bool isWorkingNow = false; | |
int periodTime = 0; | |
ISR(TIMER1_A) { | |
periodTime++; | |
showValue = !showValue;// ? false : true; | |
if(isWorkingNow && periodTime > workTime) { | |
digitalWrite(outputPin, LOW); | |
isWorkingNow = false; | |
periodTime = 0; | |
turnsCounter++; | |
} else if(!isWorkingNow && periodTime > sleepTime) { | |
if(sensorValue > threshold) { | |
digitalWrite(outputPin, HIGH); | |
isWorkingNow = true; | |
} | |
periodTime = 0; | |
} | |
} | |
void setup() { | |
Serial.begin(9600); | |
pinMode(outputPin, OUTPUT); | |
digitalWrite(outputPin, LOW); | |
disp.clear(); | |
disp.brightness(7); // яркость, 0 - 7 (минимум - максимум) | |
Timer1.setPeriod(1000000); | |
Timer1.enableISR(); | |
} | |
void loop() { | |
sensorValue = analogRead(analogInPin); | |
Serial.println(sensorValue); | |
if(showValue) { | |
disp.clear(); | |
disp.displayInt(sensorValue); | |
} | |
else { | |
disp.clear(); | |
disp.displayInt(turnsCounter); | |
} | |
if(sensorValue < lowThreshold) | |
digitalWrite(outputPin, LOW); | |
delay(100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment