/*--------------- by JediRick -----------------
boolean (8 bit) - [true/false]
byte (8 bit) - [0-255] unsigned number
char (8 bit) - [-128 to 127] signed number
unsigned char (8 bit) - [-128 to 127] signed number
word (16 bit) - [0-65535] unsigned number
unsigned int (16 bit) - [0-65535] unsigned number
int (16 bit) - [-32768 to 32767] signed number
unsigned long (32 bit) - [0-4,294,967,295] unsigned number usually for millis
long (32 bit) - [-2,147,483,648 to 2,147,483,647] signed number
float (32 bit) - [-3.4028235E38 to 3.4028235E38] signed number
uint8_t (8 bit) - [0-255] unsigned number
int8_t (8 bit) - [-127 - 127] signed number
uint16_t (16 bit) - [0-65,535] unsigned number
int16_t (16 bit) - [-32,768 - 32,767] signed number
uint32_t (32 bit) - [0-4,294,967,295] unsigned number
int32_t (32 bit) - [-2,147,483,648 - 2,147,483,647] signed number
uint64_t (64 bit) - [0-18,446,744,073,709,551,615] unsigned number
int64_t (64 bit) - [−9,223,372,036,854,775,808 - 9,223,372,036,854,775,807] signed number
--------------------------------------------*/
#define PINCOUNT 4
#define FADEPINQTY 2
#define BLINKPINQTY 2
uint8_t LEDPINS[PINCOUNT] = {13, 12, 11, 10};
uint16_t INTERVALS[PINCOUNT] = {500, 250, 5, 1};
unsigned long OLDMILLIS[PINCOUNT] = {0, 0, 0, 0};
unsigned long currentMillis = 0;
bool LEDSTATE[BLINKPINQTY] = {LOW, LOW};
uint8_t BRIGHTNESS[FADEPINQTY] = {0, 0};
uint8_t FADEQTY[FADEPINQTY] = {1, 1};
void setup() {
for (uint8_t i = 0; i < PINCOUNT; i++) {
pinMode(LEDPINS[i], OUTPUT);
}
}
void loop() {
currentMillis = millis();
blinkLeds();
fadeLeds();
}
void blinkLeds() {
for (uint8_t i = 0; i < BLINKPINQTY; i++) {
if (currentMillis - OLDMILLIS[i] >= INTERVALS[i]) {
OLDMILLIS[i] = currentMillis;
if (LEDSTATE[i] == LOW) {
LEDSTATE[i] = HIGH;
} else {
LEDSTATE[i] = LOW;
}
digitalWrite(LEDPINS[i], LEDSTATE[i]);
}
}
}
void fadeLeds() {
if (currentMillis - OLDMILLIS[2] >= INTERVALS[2]) {
OLDMILLIS[2] = currentMillis;
analogWrite(LEDPINS[2], BRIGHTNESS[0]);
BRIGHTNESS[0] = BRIGHTNESS[0] + FADEQTY[0];
if (BRIGHTNESS[0] <= 0 || BRIGHTNESS[0] >= 255) {
FADEQTY[0] = -FADEQTY[0];
}
}
if (currentMillis - OLDMILLIS[3] >= INTERVALS[3]) {
OLDMILLIS[3] = currentMillis;
analogWrite(LEDPINS[3], BRIGHTNESS[1]);
BRIGHTNESS[1] = BRIGHTNESS[1] + FADEQTY[1];
if (BRIGHTNESS[1] <= 0 || BRIGHTNESS[1] >= 255) {
FADEQTY[1] = -FADEQTY[1];
}
}
}