From a8c54f2688fcd54f290749dd13843ea199638d89 Mon Sep 17 00:00:00 2001 From: Martin-Laclaustra Date: Sun, 30 Apr 2017 19:18:45 +0200 Subject: [PATCH] Start always with a timing that has a low signal Deliver 499 or 500 samples, ensuring that the first one is always low level. --- htdocs/Sketchbook/SimpleRcScanner.ino | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/htdocs/Sketchbook/SimpleRcScanner.ino b/htdocs/Sketchbook/SimpleRcScanner.ino index 9e52351..165493b 100644 --- a/htdocs/Sketchbook/SimpleRcScanner.ino +++ b/htdocs/Sketchbook/SimpleRcScanner.ino @@ -5,9 +5,11 @@ static unsigned int timings[SAMPLESIZE]; static unsigned int pos = 0; static unsigned long lastTime = 0; +static int receiverPin = 2; static int interruptPin = 0; void setup() { + interruptPin = digitalPinToInterrupt(receiverPin); Serial.begin(9600); attachInterrupt(interruptPin, handleInterrupt, CHANGE); pinMode(13, OUTPUT); @@ -26,10 +28,12 @@ void loop() { Serial.println(); detachInterrupt(interruptPin); + + int finalstate = digitalRead(receiverPin); char s = Serial.read(); - for (unsigned int i = pos; i< SAMPLESIZE; i++) { + for (unsigned int i = pos + finalstate; i< SAMPLESIZE; i++) { Serial.print( timings[i] ); Serial.print(","); }