BIN signal to HEX numbers

Hi everybody :slight_smile:

I have an issue with my programm and I cannnot figure out why its not working.
My arduino board is connected to a clock signal and I want to convert the binary source
to a hexadecimal code.
Has somebody ever made something like that before ?
I tried to accomplish a functional programm by using basic staff, but it does not work

Kind regards
Dinochio

Bin_Hex4.PNG

Pictures of code are a waste of time

Follow the advice in read this before posting a programming question and post or attach your code

Hi
Thanks for the Help! i have the ino data attached onto the post.

BIN_TO_HEX.ino (3.93 KB)

but it does not work

The code with NO comments does something. Why do you expect us to guess what the code does?

It gets analog data from somewhere. Why do you expect us to guess where the data comes from?

You expect the code to do something different from what it is doing. Why do you expect us to guess what you expect the code to do?

Why attach the code, when you could just as easily POST IT IN CODE TAGS?

int analogPin = 1; 
int ap1=0;
bool Array1[4];
char code1;
bool zahler = 0;
bool c = 0;
int k = -1; 
int q=0;

void setup() 

{
Serial.begin(2400);
}

void loop() 
{
 ap1 = analogRead(analogPin);
 if(ap1>350 or zahler == 1)
 {
   if(ap1>350 && k<3)
   {
      Array1[k]=1;
      k++;
   }
   else if(ap1<350 && k<3)
   {
      Array1[k]=0;  
      k++;  
   }
   else if(ap1>350 && k == 3)
   {
      Array1[k]=1;
      c = 1;
      k = 0;
   }
   else if(ap1<350 && k == 3)
   {
      Array1[k]=0;
      c = 1;
      k = 0;
   }
   
   if     (Array1[0] == 0 && Array1[1] == 0 && Array1[2] == 0 && Array1[3] == 0 && c == 1)
   {
     code1 = '0';
     c = 0;
     Array1[0] = 0;
     Array1[1] = 0;  
     Array1[2] = 0;  
     Array1[3] = 0;
   }
   else if(Array1[0] == 0 && Array1[1] == 0 && Array1[2] == 0 && Array1[3] == 1 && c == 1)
   {
     code1 = '1';
     c = 0;
     Array1[0] = 0;
     Array1[1] = 0;  
     Array1[2] = 0;  
     Array1[3] = 0;
   }
   else if(Array1[0] == 0 && Array1[1] == 0 && Array1[2] == 1 && Array1[3] == 0 && c == 1)
   {
     code1 = '2';
     c = 0;
     Array1[0] = 0;
     Array1[1] = 0;  
     Array1[2] = 0;  
     Array1[3] = 0;
   }
   else if(Array1[0] == 0 && Array1[1] == 0 && Array1[2] == 1 && Array1[3] == 1 && c == 1)
   {
     code1 = '3';
     c = 0;
     Array1[0] = 0;
     Array1[1] = 0;  
     Array1[2] = 0;  
     Array1[3] = 0;
   }
   else if(Array1[0] == 0 && Array1[1] == 1 && Array1[2] == 0 && Array1[3] == 0 && c == 1)
   {
     code1 = '4';
     c = 0;
     Array1[0] = 0;
     Array1[1] = 0;  
     Array1[2] = 0;  
     Array1[3] = 0;
   }
   else if(Array1[0] == 0 && Array1[1] == 1 && Array1[2] == 0 && Array1[3] == 1 && c == 1)
   {
     code1 = '5';
     c = 0;
     Array1[0] = 0;
     Array1[1] = 0;  
     Array1[2] = 0;  
     Array1[3] = 0;
   }
   else if(Array1[0] == 0 && Array1[1] == 1 && Array1[2] == 1 && Array1[3] == 0 && c == 1)
   {
     code1 = '6';
     c = 0;
     Array1[0] = 0;
     Array1[1] = 0;  
     Array1[2] = 0;  
     Array1[3] = 0;
   }
   else if(Array1[0] == 0 && Array1[1] == 1 && Array1[2] == 1 && Array1[3] == 1 && c == 1)
   {
     code1 = '7';
     c = 0;
     Array1[0] = 0;
     Array1[1] = 0;  
     Array1[2] = 0;  
     Array1[3] = 0;
   }
   else if(Array1[0] == 1 && Array1[1] == 0 && Array1[2] == 0 && Array1[3] == 0 && c == 1)
   {
     code1 = '8';
     c = 0;
     Array1[0] = 0;
     Array1[1] = 0;  
     Array1[2] = 0;  
     Array1[3] = 0;
   }
   else if(Array1[0] == 1 && Array1[1] == 0 && Array1[2] == 0 && Array1[3] == 1 && c == 1) 
   {
     code1 = '9';
     c = 0;
     Array1[0] = 0;
     Array1[1] = 0;  
     Array1[2] = 0;  
     Array1[3] = 0;
   }
   else if(Array1[0] == 1 && Array1[1] == 0 && Array1[2] == 1 && Array1[3] == 0 && c == 1)
   {
     code1 = 'A';
     c = 0;
     Array1[0] = 0;
     Array1[1] = 0;  
     Array1[2] = 0;  
     Array1[3] = 0;
   }
   else if(Array1[0] == 1 && Array1[1] == 0 && Array1[2] == 1 && Array1[3] == 1 && c == 1)
   {
     code1 = 'B';
     c = 0;
     Array1[0] = 0;
     Array1[1] = 0;  
     Array1[2] = 0;  
     Array1[3] = 0;
   }
   else if(Array1[0] == 1 && Array1[1] == 1 && Array1[2] == 0 && Array1[3] == 0 && c == 1)
   {
     code1 = 'C';
     c = 0;
     Array1[0] = 0;
     Array1[1] = 0;  
     Array1[2] = 0;  
     Array1[3] = 0;
   }
   else if(Array1[0] == 1 && Array1[1] == 1 && Array1[2] == 0 && Array1[3] == 1 && c == 1)
   {
     code1 = 'D';
     c = 0;
     Array1[0] = 0;
     Array1[1] = 0;  
     Array1[2] = 0;  
     Array1[3] = 0;
   }
   else if(Array1[0] == 1 && Array1[1] == 1 && Array1[2] == 1 && Array1[3] == 0 && c == 1) 
   {
     code1 = 'E';
     c = 0;
     Array1[0] = 0;
     Array1[1] = 0;  
     Array1[2] = 0;  
     Array1[3] = 0;
   }
   else if(Array1[0] == 1 && Array1[1] == 1 && Array1[2] == 1 && Array1[3] == 1 && c == 1)
   {
     code1 = 'F';
     c = 0;
     Array1[0] = 0;
     Array1[1] = 0;  
     Array1[2] = 0;  
     Array1[3] = 0;
   }  
 Serial.println(code1);
 zahler = 1;
 }
}

My arduino board is connected to a clock signal and I want to convert the binary source
to a hexadecimal code.

The only thing that the code reads is an analogue input which will have a value of between 0 and 1023 which you read into an int. You seem to be trying to convert this into a single hexadecimal digit which does not make sense. Is that really what you want to do ?

Don't know what it's supposed to be outputting, but it seems to be working for me. Mind you, I could think of easier ways to get HEX output.