Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define Z 0
- #define I 1
- #define II 2
- #define III 3
- #define IV 4
- #define X 10
- #define XI 11
- #define XXIV 24
- #define XXVI 26
- #define XL 40
- #define CCXX 120
- #define PWM_MAX 255
- const byte strobe1 = II;
- const byte strobe2 = X;
- const byte fadeLed = XI;
- const byte delayTime = XL;
- long ctFadeDelay = Z;
- bool switchLED = true,
- updateLED = false,
- fade = true,
- updateFade = false;
- uint8_t fadeState = Z,
- strobeState = Z,
- strobeCount = Z,
- fadeCount = Z;
- void setup() {
- pinMode(fadeLed, OUTPUT);
- pinMode(strobe1, OUTPUT);
- pinMode(strobe2, OUTPUT);
- }
- void loop() {
- //Single timer which creates process counters
- if(millis() - ctFadeDelay > delayTime){
- fadeCount = fadeCount + I;
- strobeCount = strobeCount + I;
- ctFadeDelay = millis();
- }
- //Fading beacon
- if(fade){
- fadeState = (fadeCount * III);
- updateFade = true;
- if(fadeState > CCXX){
- fadeState = PWM_MAX;
- fadeCount = Z;
- updateFade = true;
- fade = false;
- }
- }else{
- if(fadeCount > XXVI){
- fadeCount = Z;
- fade = true;
- }else if(fadeCount > IV){
- fadeState = Z;
- updateFade = true;
- }else if(fadeCount > II){
- fadeState = PWM_MAX;
- updateFade = true;
- }else if(fadeCount > Z){
- fadeState = Z;
- updateFade = true;
- }
- }
- //Flip Flop Strobe
- if(strobeCount > XXIV){
- strobeState = HIGH;
- updateLED = true;
- strobeCount = Z;
- if(switchLED == true){
- switchLED = false;
- }else{
- switchLED = true;
- }
- }else if(strobeCount > IV){
- strobeState = LOW;
- updateLED = true;
- }else if(strobeCount > III){
- strobeState = HIGH;
- updateLED = true;
- }else if(strobeCount > II){
- strobeState = LOW;
- updateLED = true;
- }else if(strobeCount > I){
- strobeState = HIGH;
- updateLED = true;
- }else if(strobeCount > Z){
- strobeState = LOW;
- updateLED = true;
- }
- //Write update tests to to reduce processing load
- if(updateLED){
- if(switchLED){
- digitalWrite(strobe1, strobeState);
- }else{
- digitalWrite(strobe2, strobeState);
- }
- updateLED = false;
- }
- if(updateFade){
- analogWrite(fadeLed, fadeState);
- updateFade = false;
- }
- }
Add Comment
Please, Sign In to add comment