Go Down

Topic: Binary code, button, and 6 LEDs (Read 1 time)previous topic - next topic

Sam_Morland126

Apr 30, 2012, 08:46 am
I need to program my arduino to display in binary code over 6 LEDs the number of times a button has been pressed. I saw a tutorial on it but I'm still confused can anyone help? This is the first time I have ever done anything with programming.

sirbow2

#1
Apr 30, 2012, 02:45 pm
what are you confused on? what tutorial?
http://dduino.blogspot.com all my Arduino/electronic projects!!!

{NEW} Getting Started, Learning, Reference + FAQ PDF!!:
[url]http://ar

#2
Apr 30, 2012, 06:58 pm
Try this Learning Tutorial
http://arduino.cc/en/Tutorial/Debounce

When you have that working, then you can add code to start counting.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

#3
Apr 30, 2012, 10:03 pm
Then once you can detect  button push, you can show it on the output pins:

if (button_was_pressed == 1){
button_count = button_count +1;
}
// mask off the bits, and drive the LEDs.
LED0state = button_count & B00000001; // results in B0000000x, with being HIGH or LOW (1 or 0)
digitalWrite (LEDbit0, LED0state); // LEDbit0 defined as an output pin

LED1state = (button_count & B00000010)>>1; // mask for bit 1, shift into 0/1 position
digitalWrite (LEDbit1, LED1state);

LED2state = (button_count & B00000100)>>2; // mask for bit 2, shift into 0/1 position
digitalWrite (LEDbit2, LED2state);

LED3state = (button_count & B00001000)>>3; // mask for bit 3, shift into 0/1 position
digitalWrite (LEDbit3, LED3state);

LED4state = (button_count & B00010000)>>4; // mask for bit 4, shift into 0/1 position
digitalWrite (LEDbit4, LED4state);

LED5state = (button_count & B00100000)>>5; // mask for bit 5, shift into 0/1 position
digitalWrite (LEDbit5, LED5state);

if (button_count == B01000000){ button_count = 0;} // not really needed, as last 2 bits can be ignored
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up