Go Down

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

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

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

CrossRoads

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.

CrossRoads

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
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy