// 7 segments perlin fire demo
//Yaroslaw Turbin 15-05-2024
//https://vk.com/ldirko
//https://www.reddit.com/user/ldirko/
//https://twitter.com/ldir_ko
//https://www.youtube.com/c/ldirldir
#include <FastLED.h> // i use this for perlin noise
#define dataPin 2
#define latchPin 0
#define clockPin 4
#define NUM_LEDS 8*3*2
byte leds_gray [NUM_LEDS];
byte pixelMapX_norm[NUM_LEDS + 1];
byte pixelMapY_norm[NUM_LEDS + 1];
byte output_bit_buff [NUM_LEDS/8];
#include "tables.h"
void setup() {
Serial.begin(9600);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void send_Number (byte segment, byte number){
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, segment);
shiftOut(dataPin, clockPin, MSBFIRST, number);
digitalWrite(latchPin, HIGH);
}
void fire2021 (byte *pixelMapX_norm, byte *pixelMapY_norm){
int a = millis();
int a1 = a/3;
byte _buffY = pixelMapY_norm[NUM_LEDS];
for (int z = 0; z < NUM_LEDS; z++) { //fastest method
byte i = pixelMapX_norm[z];
byte j = pixelMapY_norm[z];
byte gray = qsub8 (inoise8 ((i<<5), (j<<5) +a, a1), abs8(j - (_buffY-1)) * (255 / (_buffY+15)));
leds_gray[z] = gray;
}
}
void convert_Leds_to_Bits (){
int index = 0;
for (byte i = 0; i < NUM_LEDS/8; i++) {
byte outputBits = 255;
for (byte j = 0; j < 8; j++) {
outputBits <<= 1;
byte color = leds_gray[index];
if (color<105) {outputBits|= 0b00000001;} //dirty convert to BW
index++;
}
output_bit_buff [i] = outputBits;
}
}
void out_Bits(){
for (byte i = 0; i < 6; i++) {
send_Number (1<<i, output_bit_buff [i]);
delay(1);
}
}
void FPS(){
static int frame = 0;
static double currenttime = millis();
if ((millis()-currenttime)>8000) {
Serial.print("FPS: ");
Serial.println(frame/8);
frame = 0;
currenttime = millis();
}
frame++;
}
void test_bit_output (){
normMapsGenerator_From_Coords (14, 13, pixelMapX, pixelMapY);
fire2021 (pixelMapX_norm, pixelMapY_norm);
convert_Leds_to_Bits ();
out_Bits();
}
void loop() {
test_bit_output ();
FPS();
}
esp:0
esp:2
esp:4
esp:5
esp:12
esp:13
esp:14
esp:15
esp:16
esp:17
esp:18
esp:19
esp:21
esp:22
esp:23
esp:25
esp:26
esp:27
esp:32
esp:33
esp:34
esp:35
esp:3V3
esp:EN
esp:VP
esp:VN
esp:GND.1
esp:D2
esp:D3
esp:CMD
esp:5V
esp:GND.2
esp:TX
esp:RX
esp:GND.3
esp:D1
esp:D0
esp:CLK
sevseg1:A
sevseg1:B
sevseg1:C
sevseg1:D
sevseg1:E
sevseg1:F
sevseg1:G
sevseg1:DP
sevseg1:DIG1
sevseg1:DIG2
sevseg1:DIG3
sr1:Q1
sr1:Q2
sr1:Q3
sr1:Q4
sr1:Q5
sr1:Q6
sr1:Q7
sr1:GND
sr1:Q7S
sr1:MR
sr1:SHCP
sr1:STCP
sr1:OE
sr1:DS
sr1:Q0
sr1:VCC
sr2:Q1
sr2:Q2
sr2:Q3
sr2:Q4
sr2:Q5
sr2:Q6
sr2:Q7
sr2:GND
sr2:Q7S
sr2:MR
sr2:SHCP
sr2:STCP
sr2:OE
sr2:DS
sr2:Q0
sr2:VCC
sevseg2:A
sevseg2:B
sevseg2:C
sevseg2:D
sevseg2:E
sevseg2:F
sevseg2:G
sevseg2:DP
sevseg2:DIG1
sevseg2:DIG2
sevseg2:DIG3