Function changing the value of a variable doesn't work

I am relatively new to Arduino and CS, but I think I've encountered a bug. I have created a program that's supposed talk in Morse code via LED lights (Arduino Uno), and there are three leds, all connected to their own pins of the Arduino. I tried creating a function to change what pin every letter in Morse code is flashed on, so it goes like pin1, then pin2, then pin3, and repeat, but it doesn't change what pin the led is flashing on.

to break down the code,
Dot and Dash functions, just turn LEDs on and off at the current pin variable and running FC_Pin every time they run changes.
Function Current Pin (FC_Pin) - Changes the current pin
Alphabet - Each letter has it's own function, which are just functions to run the Dot and Dash functions.

SUMMARY: A function to change a variable between 3 different values In order when it's run isn't working

Here is the function to change the pin (Pin 1, 2, and 3 are variables for pins on the board)

void FC_Pin () { 
/*FUNCTION CURRENT PIN, EVERYTIME THE FUNCTION IS RUN, THE VARIABLE CHANGES
Also, the ONLY THING this function does is changes the C_Pin, which is a NORMAL VARIABLE, and not a function.
So every time an LED is set to blink, it should be typed like "LEDBLINK (Cpin, High)", or in other words,
Blink an LED on the Current pin while calling on the VARIABLE, not the function.
  */ 
if (C_Pin = pin_3) { 
  //NEXT PIN IS PIN 1
  int C_Pin = pin_1;
}
else if (C_Pin = pin_1) {
  //NEXT PIN IS PIN 2
   int C_Pin = pin_2;
}
else { 
  //NEXT PIN IS PIN 3
   int C_Pin = pin_3;
};
};

Link to the program (It's public)->

Thanks for your help!

Welcome to the forum

if (C_Pin = pin_3) { 

This, and other code like it is wrong

Use = to set the value of a variable
Use == to compare the value of a variable with another value

Thank you so much for the quick reply, I did that, and then I made it so it doesn't re-Initialize the variable every time I want it to change, and now it works!
Thanks HeliBob

I guess that that is about statements like int C_Pin = pin_3; If so, that is not a re-initialisation; it creates a new variable called C_Pin and assigns the value. Once your function ends, that new variable no longer exists.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.