//=======for the Neopixel Jewel=========
#include <FastLED.h>// include library
#define NUM_LEDS 7 // number of leds
#define DATA_PIN 5 //signal pin of board
#define MASTER_BRIGHTNESS 10
CRGB leds[NUM_LEDS];//setup individual led array
//======for the Standard LEDS======
const unsigned long StrobeOnMillis = 100;
const unsigned long NavOnMillis = 1000;
const unsigned long StrobeBaseInterval = 900;
const unsigned long NavBaseInterval = 500;
unsigned long StrobeInterval = StrobeBaseInterval;
unsigned long NavInterval = NavBaseInterval;
byte StrobeLedstate = HIGH;
byte NavLedstate = HIGH;
unsigned long prevStrobeLedMillis;
unsigned long prevNavLedMillis;
unsigned long currentMillis = millis(); //used for all functions
const byte Strobepin = 13;
const byte Navpin = 10;
//=======for the Neopixel========
const unsigned long nacOnTime = 100; //each pixel on time
const unsigned long nacOffTime = 50; //each pixel off time
unsigned long nacInterval = nacOffTime;
unsigned long nacPreviousMillis;
bool nacState;
int nacCount;
CRGB fixedColor[NUM_LEDS] =
{
CRGB::Red,
CRGB::Blue,
CRGB::Yellow,
CRGB::Green,
CRGB::Orange,
CRGB::Magenta,
CRGB::Violet,
};
void setup() {
pinMode (Strobepin, OUTPUT);
pinMode (Navpin, OUTPUT);
digitalWrite(Strobepin, HIGH);
digitalWrite(Navpin, HIGH);
// FastLED.setBrightness(MASTER_BRIGHTNESS); // full brighness is better for Wokwi
// start the strip and blank it out
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); //declare LED strip
//Select led colors. these will not require random changing
for( int i=0; i<NUM_LEDS; i++)
leds[i] = fixedColor[i];
FastLED.show();
delay( 2000);
FastLED.clear();
}
void loop() {
currentMillis = millis();
StrobeLed();
NavLed();
NacLed();
}
void StrobeLed() {
if (currentMillis - prevStrobeLedMillis >= StrobeInterval) {
prevStrobeLedMillis += StrobeInterval;
StrobeLedstate = ! StrobeLedstate;
if (StrobeLedstate == HIGH) {
StrobeInterval = StrobeOnMillis;
}
else {
StrobeInterval = StrobeBaseInterval;
}
digitalWrite(Strobepin, StrobeLedstate);
}
}
void NavLed() {
if (currentMillis - prevNavLedMillis >= NavInterval) {
prevNavLedMillis += NavInterval;
NavLedstate = ! NavLedstate;
if (NavLedstate == HIGH) {
NavInterval = NavOnMillis;
}
else {
NavInterval = NavBaseInterval;
}
digitalWrite(Navpin, NavLedstate);
}
}
// not sure where to go here
// i want pixel zero to be high for 100ms-low for 50ms, pixel 1 hinh for 100ms-low for 50ms etc.
// each pixel having a set indivdual color
void NacLed()
{
if( currentMillis - nacPreviousMillis >= nacInterval)
{
nacPreviousMillis = currentMillis;
if( nacState)
{
// Turn the led off by making it black.
leds[nacCount] = CRGB::Black;
nacState = false;
nacInterval = nacOffTime;
// Done with this led, set the next led
nacCount++;
if( nacCount >= NUM_LEDS)
nacCount = 0;
}
else
{
leds[nacCount] = fixedColor[nacCount]; // set this led to its own color
nacState = true;
nacInterval = nacOnTime;
}
FastLED.show();
}
}