Created
April 12, 2021 22:58
-
-
Save cpyarger/75e7f5ed7d93b69c7a8922c841bb8bb2 to your computer and use it in GitHub Desktop.
bit ed square wave count
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
const byte INPUT_PIN = 3; | |
long maxCountTime = 2000; | |
long nowTime = 0; | |
int waveState = 0; | |
int waveCount = 0; | |
int waveHigh = 0; | |
void setup() { | |
// put your setup code here, to run once: | |
pinMode(INPUT_PIN, INPUT); | |
Serial.begin(9600); | |
} | |
// ================== functions ===================== | |
// int waitForHigh(maxCountTime) { | |
int doed() { | |
// wave is low | |
long lowStart = millis(); | |
long lowRun = 0; | |
int waitOut; | |
int highOK = 0; | |
while (highOK == 0) | |
{ | |
if (waitOut < 0) | |
{ | |
break; | |
} | |
nowTime = millis(); | |
lowRun = nowTime - lowStart; | |
highOK = (digitalRead(INPUT_PIN)); | |
while (waitOut >= 0) | |
{ | |
waitOut = maxCountTime - lowRun; | |
} | |
} | |
return highOK; | |
} | |
// ========================================== main loop ================ | |
void loop() { | |
Serial.println("Home"); | |
waveCount = 0; | |
nowTime = millis(); | |
waveHigh = (digitalRead(INPUT_PIN)); | |
if (waveHigh < 1) | |
{ | |
Serial.println(waveHigh); | |
// wave is low | |
// waveState = waitForHigh(maxCountTime ); | |
waveState = doed(); | |
waveHigh = waveState; | |
} | |
Serial.println( waveHigh); | |
Serial.println("end of script"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment