Files
arduino/electricity/measure/measure.ino
2018-08-08 08:33:26 +02:00

34 lines
576 B
C++

/*
Into Robotics
*/
const int lowerThreshold = 250;
const int upperThreshold = 450;
const uint8_t analogPin = A0;
void setup()
{
Serial.begin(9600);
pinMode(analogPin, INPUT);
}
void loop() {
static bool state = LOW;
static unsigned int counter = 0;
int analogValue = analogRead(analogPin);
if (state == HIGH) {
if (analogValue < lowerThreshold) {
state = LOW;
counter++;
Serial.println(counter);
Serial.println("blykst");
}
} else { // state == LOW
if (analogValue > upperThreshold) {
state = HIGH;
}
}
}