Last active
April 21, 2020 18:21
-
-
Save battis/0bc1ca08c5ad151ecee180e8e6fd98f0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To see a version of this code with some Serial output of readings in it, follow this link.