Pages: [1]   Go Down
Author Topic: Binary code, button, and 6 LEDs  (Read 700 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Sr. Member
****
Karma: 1
Posts: 486
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

what are you confused on? what tutorial?
Logged

http://dduino.blogspot.com all my Arduino/electronic projects!!!

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

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 27387
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Try this Learning Tutorial
http://arduino.cc/en/Tutorial/Debounce

When you have that working, then you can add code to start counting.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 27387
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pages: [1]   Go Up
Jump to: