Hello Team,
I've broken down the code to the bare bones to hopefully get some insight on this.
Below you can see that when I don't measure the analog input, that my digitalRead inputs are reporting a LOW variable when the switch position is off:
When I turn the switch to the right position, then the digitalRead for the right indicator input responds correctly:
Similarly when I turn the switch to the left position, then the digitalRead for the left indicator input responds correctly:
Now, when I put the analogRead statement back into play and I upload it to the board, then I get a HIGH on the digital read input for the right indicator input without the switch being turned on:
The left indicator still responds as expected when I turn the switch on:
Now, when I remove my board from my circuit board, then the digitalRead for the right indicator input reads correctly again:
So this kind of leads me to a board problem, however, I've checked all my hardware to see whether I have any short circuits between my analog input and my digital input but there are none. I also rechecked (multiple times) that there are no short circuits between 5V and the digitalRead input pin and there is not.
When not measuring the analog input, then I measure 0 volt from the right indicator digital input to ground when it is not turned on and this is expected. But as soon as I declare the analogRead statement, then I measure the 5 V available on the 5V pin on the right indicator digital input.
At this point in time I don't know what is left from right lol. I've attached the schematic diagram I put together in case someone might be able to pick something up there.
Vechile Controller - Board 1.pdf (108.8 KB)
Looking forward to potential feedback.
Code:
// Speed Control Variables
// ************************
#define Throttle_AI_Pin A2
unsigned int Throttle_Pedal_Input = 0;
// Indicator Lights Varialbes
// **************************
#define Left_Indicator_Lights_DI_Pin 32
#define Right_Indicator_Lights_DI_Pin 11
#define Left_Indicator_Lights_DO_Pin 35
#define Right_Indicator_Lights_DO_Pin 34
int Left_Indicator_Lights_State = LOW;
int Left_Indicator_Input_State = LOW;
int Right_Indicator_Lights_State = LOW;
int Right_Indicator_Input_State = LOW;
unsigned long Previous_Millis = 0; // will store last time LED was updated
unsigned long Current_Millis;
const long Timer_Interval = 400; // interval at which to blink (milliseconds)
byte Left_Indicator;
byte Right_Indicator;
// Debugging Variables
// *******************
int Second_Check_Time = 1000;
long Prev_Second_Check_Time;
// *************************************************
void setup()
{
Serial.begin(250000);
pinMode(Left_Indicator_Lights_DI_Pin, INPUT);
pinMode(Right_Indicator_Lights_DI_Pin, INPUT);
pinMode(Left_Indicator_Lights_DO_Pin, OUTPUT);
pinMode(Right_Indicator_Lights_DO_Pin, OUTPUT);
pinMode(Throttle_AI_Pin, INPUT);
}
void loop()
{
Left_Indicator_Input_State = digitalRead(Left_Indicator_Lights_DI_Pin);
Right_Indicator_Input_State = digitalRead(Right_Indicator_Lights_DI_Pin);
Throttle_Pedal_Input = analogRead(Throttle_AI_Pin);
Indicator_Function();
Debugging();
}
/**************************************************************************************************************************************************************************
************************************************** Indicator Flicker Code ***************************************************
**************************************************************************************************************************************************************************/
void Indicator_Function()
{
// Left Indicator function section
// ********************************
if(Left_Indicator_Input_State == HIGH)
{
digitalWrite(Left_Indicator_Lights_DO_Pin, HIGH);
}
else
{
Left_Indicator = 0;
digitalWrite(Left_Indicator_Lights_DO_Pin, LOW);
}
// Right Indicator function section
// ********************************
if(Right_Indicator_Input_State == HIGH)
{
digitalWrite(Right_Indicator_Lights_DO_Pin, HIGH);
}
else
{
digitalWrite(Right_Indicator_Lights_DO_Pin, LOW);
}
}
/**************************************************************************************************************************************************************************
************************************************** Debugging ***************************************************
**************************************************************************************************************************************************************************/
void Debugging()
{
//***********************************************************************
if(millis() - Second_Check_Time > Prev_Second_Check_Time)
{
Serial.print("Throttle Pedal Input:");
Serial.print("\t\t");
Serial.print(Throttle_Pedal_Input);
Serial.print('\n');
Serial.print("Left Indicator Input State:");
Serial.print("\t");
Serial.print(Left_Indicator_Input_State);
Serial.print('\n');
Serial.print("Right Indicator Input State:");
Serial.print("\t");
Serial.print(Right_Indicator_Input_State);
Serial.print('\n');
//***********************************************************************
Serial.print('\n');
Serial.print('\n');
Prev_Second_Check_Time = millis();
}
//***********************************************************************
}
//*************************************************************************************************************************************************************************
Code Attachment:
02_Throttle_Control_Bare_Bones.ino (4.2 KB)