Arduino Uno R3
Hello all im having difficulty with the switch statements and getting back a return. The project is finding out the type of resistor the user inputs with character. It keeps returning the same numbers regardless what i ask for.
#include <math.h>
int convert_color(int h);
void setup()
{
Serial.begin(115200);
Serial.print("RESISTOR COLOR-CODE PROGRAM\n\n");
Serial.print("Input three characters corresponding to the three color bands on a resistor:\n");
Serial.print("K or k for BLACK\tN or n for BROWN\tR or r for RED\t\tO or o for ORANGE\tY or y for YELLOW\n");
Serial.print("G or g for GREEN\tU or u for BLUE\t\tV or v for VIOLET\tE or e for GREY\t\tW or w for WHITE\n");
}
void loop()
{
int x,y,q,t,h;
while(Serial.available()==0);
x= Serial.parseInt();
x= convert_color(h);
while(Serial.available()==0);
y= Serial.parseInt();
y= convert_color(h);
while(Serial.available()==0);
q= Serial.parseInt();
q= convert_color(h);
t=pow(10,q);
Serial.print("Input three characters: ");
Serial.print("\n");
Serial.print(x);Serial.print(y);Serial.print(t);Serial.print("Ohms");
}
int convert_color(int h)
{
int z;
switch (h)
{
case 'K':
case 'k':
z=0;
break;
case 'N':
case 'n':
z=1;
break;
case 'R':
case 'r':
z=2;
break;
case 'O':
case 'o':
z=3;
break;
case 'Y':
case 'y':
z=4;
break;
case 'G':
case 'g':
z=5;
break;
case 'U':
case 'u':
z=6;
break;
case 'V':
case 'v':
z=7;
break;
case 'E':
case 'e':
z=8;
break;
case 'W':
case 'w':
z=9;
break;
}
return(z);
}