Skip to content

Instantly share code, notes, and snippets.

@battis
Last active April 21, 2020 18:21
Show Gist options
  • Save battis/0bc1ca08c5ad151ecee180e8e6fd98f0 to your computer and use it in GitHub Desktop.
Save battis/0bc1ca08c5ad151ecee180e8e6fd98f0 to your computer and use it in GitHub Desktop.
const int SENSOR_PIN = 0;
const int CYCLE_DURATION = 250;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
}
void loop() {
int reading = analogRead(SENSOR_PIN);
int duration = map(reading, 0, 1023, 0, CYCLE_DURATION);
digitalWrite(LED_BUILTIN, HIGH);
delay(duration);
digitalWrite(LED_BUILTIN, LOW);
delay(CYCLE_DURATION - duration);
}
@battis
Copy link
Author

battis commented Apr 21, 2020

To see a version of this code with some Serial output of readings in it, follow this link.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment