Created
May 16, 2021 16:00
-
-
Save enzzc/16b4213d49a816971ebda8c5eb27ae53 to your computer and use it in GitHub Desktop.
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
#define DATA_PIN 7 | |
#define CLOCK_PIN 12 | |
#define LATCH_PIN 9 | |
uint8_t k = 0; | |
float speed_msecs = 0; | |
int lum = 0; | |
void setup() { | |
pinMode(DATA_PIN, OUTPUT); | |
pinMode(CLOCK_PIN, OUTPUT); | |
pinMode(LATCH_PIN, OUTPUT); | |
digitalWrite(DATA_PIN, LOW); | |
digitalWrite(CLOCK_PIN, LOW); | |
digitalWrite(LATCH_PIN, LOW); | |
} | |
void loop() { | |
lum = analogRead(A1); | |
if (lum < 5) | |
lum = 5; | |
speed_msecs = (1. / lum) * 10000; | |
digitalWrite(LATCH_PIN, LOW); | |
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, k); | |
digitalWrite(LATCH_PIN, HIGH); | |
delay((int)speed_msecs); | |
if (++k >= 3) k = 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment