AUTOMATIC BINARY COUNTER INPUT BUTTON PLEASE HEEEEEEEEEEEEEELP

K, so i have an 8 bit automatic binary counter, in which the moment you start the code, it will count up

to 256. But the problem is, I need to put the push button to start the count. So you push the button, it

will have a 1 second delay, then start the binary count. But the thing is, I can't understand how to

program it.

PLEASE HEEEEELP

this is the code:

int ledPin[] = {
9, 8, 7, 6, 5, 4, 3, 2
};
int maxCount = 256;
int delayInterval = 250;

void setup()
{
for (int i = 0; i < 9; i++)
{

pinMode(ledPin*, OUTPUT);*

  • }*
    }
    void loop()
    {
  • 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);
    }
    }
    }*_

WEEEEEEEEEEEEELL, #7 below:

http://forum.arduino.cc/index.php/topic,148850.0.html

PLEASE HEEEEEEEEEEEEEELP

OK. That's spelled HELP!

K, so i have an 8 bit automatic binary counter, in which the moment you start the code, it will count up

to 256. But the problem is, I need to put the push button to start the count. So you push the button, it

will have a 1 second delay, then start the binary count. But the thing is, I can't understand how to

program it.

PLEASE HEEEEELP

this is the code:

int ledPin[] = {
9, 8, 7, 6, 5, 4, 3, 2
};
int maxCount = 256;
int delayInterval = 250;

void setup()
{
for (int i = 0; i < 9; i++)
{

pinMode(ledPin, OUTPUT);
}
}

void loop()
{
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);
}
}

}

The naive approach with delay would be:

void loop()
{
  if (digitalRead (button))
  {
    delay (1000) ;
    for (int counter = 0; counter < maxCount; counter++)
    {
      displayBinary(counter);
      delay(delayInterval);
    }
  }
}

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;

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);
    }
    }
    }
    >*
    Now all I need is a serial display that will show the decimal aspects of the code_

Because you did not use code tags </> so your code were readable and unmangled by the forum system I can only comment what I see.

This code will not compile (or not work as expected).

Does it work now. Please, i do need help on this.
And the program does work, I just need a serial display.

// in setup
  Serial.begin(9600);
// in displayBinary
  Serial.println(numToShow, 2);

Is there any way to convert from decimal to binary number to hexadecimal number?

I am sure you realize these are formats for display.

Please tell us what you are trying to do.

Computers and microcontrollers are really good at presenting binary numbers in different formats.

Serial.print(number, HEX);

Prints the hexadecimal representation of "number".

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?_

You did not convert from dec to anything!

Mark

The function displayBinary() reveals the individual bits of a binary number using LEDs.

Don't waste our time by crossposting!

Mark

Mods - All the OP's posts are the same question and 4 or 5 contain the same post!

M

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.

This guy has been posting the same code on a number of different threads.

Mark