Hello,
I'm trying to use millis() to create a fade (blinking works fine).
In this project, I'm going to use some of my taillights to turn on the signal via Bluetooth.
The rear lights work normally on 50 diodes power.
Right now all my turn signals works from 0 to 255 so its fine for my front turn signal lights, but on rear i want to setup them to work from 50 to 255.
What should i change / fix?
Not the answer to the question that you asked, but using pins 0 and 1 for SoftwareSerial on many Arduinos is not a good idea as they are used by the hardware Serial interface for the Serial monitor and to upload code
So then the OP has to describe in normal words but in detail what she/he wants the LEDs to look like
One single speculation @arduraz
do you want the LEDs to start at "half brightness = your 50%" and then increase to 100% over a certain time instead of immidiately switching to full brightness = your 100%?
if this is what you want in which timeintervall shall the transition from 50% to 100% be finished?
Thank you for help, its work!
But after all i have some new problems...
In this project i have front and rear turn signal diodes, front one are on digital pins (they ar blinked from 0 to 100% and its ok) and rear are fade from 50 to 100%.
Now the problem are:
a) If I off left or right turn signal diodes, is 50% chance to frontdiodes stay ON,
b) hazzard lights are not synhronized (special if I used turn signal before), + theay state ar 100% when i stop it.
How to fix these problems?
Fixed Code:
#include <SoftwareSerial.h>
int turnSignalRearL = 5; //PWM 2x diode turn signal rear-left
int turnSignalRearR = 6; //PWM 2x diode turn signal rear-right
int turnSignalFrontL = 7; //2x diode turn signal front-left
int turnSignalFrontR = 8; //2x diode turn signal front-right
const int constStateLed = 50;
int stateLed1 = 50;
int stateLed2 = 50;
//BLINK / FADE
unsigned long currentTime1 = 0;
unsigned long savedTime1 = 0;
unsigned long savedTime2 = 0;
boolean turnSigLeft = false;
boolean turnSigRight = false;
SoftwareSerial Bluetooth(0, 1);
char Data;
void sendData(String transmitData){
Bluetooth.println(transmitData);}
void setup(){
Bluetooth.begin(9600);
pinMode(turnSignalRearL,OUTPUT);
pinMode(turnSignalRearR,OUTPUT);
pinMode(turnSignalFrontL,OUTPUT);
pinMode(turnSignalFrontR,OUTPUT);
}
void loop(){
currentTime1 = millis();
//=== LEFT turn signal ===
if (turnSigLeft && currentTime1 - savedTime1 >= 300UL) {
savedTime1 = currentTime1;
digitalWrite(turnSignalFrontL, !digitalRead(turnSignalFrontL));
if (stateLed1 == 50)
stateLed1 = 255;
else
stateLed1 = 50;
analogWrite(turnSignalRearL, stateLed1);
}
//=== RIGHT turn signal ===
if (turnSigRight && currentTime1 - savedTime2 >= 300UL) {
savedTime2 = currentTime1;
digitalWrite(turnSignalFrontR, !digitalRead(turnSignalFrontR));
if (stateLed2 == 50)
stateLed2 = 255;
else
stateLed2 = 50;
analogWrite(turnSignalRearR, stateLed2);
}
//=== BLINKING / FADING ===
if(Bluetooth.available()){
Data=Bluetooth.read();
//Left ON
if(Data==('g')){
turnSigRight = false;
analogWrite(turnSignalRearR,constStateLed);
turnSigLeft = true;
sendData("turn signal left ON");
}
//Left OFF
if(Data==('h')){
turnSigLeft = false;
analogWrite(turnSignalRearL,constStateLed);
digitalWrite(turnSignalFrontL,0);;
sendData("turn signal left OFF");
}
//Right ON
if(Data==('i')){
turnSigLeft = false;
analogWrite(turnSignalRearL,constStateLed);
turnSigRight = true;
sendData("turn signal right ON");
}
//Right OFF
if(Data==('j')){
turnSigRight = false;
analogWrite(turnSignalRearR,constStateLed);
digitalWrite(turnSignalFrontR,0);
sendData("turn signal right OFF");
}
//Hazzard lights OM
if(Data==('9')){
turnSigLeft = true;
turnSigRight = true;
sendData("HAZARD lights ON");
}
//Hazzard lights OFF
if(Data==('0')){
turnSigLeft = false;
turnSigRight = false;
digitalWrite(turnSignalFrontL,0);
digitalWrite(turnSignalFrontR,0);
analogWrite(turnSignalRearL,constStateLed);
analogWrite(turnSignalRearR,constStateLed);
sendData("HAZARD lights OFF");
}
}
}
The first problem was solved by me.
The second problem is not hardware (schematic etc.), but software(desynchronised).
I modified my code (Fixed Code) to easy to understand.
The problem is the synchronization of the flashing of the direction indicators when using the hazard lights, and when I turn off one of the direction indicators while the LEDs are on.
The front turn signals and the rear turn signals are desynchronised.
I cant do schematic for you right now, but I`m 100% sure its ok.
I'll do it schematic tomorrow if u want.