/*
wokwi logo made out of LEDs
*/
const int dataPin = 2; /* DS */
const int clockPin = 4; /* SHCP */
const int latchPin = 3; /* STCP */
#include <TinyDebug.h>
const int ledAmount = 58;
void setup() {
// put your setup code here, to run once:
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(latchPin, OUTPUT);
Debug.begin();
Debug.println(F("Animated Wokwi logo by usernamee"));
digitalWrite(latchPin, LOW);
for (int x = 0;x<ledAmount;x++) {
digitalWrite(clockPin, LOW);
digitalWrite(dataPin, HIGH);
digitalWrite(clockPin, HIGH);
}
digitalWrite(latchPin, HIGH);
delay(2000);
}
void singleDot() {
int led = ledAmount;
int ledDir = -1;
while (1) {
digitalWrite(latchPin, LOW);
for (int x = 0;x<ledAmount;x++) {
digitalWrite(clockPin, LOW);
digitalWrite(dataPin, (led == x) ? HIGH : LOW);
digitalWrite(clockPin, HIGH);
}
digitalWrite(latchPin, HIGH);
led+= ledDir;
if (led > ledAmount - 1) {
//ledDir = -1;
//led += ledDir;
break;
}
if (led < 0) {
ledDir = 1;
led += ledDir;
}
delay(100);
}
}
void fillUp() {
int filled = 0;
while (1) {
digitalWrite(latchPin, LOW);
for (int x = 0;x<ledAmount;x++) {
digitalWrite(clockPin, LOW);
digitalWrite(dataPin, (filled > x) ? HIGH : LOW);
digitalWrite(clockPin, HIGH);
}
digitalWrite(latchPin, HIGH);
filled++;
if (filled > (ledAmount + 1)) {
break;
}
delay(100);
}
}
void fillUp2() {
int filled = 0;
while (1) {
digitalWrite(latchPin, LOW);
for (int x = 0;x<ledAmount;x++) {
digitalWrite(clockPin, LOW);
digitalWrite(dataPin, (filled > (ledAmount - x)) ? HIGH : LOW);
digitalWrite(clockPin, HIGH);
}
digitalWrite(latchPin, HIGH);
filled++;
if (filled > (ledAmount + 1)) {
break;
}
delay(100);
}
}
void alternate() {
for (int cycles = 0;cycles<10;cycles++) {
digitalWrite(latchPin, LOW);
for (int x = 0;x<ledAmount;x++) {
digitalWrite(clockPin, LOW);
digitalWrite(dataPin, (x % 2) ? HIGH : LOW);
digitalWrite(clockPin, HIGH);
}
digitalWrite(latchPin, HIGH);
delay(300);
digitalWrite(latchPin, LOW);
for (int x = 0;x<ledAmount;x++) {
digitalWrite(clockPin, LOW);
digitalWrite(dataPin, (x % 2) ? LOW : HIGH);
digitalWrite(clockPin, HIGH);
}
digitalWrite(latchPin, HIGH);
delay(300);
}
}
void blink() {
for (int cycles = 0;cycles<10;cycles++) {
digitalWrite(latchPin, LOW);
for (int x = 0;x<ledAmount;x++) {
digitalWrite(clockPin, LOW);
digitalWrite(dataPin, HIGH);
digitalWrite(clockPin, HIGH);
}
digitalWrite(latchPin, HIGH);
delay(300);
digitalWrite(latchPin, LOW);
for (int x = 0;x<ledAmount;x++) {
digitalWrite(clockPin, LOW);
digitalWrite(dataPin, LOW);
digitalWrite(clockPin, HIGH);
}
digitalWrite(latchPin, HIGH);
delay(300);
}
}
void loop() {
Debug.println("Single dot");
singleDot();
delay(1000);
Debug.println("Fill up");
fillUp2();
delay(1000);
Debug.println("Fill up reverse");
fillUp();
delay(1000);
Debug.println("Alternate");
alternate();
delay(1000);
Debug.println("Blink");
blink();
delay(1000);
}