I already learned prior about concatenating strings together. I am now trying to apply this information to multiplying together a float variable and a basic number. There is other stuff going on in my program so I will paraphrase my code with notes:
//GLOBAL VARIABLES
int yellowLED = A1;
int numYellowBlinks;
int yellowOnTime=500;
int yellowOffTime=500;
float yellowLEDVolts;
void setup(){
//INTIALIZES PORTS
pinMode (redLED, OUTPUT);
pinMode (yellowLED, OUTPUT);
Serial.begin(2000000);
//BEGINS SERIAL PROMPTS
Serial.println("How Many Times Do You Want the Yellow LED to Blink? "); //SERIAL: Output Message
while (Serial.available()==0 ){ //SERIAL: Wait for User Input
}
numYellowBlinks = Serial.parseInt(); //SERIAL: Read and Assign Data
Serial.println(""); //SERIAL: Break Line
Serial.println("How Many Volts Would You Like to Use?"); //SERIAL: Output Message
while (Serial.available()==0){ //SERIAL: Wait for User Input
}
yellowLEDVolts = Serial.parseFloat(); //SERIAL: Read and Assign User Input
Serial.println("");
}
void loop(){
for (int j=1; j<=numYellowBlinks; j=j+1){ //Blinks LED # of Times
Serial.print("You are on Blink #: "); //SERIAL: Output Message
Serial.println(j); //SERIAL: Output Data
analogWrite (yellowLED, 51*yellowLEDVolts); //Applies analog voltage
delay (yellowOnTime); //Creates a delay (in MS) from global int var 'yellowOnTime'
analogWrite (yellowLED, 0); //Applies analog voltage off
delay (yellowOffTime); //Creates a delay (in MS) from global int var 'yellowOffTime'
}
The video series I'm watching is going over how to convert digital integer ON/OFF (aka 0 or 5volts) into analog 0-255 (0-5volts). In his example, he enters the 0-255 number directly where "51*yellowLEDVolts" is in in the bottom section of my code loop and it seems to work. However, I wanted to add a global float variable so I can prompt the user to enter number of volt number through the serialPort and have it automatically multiply the value by 51 in order to change the brightness of the circuit. But it does not work. It won't even turn on unless it is exactly 0 or 5 volts. Why?