Arduino sketch modification. Deflector dish.

Forum rules
Forum Rules For All Members: No posts of any kind containing offensive language or personal insults will be allowed. Also, no pictures depicting full nudity whether in a post or an individual members personal avatar are permitted. Spamming or multiple trolling posts by members in an offensive way are also not permitted. Violations of these basic guidelines will result in Admin taking action starting with a warning and up to a permanent ban from the community for repeat offending members.
Post Reply
User avatar
Shawn McClure
Posts: 367
Joined: April 3rd, 2019, 12:46 pm

January 11th, 2020, 8:59 pm

Hi all, I need some help with Arduino code, In this sketch, the deflector dish comes on when the board is powered up. What I want to have happen is that the navigation turns on only when powered up. Then push a button, the deflector dish turns amber, another turns it blue... another turns it off.

How can the following code be modified to make this happen,.

Thank you.



// Simple Navigation & Strobe light flashing
// Added Impulse/Warp Mode Fade-out and Fade-in
// Author: Ostrich Longneck
// Date: 4 November 2015

// LedFlasher Library by Nick Gammon, 23 Dec 2012
#include <LedFlasher.h>

// set up the LEDs
// Always-flashing LEDs: PIN OFF ON (milliseconds)
LedFlasher strobeLights (13, 900, 100);
LedFlasher navLights (12, 500, 1000);

// set up the pin numbers used for warp mode activation/deactivation
const int impulsePin = 10; // Pin 10 is a PWM pin, used to fade the yellow impulse LED up and down
const int warpPin = 11; // Pin 11 is a PWM pin, used to fade the blue warp LED up and down
const int warpButton = 1; // Warpmode will be activated & deactivated by a button on pin 1

// Set up variables used to activate/deactivate warp mode
int fadeVal = 0; // variable for fade loop
int fadeTime = 0; // variable for fade delay loop
int fadeTo = 0; // variable for length of fade delay
int maxFade = 255; // set max brightness value for fade-up and fade-down
int warpMode = 0; // Warp mode: 0=impulse; 1=warp
int warpButtonState = 0; // flag to check if button has been pressed
int stateChange = 0; // Variable to prevent reading button on pin 1 during warp LEDs fade-in & fade-out
int fadeLength = 4000; // approximate length of time (milliseconds) in which the fade-down fade-up cycle will take place
int fadeDown = 0; // flag to check if we are currently fading down to 0
int fadeUp = 0; // flag to check if we are currently fading up to 255


void setup()
{
strobeLights.begin (); // Initialize strobe lights
navLights.begin (); // Initialize navigation lights

pinMode (impulsePin, OUTPUT); // Impulse LED on pin 10
pinMode (warpPin, OUTPUT); // Warp LED on pin 11
pinMode (warpButton, INPUT); // Warp mode button on pin 1

fadeTo = fadeLength/8; // used for delay timer in fade loop

// small delay before fade-up of yellow impulse mode LED
// because it looks kinda cool...
// delete the next 6 lines if you want to remove this delay


// fade-up yellow or blue impulse mode LED at startup
for (fadeVal = 0; fadeVal <= maxFade; fadeVal +=1) {
if (warpMode == 0) {
analogWrite (impulsePin, fadeVal);
}
else {
analogWrite (warpPin, fadeVal);
}
for (fadeTime = 0; fadeTime <= fadeTo; fadeTime +=1) {
strobeLights.update ();
navLights.update ();
}
}

} // end of setup

void loop() // The main program
{
// update lights
strobeLights.update ();
navLights.update ();

// SWITCH BETWEEN WARP MODE AND IMPULSE MODE
warpButtonState = digitalRead (warpButton); // check for button press
if (warpButtonState == HIGH and stateChange == 0) { // if button has been pressed and state change between impulse/warp has not begun yet, then:
stateChange = 1; // initialize state change
fadeDown = 1; // initialize fade down (dimming)
fadeUp = 0; // do not fade up yet (brightening)
}

// IMPULSE TO WARP - Fade orange to black first
if (warpMode == 0 and stateChange == 1 and fadeDown == 1) {
for (fadeVal = maxFade; fadeVal >= 0; fadeVal -=1) {
analogWrite (impulsePin, fadeVal);
for (fadeTime = 0; fadeTime <= fadeTo; fadeTime +=1) {
strobeLights.update ();
navLights.update ();
}
}
fadeDown = 0;
fadeUp = 1;
}
// IMPULSE TO WARP - Fade black to blue
if (warpMode == 0 and stateChange == 1 and fadeUp == 1) {
for (fadeVal = 0; fadeVal <= maxFade; fadeVal +=1) {
analogWrite (warpPin, fadeVal);
for (fadeTime = 0; fadeTime <= fadeTo; fadeTime +=1) {
strobeLights.update ();
navLights.update ();
}
}
fadeUp = 0;
stateChange = 0;
warpMode = 1;
}

// SWITCH BETWEEN IMPULSE MODE AND WARP MODE
// button state was cheked above; state change and fade down were activated

// WARP TO IMPULSE - Fade blue to black first
if (warpMode == 1 and stateChange == 1 and fadeDown == 1) {
for (fadeVal = maxFade; fadeVal >= 0; fadeVal -=1) {
analogWrite (warpPin, fadeVal);
for (fadeTime = 0; fadeTime <= fadeTo; fadeTime +=1) {
strobeLights.update ();
navLights.update ();
}
}
fadeDown = 0;
fadeUp = 1;
}
// WARP TO IMPULSE - Fade black to yellow
if (warpMode == 1 and stateChange == 1 and fadeUp == 1) {
for (fadeVal = 0; fadeVal <= maxFade; fadeVal +=1) {
analogWrite (impulsePin, fadeVal);
for (fadeTime = 0; fadeTime <= fadeTo; fadeTime +=1) {
strobeLights.update ();
navLights.update ();
}
}
fadeUp = 0;
stateChange = 0;
warpMode = 0;
}

// Check for Button presses & execute code here ...


} // end of loop
I would never belong to a club that would have a person like me as a member.
User avatar
Spencer
Posts: 167
Joined: April 3rd, 2019, 1:43 pm
Location: West Virginia, USA
Contact:

January 12th, 2020, 9:37 pm

Hey Shawn,

Did Tom over at HLI get you sorted on this? If not, let me know and I can take a look in a day or so ...

Spencer
User avatar
Shawn McClure
Posts: 367
Joined: April 3rd, 2019, 12:46 pm

January 12th, 2020, 11:05 pm

Hi Spencer,

He was working on it. I don’t think he got it yet. Kenny was saying that if we get it, we could post it on the site, giving due credit of course.

If you want to take a shot at it, please do.

I’ll let you know if Tom comes up with anything.

I would like to post the final on this site too. I can’t be the only one that wants this feature.

Thank you,
Shawn
I would never belong to a club that would have a person like me as a member.
Post Reply