[chronojump/quickfirmware] Wifi. WIP. Adding debounce time to sensor.
- From: Xavier Padullés <xpadulles src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump/quickfirmware] Wifi. WIP. Adding debounce time to sensor.
- Date: Mon, 13 Sep 2021 11:35:05 +0000 (UTC)
commit 764f4d8191e2073bbec7acb22cff199935df1f50
Author: Xavier Padullés <x padulles gmail com>
Date: Mon Sep 13 13:33:38 2021 +0200
Wifi. WIP. Adding debounce time to sensor.
arduino/lightChro/terminal/terminal.ino | 37 +++++++++++++++++++++++++--------
1 file changed, 28 insertions(+), 9 deletions(-)
---
diff --git a/arduino/lightChro/terminal/terminal.ino b/arduino/lightChro/terminal/terminal.ino
index 6dcb4109d..d0a524515 100644
--- a/arduino/lightChro/terminal/terminal.ino
+++ b/arduino/lightChro/terminal/terminal.ino
@@ -4,6 +4,7 @@
#include <RF24.h>
#include <printf.h>
#include <MsTimer2.h>
+#include <TimerOne.h>
String version = "Wifi-Sensor-1.11";
//
@@ -199,14 +200,24 @@ void setup(void)
// Serial.print("Is chip connected:");
// Serial.println(radio.isChipConnected());
+
+ Timer1.initialize(1000000); //Initializing the debounce timer to 1 ms
+ Timer1.detachInterrupt();
+ sample.state = digitalRead(2);
+ lastPinState = sample.state;
+ Serial.println("Initial state");
+ Serial.print(lastPinState);
+ Serial.print("\t");
+ Serial.println(sample.state);
}
void loop(void)
{
- if (flagint == HIGH && lastPinState != sample.state) //The sensor has changed
+ //if (flagint == HIGH && lastPinState != sample.state) //The sensor has changed
+ if (flagint == HIGH && lastPinState ) //The sensor has changed
{
- lastPinState = sample.state;
+ //lastPinState = sample.state;
sample.elapsedTime = (millis() - time0);
flagint = LOW;
buzzer_off;
@@ -255,21 +266,29 @@ void loop(void)
void controlint()
{
-// Serial.println("Int");
+ sample.state = digitalRead(2);
+ //Serial.println("Int");
if (waitingSensor == true) {
//flagint = HIGH;
- sample.state = digitalRead(2);
- MsTimer2::set(debounceTime, debounce);
- MsTimer2::start();
+ //Timer1.initialize(1000000); //Initializing the debounce timer to 1 ms
+ Timer1.attachInterrupt(debounce);
+ Serial.print(lastPinState);
+ Serial.print("\t");
+ Serial.println(sample.state);
}
}
void debounce(){
- MsTimer2::stop();
+ Serial.println("in debounce");
+ sample.state = digitalRead(2);
+ Timer1.detachInterrupt();
+ Serial.print(lastPinState);
+ Serial.print("\t");
+ Serial.print(sample.state);
if (sample.state != lastPinState){
flagint = HIGH;
- } else {
- if (blinkingRed | blinkingGreen | blinkingBlue) blinkStart(blinkPeriod);
+ lastPinState = sample.state;
+ Serial.println("\tDebounced");
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]