I am using ARDUINO case 2 has some issues that reason binary to decimal not working please someone solve this? #include
Posted: Sat May 14, 2022 3:44 pm
I am using ARDUINO
case 2 has some issues that reason binary to decimal not
working please someone solve this?
#include
#include
const byte ROWS = 4;
const byte COLS = 3;
char keys [ROWS][COLS]= {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0',' '},
};
byte rowPins[ROWS] = {7,6,5,4};
byte colPins[COLS] = {3,2,1};
LiquidCrystal lcd (13, 12, 11, 10, 9, 8);
Keypad keypad = Keypad(makeKeymap (keys), rowPins,colPins, ROWS,
COLS);
char key = keypad.getKey (); //key
void setup() {
lcd.begin(16, 2);
}
void loop()
{
start:
char volver =0;
char num=0,ch=0;
char n[8]= {0,0,0,0,0,0,0,0};
int i=0,no=0;
int x=0,LEN=0,B[8]={0,0,0,0,0,0,0,0};
lcd.print("Give Number:");
lcd.setCursor(12,0);
for(i=0; num!=' ';i++)
{
num= keypad.waitForKey();// wait until a key is pressed
n=num;
lcd.print(num);
}
no=atof(n);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("1)Binary 2)Decimal");
lcd.setCursor(0,1);
ch=keypad.waitForKey(); //key
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Give Number:");
lcd.setCursor(12,0);
lcd.print(no);
lcd.setCursor(0,1);
switch(ch)
{
case '1' :
lcd.print("Binary:");
lcd.setCursor(7,1);
if(no==0)
{
lcd.print("0");
}
while (no>0)
{
B[LEN]=no%2;
no=no/2;
LEN++;
};
for(x=LEN-1;x>-1;x--)
{
lcd.print(B[x]);
}break;
case '2' :
int decimalVal=0 ,baseVal=1;
lcd.print("Decimal :");
lcd.setCursor(9,1);
if(no==0)
{
lcd.print("0");
}
while (no>0)
{
B[LEN]=no%10;
no=no/10;
decimalVal += B[LEN] * baseVal;
baseVal = baseVal * 2;
LEN++;
};
for(x=LEN-1;x>-1;x--)
{
lcd.print(B[x]);
}break;
default:
lcd.clear();
lcd.setCursor(0,0);
lcd.print("wrong Choice");
}
volver=keypad.waitForKey();
if(volver=='*')
{
lcd.clear();
lcd.setCursor(0,0);
goto start;
}
else{
}
case 2 has some issues that reason binary to decimal not
working please someone solve this?
#include
#include
const byte ROWS = 4;
const byte COLS = 3;
char keys [ROWS][COLS]= {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0',' '},
};
byte rowPins[ROWS] = {7,6,5,4};
byte colPins[COLS] = {3,2,1};
LiquidCrystal lcd (13, 12, 11, 10, 9, 8);
Keypad keypad = Keypad(makeKeymap (keys), rowPins,colPins, ROWS,
COLS);
char key = keypad.getKey (); //key
void setup() {
lcd.begin(16, 2);
}
void loop()
{
start:
char volver =0;
char num=0,ch=0;
char n[8]= {0,0,0,0,0,0,0,0};
int i=0,no=0;
int x=0,LEN=0,B[8]={0,0,0,0,0,0,0,0};
lcd.print("Give Number:");
lcd.setCursor(12,0);
for(i=0; num!=' ';i++)
{
num= keypad.waitForKey();// wait until a key is pressed
n=num;
lcd.print(num);
}
no=atof(n);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("1)Binary 2)Decimal");
lcd.setCursor(0,1);
ch=keypad.waitForKey(); //key
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Give Number:");
lcd.setCursor(12,0);
lcd.print(no);
lcd.setCursor(0,1);
switch(ch)
{
case '1' :
lcd.print("Binary:");
lcd.setCursor(7,1);
if(no==0)
{
lcd.print("0");
}
while (no>0)
{
B[LEN]=no%2;
no=no/2;
LEN++;
};
for(x=LEN-1;x>-1;x--)
{
lcd.print(B[x]);
}break;
case '2' :
int decimalVal=0 ,baseVal=1;
lcd.print("Decimal :");
lcd.setCursor(9,1);
if(no==0)
{
lcd.print("0");
}
while (no>0)
{
B[LEN]=no%10;
no=no/10;
decimalVal += B[LEN] * baseVal;
baseVal = baseVal * 2;
LEN++;
};
for(x=LEN-1;x>-1;x--)
{
lcd.print(B[x]);
}break;
default:
lcd.clear();
lcd.setCursor(0,0);
lcd.print("wrong Choice");
}
volver=keypad.waitForKey();
if(volver=='*')
{
lcd.clear();
lcd.setCursor(0,0);
goto start;
}
else{
}