Hi guys,
I have this code written to control various led's for a lighting project that will go inside a 1/6 scale model motorcycle.
as it currently stands it has 6 outputs,
1 - dipped beam
2 - high beam
3 - left indicators
4 - right indicators
5 - rear light
6 - rear brake
The problem with that is that the headlight and tail light both need 2 leds in them.
So i was wondering if someone can alter the code so there is only 1 led for high beam and dipped beam and 1 led for rear light and brake light, the idea being that the rear light and dipped beam are 50% brightness and brake light and high beam take those 2 leds up to 100% brightness with no fade time just instant increase/decrease in brightness where needed?
heres the code i have already, it includes the fader library but isn't used in the current setup,
// Motorcycle Prototype Mk1
#include <LedFader.h>
#include <LedFlasher.h>
// pin assignments PMW 3,5,6,9,10,11
const byte DippedPin = 1; //
const byte HighPin = 2; //
const byte RightIndicatorPin = 3; //
const byte LeftIndicatorPin = 4; //
const byte RearLightPin = 5; //
const byte RearBrakePin = 6; //
// Flashers pin off-time on-time on?
LedFlasher LeftIndicator (LeftIndicatorPin, 500, 500, false);
LedFlasher RightIndicator (RightIndicatorPin, 500, 500, false);
LedFlasher RearBrake (RearBrakePin, 700, 2000, false);
// states for the state machine
typedef enum
{
initialState,
wantDippedBeam,
wantHighBeam,
wantHighBeamOff,
wantLeftIndicator,
wantRightIndicator,
wantLeftIndicatorOff,
wantRightIndicatorOff,
wantRearLight,
wantRearBrake,
wantRearBrake2,
wantRearBrakeOff,
wantRearBrakeOff2,
} states;
// state machine variables
states state = initialState;
unsigned long lastStateChange = 0;
unsigned long timeInThisState = 1000;
void setup ()
{
pinMode (DippedPin, OUTPUT);
pinMode (HighPin, OUTPUT);
pinMode (RearLightPin, OUTPUT);
// set up faders, flashers
LeftIndicator.begin ();
RightIndicator.begin ();
RearBrake.begin ();
} // end of setup
void doStateChange ()
{
lastStateChange = millis (); // when we last changed states
timeInThisState = 1000; // default one second between states
switch (state)
{
case initialState:
state = wantDippedBeam;
break;
case wantDippedBeam:
digitalWrite (DippedPin, HIGH);
state = wantRearLight;
break;
case wantRearLight:
digitalWrite (RearLightPin, HIGH);
state = wantRearBrake;
timeInThisState = 20000;
break;
//left Indicators/brake Lights
case wantRearBrake:
RearBrake.on();
state = wantLeftIndicator;
break;
case wantLeftIndicator:
LeftIndicator.on();
state = wantRearBrakeOff;
timeInThisState = 5000;
break;
case wantRearBrakeOff:
RearBrake.off();
state = wantLeftIndicatorOff;
break;
case wantLeftIndicatorOff:
LeftIndicator.off();
state = wantHighBeam;
timeInThisState = 20000;
break;
case wantHighBeam:
digitalWrite (HighPin, HIGH);
state = wantRearBrake2;
break;
case wantRearBrake2:
RearBrake.on();
state = wantRightIndicator;
break;
case wantRightIndicator:
RightIndicator.on();
state = wantRearBrakeOff2;
timeInThisState = 5000;
break;
case wantRearBrakeOff2:
RearBrake.off();
state = wantRightIndicatorOff;
break;
case wantRightIndicatorOff:
RightIndicator.off();
state = wantHighBeamOff;
timeInThisState = 20000;
break;
case wantHighBeamOff:
digitalWrite (HighPin, LOW);
state = wantDippedBeam;
break;
} // end of switch on state
} // end of doStateChange
void loop ()
{
if (millis () - lastStateChange >= timeInThisState)
doStateChange ();
// update faders, flashers
RearBrake.update ();
LeftIndicator.update ();
RightIndicator.update ();
} // end of loop
If someone can make the changes needed that would be outstanding.