Skip to content

Instantly share code, notes, and snippets.

@stevelord
Created October 29, 2017 17:58
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 stevelord/d2d39579bdc30497ded8032633aa416d to your computer and use it in GitHub Desktop.
Save stevelord/d2d39579bdc30497ded8032633aa416d to your computer and use it in GitHub Desktop.
A (better) EMF detector
#define SAMPLES 250
unsigned int state = 0;
unsigned long total = 0;
void setup() {
}
void loop() {
for (int i = 0; i < SAMPLES; i++){
total += analogRead(A1);
}
state = total / SAMPLES;
state = constrain(state, 0, 100);
state = map(state, 0, 100, 0, 255);
analogWrite(PB1,state);
total = 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment