Need to wait until end of Function?
hi
following work on trying understand 4051 multiplexer (also discussed - , helped - in thread: http://forum.arduino.cc/index.php?topic=171621.0) next step have 8 buttons on 4051 multiplexer lighting 8 leds on 74hc595 shift register.
i found nice library (shifter - http://bildr.org/2011/08/74hc595-breakout-arduino/) simplifies process of using shift register.
what trying achieve?
when press button, corresponding led blink 3 times. if press button1 led1 should blink 3 times, if press button4 led4 should blink 3 times,...
at moment code this:
the code more or less working wanted.
when press button corresponding led blinks.
but problem while leds blinking nothing else can happen. needs wait until ledblinkslow function on before can go on...
is there way make each "button+led" can independent of others? can press button while blinking?
(i use on midi foot controller, wouldn't want have wait second between button pushes!)
i hope understand mean...
thanks!
following work on trying understand 4051 multiplexer (also discussed - , helped - in thread: http://forum.arduino.cc/index.php?topic=171621.0) next step have 8 buttons on 4051 multiplexer lighting 8 leds on 74hc595 shift register.
i found nice library (shifter - http://bildr.org/2011/08/74hc595-breakout-arduino/) simplifies process of using shift register.
what trying achieve?
when press button, corresponding led blink 3 times. if press button1 led1 should blink 3 times, if press button4 led4 should blink 3 times,...
at moment code this:
code: [select]
#include <clickbutton.h>
#include <shifter.h>
const int buttonpin = a0;
int buttonvalue[8] = {0,0,0,0,0,0,0,0};
int lastbuttonvalue[8] = {0,0,0,0,0,0,0,0};
int b0 = 0;
int b1 = 0;
int b2 = 0;
#define ser_pin 7 // ser_in
#define rclk_pin 6 // l_clock
#define srclk_pin 5 // clock
#define num_registers 1 //how many shift registers in chain
// initialize shifter using shifter library
shifter shifter(ser_pin, rclk_pin, srclk_pin, num_registers);
void setup() {
pinmode(10,output); // s0
pinmode(9, output); // s1
pinmode(8, output); // s2
serial.begin(115200);
} // end void setup
void loop() {
for (int buttoncount = 0; buttoncount < 8; buttoncount++){
b0 = bitread(buttoncount,0);
b1 = bitread(buttoncount,1);
b2 = bitread(buttoncount,2);
digitalwrite(10,b0);
digitalwrite(9,b1);
digitalwrite(8,b2);
buttonvalue[buttoncount] = digitalread(buttonpin);
if (buttonvalue[buttoncount] == click_singleclick && buttonvalue[buttoncount] != lastbuttonvalue[buttoncount]) {
serial.println(buttoncount);
ledblinkslow(buttoncount);
}
lastbuttonvalue[buttoncount] = buttonvalue[buttoncount];
} // end buttoncount
} // end void loop
void ledblinkslow (int led2light) {
shifter.setpin(led2light,high);
shifter.write();
delay(200);
shifter.clear();
shifter.write();
delay(200);
shifter.setpin(led2light,high);
shifter.write();
delay(200);
shifter.clear();
shifter.write();
delay(200);
shifter.setpin(led2light,high);
shifter.write();
delay(200);
shifter.clear();
shifter.write();
}
the code more or less working wanted.
when press button corresponding led blinks.
but problem while leds blinking nothing else can happen. needs wait until ledblinkslow function on before can go on...
is there way make each "button+led" can independent of others? can press button while blinking?
(i use on midi foot controller, wouldn't want have wait second between button pushes!)
i hope understand mean...
thanks!
take @ "blink without delay" example in ide's file->examples menu.
you'll see has replaced delay() calls comparisons of millis() function.
you'll see has replaced delay() calls comparisons of millis() function.
Arduino Forum > Using Arduino > Programming Questions > Need to wait until end of Function?
arduino
Comments
Post a Comment