Hello everyone. So I need to have a serial display system for my 8 bit counter. How it works is that you press a button, there is going to be a 1 second delay, then it will count 1-255 in binary language, which is represented by 8 led lights. But now, I need to use a serial display to show the count from 1-255, which I am having no idea how to program it. Please help!!!!
This is the program I used for the 8 bit counter
<int button = 2;
int ledPin[] = {
10, 9, 8, 7, 6, 5, 4, 3};
int maxCount = 256;
int delayInterval = 250;
for (int counter = 0; counter < maxCount; counter++)*
{*
displayBinary(counter);*
delay(delayInterval);*
}*
}* } void displayBinary(byte numToShow) {
for (int i = 0; i < 8; i++)*
{*
if (bitRead(numToShow, i) == 1)*
{*
_ digitalWrite(ledPin*, HIGH);_
_ }_
_ else*_ * {* _ digitalWrite(ledPin*, LOW); } } } >* Now all I need is a serial display that will show the decimal aspects of the code_
int button = 2;
int ledPin[] = {
10, 9, 8, 7, 6, 5, 4, 3};
int maxCount = 256;
int delayInterval = 250;
void setup()
{
for (int i = 0; i < 9; i++)
{
pinMode(button, INPUT);
pinMode(ledPin*, OUTPUT);* } } void loop() {
if (digitalRead (button))*
{*
delay (1000) ;*
for (int counter = 0; counter < maxCount; counter++)*
{*
displayBinary(counter);*
delay(delayInterval);*
}*
}* } void displayBinary(byte numToShow) {
for (int i = 0; i < 8; i++)*
{*
if (bitRead(numToShow, i) == 1)*
{*
_ digitalWrite(ledPin*, HIGH);_
_ }_
_ else*_ * {* _ digitalWrite(ledPin*, LOW); } } [/quote] > This was the code I was using previously. So all I need to do is put the serial.print part into my for loop function? }*_
int button = 2;
int ledPin[] = {
10, 9, 8, 7, 6, 5, 4, 3};
int maxCount = 256;
int delayInterval = 250;
void setup()
{
for (int i = 0; i < 9; i++)
{
pinMode(button, INPUT);
pinMode(ledPin*, OUTPUT);* } } void loop() {
if (digitalRead (button))*
{*
delay (1000) ;*
for (int counter = 0; counter < maxCount; counter++)*
{*
displayBinary(counter);*
delay(delayInterval);*
}*
}* } void displayBinary(byte numToShow) {
for (int i = 0; i < 8; i++)*
{*
if (bitRead(numToShow, i) == 1)*
{*
_ digitalWrite(ledPin*, HIGH);_
_ }_
_ else*_ * {* _ digitalWrite(ledPin*, LOW); } } [/quote]* So this was the code that I used to convert from decimal to binary, so how would I convert binary to hexadecimal?_
jremington:
The function displayBinary() reveals the individual bits of a binary number using LEDs.
No it flashes an LED very quickly in a non return to zero form which visually is totally useless.
Face it if the OP has trouble distinguishing between quote and code then no wonder it is a poor question.
How is this hex going to be displayed? In as clack handed way as the binary? If so then the answer is what you have also displays hex.