Electronic dice programming
hello everyone!
i working on making electronic dice, has 7 diode's in shape:
0 0 0
0
0 0 0
with can make numbers dice has.
i got configured in such way press of button dice show next number:
example: dice shows 1 -> pushbutton -> 2.
i got 2nd button , want work this:
if press 2nd button, dice show number came before current one.
example: dice shows 5 -> pushbutton2 -> 4.
i'm using internal pull 2nd 1 , pull transistor 1st one. code:
i working on making electronic dice, has 7 diode's in shape:
0 0 0
0
0 0 0
with can make numbers dice has.
i got configured in such way press of button dice show next number:
example: dice shows 1 -> pushbutton -> 2.
i got 2nd button , want work this:
if press 2nd button, dice show number came before current one.
example: dice shows 5 -> pushbutton2 -> 4.
i'm using internal pull 2nd 1 , pull transistor 1st one. code:
code: [select]
//a program simulates real life dice.
//all leds attached board
int led = 2;
int led2 = 3;
int led3 = 4;
int led4 = 5;
int led5 = 6;
int led6 = 7;
int led7 = 8;
int btn = 9;
int btn2 = 10;
// setup routine runs once when press reset:
void setup() {
// initialize digital pin output.
pinmode(led, output);
pinmode(led2, output);
pinmode(led3, output);
pinmode(led4, output);
pinmode(led5, output);
pinmode(led6, output);
pinmode(led7, output);
pinmode(btn, input); //button 1
pinmode(btn2, input_pullup); //button 2
}
void clickthebutton() { //button 1.
while( digitalread( btn ) == low ) {}
while( digitalread( btn ) == high ) {}
}
// loop routine runs on , on again forever:
void loop() {
digitalwrite(led5, high);
clickthebutton();
digitalwrite(led5, low);
digitalwrite(led, high);
digitalwrite(led4, high);
clickthebutton();
digitalwrite(led, low);
digitalwrite(led4, low);
digitalwrite(led3, high);
digitalwrite(led5, high);
digitalwrite(led6, high);
clickthebutton();
digitalwrite(led3, low);
digitalwrite(led5, low);
digitalwrite(led6, low);
digitalwrite(led3, high);
digitalwrite(led6, high);
digitalwrite(led4, high);
digitalwrite(led, high);
clickthebutton();
digitalwrite(led3, low);
digitalwrite(led6, low);
digitalwrite(led4, low);
digitalwrite(led, low);
digitalwrite(led3, high);
digitalwrite(led6, high);
digitalwrite(led4, high);
digitalwrite(led, high);
digitalwrite(led5, high);
clickthebutton();
digitalwrite(led5, low);
digitalwrite(led3, low);
digitalwrite(led6, low);
digitalwrite(led4, low);
digitalwrite(led, low);
digitalwrite(led3, high);
digitalwrite(led7, high);
digitalwrite(led4, high);
digitalwrite(led2, high);
digitalwrite(led, high);
digitalwrite(led6, high);
clickthebutton();
digitalwrite(led, low);
digitalwrite(led3, low);
digitalwrite(led7, low);
digitalwrite(led4, low);
digitalwrite(led6, low);
digitalwrite(led2, low);
}
hi
is code posted working button1?
you using pull-up transistors? mean pull-up resistors?
if want dice display random numbers, don't need 2 buttons. need 1 button tell arduino when make new number.
and maybe easiest way use switch case.
you can learn switchcase here:
http://arduino.cc/en/tutorial/switchcase
and here project of arduino dice, produces random numbers, , used switchcase...
http://www.instructables.com/id/arduino-led-dice/?allsteps
good luck!
=)
is code posted working button1?
you using pull-up transistors? mean pull-up resistors?
if want dice display random numbers, don't need 2 buttons. need 1 button tell arduino when make new number.
and maybe easiest way use switch case.
you can learn switchcase here:
http://arduino.cc/en/tutorial/switchcase
and here project of arduino dice, produces random numbers, , used switchcase...
http://www.instructables.com/id/arduino-led-dice/?allsteps
good luck!
=)
Arduino Forum > Using Arduino > Programming Questions > Electronic dice programming
arduino
Comments
Post a Comment