Hello there. Basically new at this. BUT, while I can find code for lots of methods of constructing a binary converter on Arduino, I am looking some help to code for converting a number up to 255 which the user manually inputs to a prompt while running the sketch and then that number, after being inputed by the use is converted to binary displayed in an 8 led setup.
My reference in the topic header to "Cin" may be wrong. As I said, I dont know much.
Anybody aware of anything?
I think the easiest way to do this is using a shift register. So you just connect the leds to the SR pins and output the user inputted number to the SR by shiftOut() command.
The Example1 of Arduino Shift Register tutorial do exactly what you want:
Hello, I would like to see a sketch which takes a number (up to 255) that the user inserts in the serial buffer and represents that in Binary display of 8 LED's on a breadboard. Can quite find a sketch that does this - although there are lots of various converters. Am relatively new to this.
Thanks
I can give you a starter sketch. I just reads the serial input and tells what number was entered.
// Starter sketch
// Forum: https://forum.arduino.cc/t/converting-an-input-decimal-to-led-binary-output/1169026
// This Wokwi project: https://wokwi.com/projects/376015409717764097
void setup()
{
Serial.begin(115200);
Serial.println("Type a number");
}
void loop()
{
if(Serial.available() > 0)
{
// Something has been received.
// The Arduino .parseInt() has a timeout of 1 second.
int x = Serial.parseInt();
Serial.print("Your number is ");
Serial.println(x);
// clear any trailing CarriageReturn and/or LineFeed
while(Serial.available() > 0)
{
Serial.read();
}
delay(500);
Serial.println("Type a number");
}
}
Try the sketch in Wokwi simulation:
If you want to continue with my Wokwi project, then make an account in Wokwi (it is free) and use "Save as" to store it as your own project. Be sure to save any changes before closing that webpage of Wokwi.
Wokwi has a breadboard, but I didn't use it.
Your two or more topics on the same or similar subject have been merged.
Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.
Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.
Repeated duplicate posting could result in a temporary or permanent ban from the forum.
Could you take a few moments to Learn How To Use The Forum
It will help you get the best out of the forum in the future.