Code for digital caliper

Any feedback and advise for this so far please? It doesnt compile currently as it doesnt like my bcdtodec call.

  1. finds which analog input is active (1-8)

  2. calculates the what the voltage level is (1-8)

  3. converts the results for both to binary

  4. combines them into a single binary number

  5. converts back to decimal

  6. not completed yet, but it will then compare the possible 64 variations and some more mathematics, then display the result on an LCD.

int i;  // large plate
int x;
int platelet;  // small platelet
int plate;  // large plate
int volts;
int w;
byte calctotal;

void setup()
{
}


void loop()
{
  // locates which of the 8 input plates is being used
  for (i = 19; i < 27; ++i) {
    if ((volts = analogRead(i)) > 100)
      voltage(volts);
  int decToBcd(byte i);
  int decToBcd(byte w);
  int calc(byte w, byte i);
  byte bcdtodec(byte calctotal};
  
}

int voltage(int x)
{ 
  float volts = x * (5.0 /1023.0);
// locates which of the 8 voltages is being received
  if (volts < 0.6535)
    w = (1);
  else if (volts < 1.2595)
    w = 2;
  else if (volts < 1.874)
    w = (3);
  else if (volts < 2.4915)
    w = (4);
  else if (volts < 3.1105)
    w = (5);
  else if (volts < 3.7305)
    w = (6);
  else if (volts < 4.3515)
    w = (7);
  else
    w = (8);

  return (int)volts;
}



byte decToBcd(byte val) // Convert voltage number and plate number to binar
{
return ( (val/10*16) + (val%10) );
}
 





  int calc(byte y, byte z)
  {
    uint8_t lower_part = y;
    uint8_t upper_part = z;
    uint8_t result = 0; // accumulator to build result
    result |= (lower_part & 0b00001111); // i
    result |= ((upper_part & 0x00001111) << 4); // 
    byte calctotal = result;
return result; 
  }


// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}

Project.ino: In function 'void loop()':
Project:23: error: expected ',' or '...' before '}' token
Project:23: error: expected `)' before '}' token
Project:23: error: expected initializer before '}' token

Please post you pictures at a sensible size that is far too big to actually see anything.

This line:-

byte bcdtodec(byte calctotal};

should be

byte bcdtodec(byte calctotal);
}
  int decToBcd(byte i);
  int decToBcd(byte w);
  int calc(byte w, byte i);
  byte bcdtodec(byte calctotal};

Are not function calls!! A function call looks like

  int a = func (b) ;

Perhaps you mean something like

  int a = bcdtodec (calc (dectobcd (w), dectobcd (i)) ;

But the whole thing looks completely suspect, bcd is not binary....

Are you just trying to parse a decimal string to binary (atoi() does this)?

you declare function prototypes within a function, that will not work.

This is a partly rewrite that should get you started again. It also shows how to work with functions.

void setup()
{
  Serial.begin(115200);
  Serial.println("Caliper 0.0");
}

void loop()
{
  int plate = determinePlate();
  Serial.println(plate);

  float volts = getVoltage(plate);
  Serial.println(volts, 3); // 3 decimals

  int x = decToBcd(plate);
  Serial.println(x, DEC);  // to enforce printing as an int.


  // additional code

}

int determinePlate()
{
  for (int i = 19; i < 27; ++i) 
  {
    if (analogRead(i)  > 100) return i;
  }
  return -1; //none found !!
}

float getVoltage(int p)
{
  return analogRead(p) * 5.0 / 1024.0;
}

byte decToBcd(byte val) // Convert voltage number and plate number to binar
{
  return ( (val/10*16) + (val%10) );
}

byte bcdToDec(byte val)
{
  return ( (val/16*10) + (val%16) );
}

int calc(byte lower_part , byte upper_part )
{
  uint8_t result = lower_part & 0b00001111;
  result |= ((upper_part & 0x00001111) << 4); // 
  return result; 
}

give it a try

Thank you for the feedback guys, and thank you for that rewrite buddy!