I'm trying to have one button to select 3 different status (select, read memory, write memory), and then read a group of 6 buttons
for 'pressed'; basically, state of single button will assign 96 to KVal, and state of group button will add 1 or 2 or 3 ecc to KVal,
based on which button is pressed. Then based on the value of KVal do something.
is this code, shamelessly copied and adapted from the net!, something that could work?
are b and KVal kept for the whole loop?
Thanks for help guys!!!!
Ciao
Armando
.......
void loop()
{
// Get button event and act accordingly
int b = checkButton();
if (b == 1) clickEvent();
if (b == 2) doubleClickEvent();
if (b == 3) holdEvent();
//if (b == 4) longHoldEvent();
}
// put here switch case letters from 'a' to whatever is needed
// switch KVal
// {
// case KVal=='a':
// do something...
// ect....
//
//=================================================
// Events to trigger by click and press+hold
void clickEvent()
{
KVal=96
ledVal1 = !ledVal1;
digitalWrite(ledPin1, ledVal1);
for (i=0 ; i < 6; i ++)
{
PushPinVal = digitalRead(PushPin[i]);
swtich PushPinVal
{
case 1:
KVal = KVal+1
Break;
case 2:
KVal = KVal+2
Break;
case 3:
KVal = KVal+3
Break;
case 4:
KVal = KVal+4
Break;
case 5:
KVal = KVal+5
Break;
case 6s:
KVal = KVal+5
Break;
}
}
First thing you need to do is write down very carefully the complete sequence(s) of button presses that you want with particular care given to the order in which things must happen. Writing this down will probably represent 70% of the intellectual effort needed to create the program so it is not wasted effort.
Regarding the code and the question "something that could work?" - try it and see. If it does not do what you want then tell us what it actually does and what you want to be different.
thanks Robin2 for reply! indeed great advertise! (which I knew about but didn't think to put in place). And writing down roughly the sequences as they appear on my mind, just realized that code was missing an important part that's to toggle the state of the switched....
I'll go through the lessons you linked slowly slowly and try do get them digested...
In the mean time here's the sequences I was thinking about...
Project Description :
Effects looper with 6 programmable loops
6 buttons for loops selection, only one loop at a time
1 button 3 states (click, double click, long click) for select preset - select loops to build a preset - memorize a preset
**optional mute audio before switching relays.
Relay pins
8 to 13
preset2/loop2 selector pins
2 to 7
LED pin
19
Selector pin
14
check (button_3_state state) // click, double click, long click
** status has to toggle on/off and kept to proceed on **
// status=
// 1 recall_preset(1-6) mode
// 2 preset_channel_selector(1-6) to memorize
// 3 select preset to memorize
** main loop, takes the looper is almost used for selecting loops than for change and memorize loops **
if (button_3_state state) = 1 //select loops
turn led on
check (Buttons_1_6) state //one could be on at a time and status has to toggle on/off and kept
if (Buttons_1_6) state = on
restore from EEPROM relay(1-6) (value(1-6), state(1=on-0=off)) mute audio with optocoupler //optional
turn on/off relay(1-6) based on relay value state (on/off)
if (button_3_state) state = 2 //preset_channel_selector(1-6) to memorize
blink led slow
check (Buttons_1_6) state // several/all could be on at a time and status of all has to toggle on/off and kept
if (buttons_1_6 state) = on // check what buttons are on
turn on/off relay(1-6) based on button state value (on/off)
memorize status in array relay[1-6], [1 or 0]
if (button_3_state0 state = 1 //preset memorize
flash led fast
check (buttons_1_6) state //one could be on at a time
write to EEPROM address(1-6) the relay array mute audio with optocoupler //optional
turn on/off relay(1-6) based on relay value state (on/off)
Press button A - causes state to change A0 = Select/recall preset
or A0 could be the default state
Press button A again - change to state B0 = Build preset
Press button A again - change to state C0 = Store preset
Press button A again - back to state A0
when in state A0 - Select preset
press button B1 recall preset 1
....
press button B6 recall preset 2
when in state B0 - Build preset
press button B1 turn on ledPin1 and relePin1 and store [1,1] to relayArray
press button B1 again turn off ledPin1 and relePin1 and store [1,0] to relayArray
.....
press button B6 turn on ledPin1 and relePin1 and store [2,1] to relayArray
press button B6 again turn off ledPin1 and relePin1 and store [2,0] to relayArray
when in state C0 - Store preset
press button B1 causes relayArray to be stored
.....
press button B6 causes relayArray to be stored