Skip to content

Instantly share code, notes, and snippets.

@thmosqueiro
Last active February 15, 2017 05:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thmosqueiro/d3bd68d05f8e5f404a2828a74a18bc49 to your computer and use it in GitHub Desktop.
Save thmosqueiro/d3bd68d05f8e5f404a2828a74a18bc49 to your computer and use it in GitHub Desktop.
Arduino jitter experiment
// 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