hey thx i didn't know that the ide has an auto format tool:
here is the code but with many additional stuff that isn't used here, i'll ad the other stuff later when i get the state thing working:
#include <FastLED.h>
#include <Button.h>
//DM13A classes
#include "DM13A_LedSegment.h"
#include "DM13A.h"
//Speaker
#include <SoftwareSerial.h>
#include <Arduino.h>
#include "DYPlayerArduino.h"
//Cyclotron LEDs
#define NUM_LEDS_CYCLOTRON 28
#define CYCLOTRON_LED_PIN A1
CRGB cyclotron_leds[NUM_LEDS_CYCLOTRON];
const int PERIOD_CYCLOTRON = 5;
unsigned long current_Program_Run_Time = 0;
//Poti test
#define Poti_Pin A6
#define NUM_LEDS_VENT 28
#define LED_PIN A0
int Poti_val = 0;
int Poti_adjusted = 0;
CRGB vent_leds[NUM_LEDS_VENT];
//Buttons
Button SW_WandTip(10);
Button SW_StartUp1(8);
Button SW_StartUp2(7);
Button SW_Intensify(4);
Button SW_BarGraph(3);
Button SW_Vent(2);
//DM13A
constexpr byte LATCH_PIN = 12; // ST_CP // LAT -> for LED-Shiftregisters
constexpr byte CLOCK_PIN = 11; // SH_CP // SCLK -> for LED-Shiftregisters
constexpr byte DATA_PIN = 6; // DS // SIN -> for LED-Shiftregisters
constexpr byte CHAINED_CHIPS = 2;
DM13A DM13ALeds(LATCH_PIN, CLOCK_PIN, DATA_PIN, (2 * CHAINED_CHIPS));
const int PERIOD_POWERCELL_IDLE = 70;
const int PERIOD_BARGRAPH_IDLE = 90;
const int PERIOD_BARGRAPH_FIRING_IDLE = 50;
const int PERIOD_SELFTEST = 7500;
constexpr byte Power_Cell_Leds[][2] = { { 1, 7 }, { 0, 0 }, { 0, 1 }, { 0, 2 }, { 0, 3 }, { 0, 4 }, { 0, 5 }, { 0, 6 }, { 0, 7 }, { 1, 1 }, { 1, 2 }, { 1, 3 }, { 1, 4 }, { 1, 5 }, { 1, 6 } };
const DM13A_LedSegment Power_Cell_Segment(Power_Cell_Leds);
constexpr byte BarG_Element_Leds[][2] = { { 2, 6 }, { 2, 5 }, { 2, 4 }, { 2, 3 }, { 2, 2 }, { 2, 1 }, { 3, 7 }, { 3, 6 }, { 3, 5 }, { 3, 4 }, { 3, 3 }, { 3, 2 } };
const DM13A_LedSegment BarG_Element_Segment(BarG_Element_Leds);
constexpr byte n_Led[][2] = { 2, 7 };
const DM13A_LedSegment n_Segment(n_Led);
constexpr byte k_Led[][2] = { 3, 1 };
const DM13A_LedSegment k_Segment(k_Led);
constexpr byte l_Led[][2] = { 3, 0 };
const DM13A_LedSegment l_Segment(l_Led);
const byte SlowBlow_Led[][2] = { 2, 0 };
enum SelfTestSequence {
coldStart, // sets to 0
isVentPoti_off,
isBarGraph_SW_off,
isStartUp_SW_off,
passed,
ERROR
};
//Speaker 0
#define rxPin0 A4
#define txPin0 A5
SoftwareSerial mySerial0 = SoftwareSerial(rxPin0, txPin0);
DY::Player playerSoftware0(&mySerial0);
const int L_SlowBlow = 5;
//Cyclotron LEDs cycle
void setRedColor(int index, int brightness) {
cyclotron_leds[index] = CRGB(brightness, 0, 0);
//FastLED.show();
}
void updateProgramCallTimer(unsigned long& update_program_cycle) {
update_program_cycle = current_Program_Run_Time;
}
static byte active_LED = 0;
static bool cycleUp = true;
static int current_brightness = 0;
void PROGRAM_Cyclotron() {
static unsigned long cycle_Time_Cyclotron = 0;
static int max_brightness = 100;
if (millis() - cycle_Time_Cyclotron > PERIOD_CYCLOTRON) {
if (cycleUp) {
if (current_brightness < max_brightness) {
current_brightness++;
}
setRedColor(active_LED, current_brightness);
if (current_brightness == max_brightness) cycleUp = false;
}
if (!cycleUp) {
if (current_brightness > 0) {
current_brightness--;
setRedColor(active_LED, current_brightness);
}
if (current_brightness == 0) {
cycleUp = true;
if (active_LED == 21) active_LED = 0;
else active_LED += 7;
}
}
updateProgramCallTimer(cycle_Time_Cyclotron);
}
}
int current_BarGraph_LED = 0;
void PROGRAM_BarGraph_idle_const() { // kann für power cell kopiert werden inhaltlich
static unsigned long cycle_Time_BarGraph_idle_const = 0;
static int max_BarGraph_LEDs = BarG_Element_Segment.ledCount;
if (millis() - cycle_Time_BarGraph_idle_const > PERIOD_BARGRAPH_IDLE) {
DM13ALeds.setOneBit(BarG_Element_Segment, current_BarGraph_LED);
current_BarGraph_LED++;
if (current_BarGraph_LED == max_BarGraph_LEDs + 1) {
DM13ALeds.clearSegment(BarG_Element_Segment);
current_BarGraph_LED = 0;
}
DM13ALeds.needsToUpdate();
DM13ALeds.outputRefresh_direct();
updateProgramCallTimer(cycle_Time_BarGraph_idle_const);
}
}
int firing_help = 0;
void PROGRAM_Firing() {
static unsigned long cycle_Time_Firing_idle_const = 0;
if (millis() - cycle_Time_Firing_idle_const > PERIOD_BARGRAPH_FIRING_IDLE) {
if (firing_help <= 6) {
DM13ALeds.clearSegment(BarG_Element_Segment);
DM13ALeds.setOneBit(BarG_Element_Segment, firing_help);
DM13ALeds.setOneBit(BarG_Element_Segment, 12 - firing_help);
DM13ALeds.needsToUpdate();
DM13ALeds.outputRefresh_direct();
}
firing_help = (firing_help + 1) % 7;
updateProgramCallTimer(cycle_Time_Firing_idle_const);
}
}
int current_PowerCell_LED = 0;
void PROGRAM_PowerCell_idle_const() { // kann für power cell kopiert werden inhaltlich
static unsigned long cycle_Time_PowerCell_idle_const = 0;
static int max_PowerCell_LEDs = Power_Cell_Segment.ledCount;
if (millis() - cycle_Time_PowerCell_idle_const > PERIOD_POWERCELL_IDLE) {
DM13ALeds.setOneBit(Power_Cell_Segment, current_PowerCell_LED);
current_PowerCell_LED++;
if (current_PowerCell_LED == max_PowerCell_LEDs + 1) {
DM13ALeds.clearSegment(Power_Cell_Segment);
current_PowerCell_LED = 0;
}
DM13ALeds.needsToUpdate();
DM13ALeds.outputRefresh_direct();
updateProgramCallTimer(cycle_Time_PowerCell_idle_const);
}
}
/*
a= cubicwave8(Poti_adjusted);
//a = sin8(Poti_adjusted);
*/
void PROGRAM_VENT_LIGHT(int value = 0, int hue = 0, int saturation = 0) { //with setting everything to 0 -> calling PROGRAM_VENT_LIGHT() without any input sets all to 0 -> hence off
vent_leds[0] = CHSV(hue, saturation, value);
vent_leds[1] = CHSV(hue, saturation, value);
vent_leds[2] = CHSV(hue, saturation, value);
vent_leds[3] = CHSV(hue, saturation, value);
vent_leds[4] = CHSV(hue, saturation, value);
vent_leds[5] = CHSV(hue, saturation, value);
vent_leds[6] = CHSV(hue, saturation, value);
}
/*
void SlowBlowLed_Boot(){
for (int brightness = 0; brightness <= 128; brightness ++) {
analogWrite(L_SlowBlow, brightness); // Write the current brightness to the LED pin
delay(5000/128); // Wait for (2000ms/128) = ~15.625ms before moving to the next brightness level
}
}
*/
const int brightnessMax = 180; // % brightness = x%+254/100
const int interval = 3500; // 5 seconds
void SlowBlowLed_Boot() {
for (int i = 0; i <= brightnessMax; i++) {
int pwmValue = pow(2, i / 32.0) - 1; // Logarithmic scale
analogWrite(L_SlowBlow, pwmValue);
delay(interval / brightnessMax);
}
}
void setup() {
// put your setup code here, to run once:
//Cyclotron LEDs
FastLED.addLeds<WS2812, CYCLOTRON_LED_PIN, GRB>(cyclotron_leds, NUM_LEDS_CYCLOTRON);
//Vent LEDs
FastLED.addLeds<WS2812, LED_PIN, GRB>(vent_leds, NUM_LEDS_VENT);
//Slow Blow PMW
pinMode(L_SlowBlow, OUTPUT);
// Buttons
SW_WandTip.begin();
SW_StartUp1.begin();
SW_StartUp2.begin();
SW_Intensify.begin();
SW_BarGraph.begin();
SW_Vent.begin();
//DM13A
DM13ALeds.begin();
DM13ALeds.clearSegment(BarG_Element_Segment);
DM13ALeds.clearSegment(Power_Cell_Segment);
DM13ALeds.clearSegment(n_Segment);
DM13ALeds.clearSegment(k_Segment);
DM13ALeds.clearSegment(l_Segment);
//Software|Hardware Serial Stuff
playerSoftware0.begin();
playerSoftware0.setVolume(10);
playerSoftware0.pause();
Serial.begin(9600);
}
bool selt_test = false;
SelfTestSequence WandStartUpID = coldStart;
void PROGRAM_TEST(SelfTestSequence& currentTestID) {
static unsigned long cycle_Time_TEST = 0;
Serial.println("Test excecuted");
Serial.println(currentTestID);
Serial.println(millis() - cycle_Time_TEST);
Serial.println();
if (currentTestID == ERROR) {
Serial.println("Startet with ERROR");
currentTestID = coldStart;
delay(1000);
}
if (currentTestID != ERROR && (millis() - cycle_Time_TEST) > PERIOD_SELFTEST) {
Serial.println("Startet of Time");
}
if (currentTestID == ERROR || (currentTestID != ERROR && (millis() - cycle_Time_TEST) > PERIOD_SELFTEST)) {
Serial.println("Function real start");
if (currentTestID == ERROR) {
currentTestID = coldStart;
}
if (currentTestID == coldStart) {
currentTestID = isVentPoti_off;
Serial.print(SW_Vent.read());
Serial.println(" ->isVentPoti_off");
} else currentTestID = ERROR;
if (currentTestID == isVentPoti_off) {
Serial.println(Poti_adjusted);
if (Poti_adjusted < 1) {
currentTestID = isBarGraph_SW_off;
Serial.println(" ->isBarGraph_SW_off");
}
} else currentTestID = ERROR;
delay(2500);
updateProgramCallTimer(cycle_Time_TEST);
}
Serial.println("Test exited !!");
}
void loop() {
// put your main code here, to run repeatedly:
Poti_val = analogRead(Poti_Pin);
Poti_adjusted = constrain(Poti_val, 15, 1005);
Poti_adjusted = map(Poti_adjusted, 14, 1005, 0, 254);
PROGRAM_TEST(WandStartUpID);
Serial.print(" |");
Serial.println(Poti_adjusted);
delay(100);
current_Program_Run_Time = millis();
}