Hi everyone, I'm very new to coding and just learned the basics. I was hoping someone could show me the best way to take 2 different inputs and produce 1 output from those 2 inputs.
input 1: this number changes constantly between 0-300 read on input pin
input 2: has 3 numbers between 0-255 (user adjustable) example: 75, 245, 110
If the first input is between 0-100, i need to multiply it by in this case 75
If the first input is between 100-200, i need to multiply it by in this case 245
If the first input is between 200-300, i need to multiply it by in this case 110
Why do you need to read input 2? The number to use as the multiplicand is not determined by reading input 2 it is determined by the range of values of input 1.
Keeping in mind the questions raised above, you could do if-else if -else statements, like the following pseudocode:
read in input a
read in input b
if (a < 101) {do this action, e.g. multiply a by value of b}
else if (a< 201) {do second thing}
else {do last option}
This is assuming your inputs are integers and will never be above 300 or below 0, and that value b can only be one value at a time.
If you need to store 3 different values for b, then you would either need to store them in an array
I did something like this... (this is a much simplified version of my code)
PS im just a beginner, I found that code somewhere online...
pulseState = map(pulse, 0, 300, 0, 2);
switch (pulseState) {
case 0: // starts at 0 to 100
(code here)
break;
case 1: // starts at 100 to 200
(code here)
break;
case 2: // starts at 200 to 300
(code here)
break;
default:
(outside of 0-300 code here)
break;