resistor code project

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);
}

Go on, give us a hint...what same numbers does it always return?

Steve

00 ohms

Some resistors are coded in3 colours, some in 4 clours. Some have a gold/silver line to tell the accurazy. Can that be an issue?

no our professor just wants the first 3 so something like 12k ohms or 11ohms

Okey, 3 colours. the first to tell the numbers and the last, 3:rd, tells the magnitude. Check the reception from Serial, check the math typing simple examples.
@Robin2 has written advice about how to pick up data from serial. Have a look.

sweet thanks

Robin2's serial input basics tutorial.

groundFungus:
Robin2's serial input basics tutorial.

Thanks!

:slight_smile: I have it bookmarked for ease of access. I use it a lot.

I've tried the same now.

Your taking an int and comparing it to a char. I'd start there.

-jim lee