Last active
February 15, 2017 05:03
-
-
Save thmosqueiro/d3bd68d05f8e5f404a2828a74a18bc49 to your computer and use it in GitHub Desktop.
Arduino jitter experiment
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
// Ping of the LED's positive leg | |
int ledPin=7; | |
int state = 0; | |
int count; | |
unsigned long previousMillis = 400L; | |
double timer; | |
unsigned long interval = 3L; | |
unsigned long delta; | |
unsigned long waittime = 7L; | |
void setup() | |
{ | |
// Pin that singals open/close valve | |
pinMode(ledPin, OUTPUT); | |
digitalWrite(ledPin, LOW); | |
delta = waittime; | |
delay(1000); | |
Serial.begin(9600); | |
Serial.println("Hello, I am awake."); | |
} | |
void loop() | |
{ | |
timer = micros()/10000.; | |
if ( timer - previousMillis >= delta && state == 0 ) | |
{ | |
digitalWrite(ledPin, HIGH); | |
previousMillis = timer; | |
state = 1; | |
Serial.print(micros()); | |
Serial.print(" - "); | |
Serial.println(previousMillis); | |
delta = interval; | |
} | |
timer = micros()/10000.; | |
if ( timer - previousMillis >= delta && state == 1 ) | |
{ | |
digitalWrite(ledPin, LOW); | |
previousMillis = timer; | |
Serial.print(micros()); | |
Serial.print(" - "); | |
Serial.println(previousMillis); | |
state = 0; | |
delta = waittime; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment