I'm not getting very far with my code, I have tried to ask before, but I get the feeling people prefer to be little me rather than provide useful assistance. I am new to this so apologies.
These two codes work individually, the 1st puts on LEDS on by one per button push
#include <Bounce2.h>
#include <Button.h>
int trlpin_A = 13;
int trlpin_B = 12;
int trlpin_C = 11;
int push_button = 4;
int buttonstate = LOW;
int lastbuttonstate = HIGH;
int actual;
Bounce debouncer = Bounce();
void setup() {
pinMode(trlpin_A, OUTPUT);
pinMode(trlpin_B, OUTPUT);
pinMode(trlpin_C, OUTPUT);
pinMode(push_button, INPUT);
debouncer.attach(push_button);
debouncer.interval(50); // interval in ms
}
void loop() {
// Update the Bounce instance :
debouncer.update();
// Get the updated value :
int value = debouncer.read();
if ( value == HIGH ) {
buttonstate = digitalRead(push_button);
if (buttonstate == HIGH && buttonstate != lastbuttonstate)
{
if(actual == 3) actual = 0;
else actual++;
}
lastbuttonstate = buttonstate;
switch(actual)
{
case 0:
digitalWrite(trlpin_C, LOW);
digitalWrite(trlpin_A, HIGH);
break;
case 1:
digitalWrite(trlpin_A, LOW);
digitalWrite(trlpin_B, HIGH);
break;
case 2:
digitalWrite(trlpin_B, LOW);
digitalWrite(trlpin_C, HIGH);
break;
}
}
}
The next where I push the button it puts LEDs A and B on the off after 2 seconds OR i push and hold and it puts another 2 LEDs on then off.
#define debounce 20
#define holdTime 2000
#include <Button.h>
int trlpin_A = 13;
int trlpin_B = 12;
int trlpin_C = 11;
int trlpin_E = 10;
int push_button = 4;
int buttonVal = 0;
int buttonLast = 0;
long btnDnTime;
long btnUpTime;
boolean ignoreUp = false;
void setup()
{
pinMode(trlpin_A, OUTPUT);
pinMode(trlpin_B, OUTPUT);
pinMode(trlpin_C, OUTPUT);
pinMode(trlpin_E, OUTPUT);
pinMode(push_button, INPUT);
digitalWrite(push_button, LOW );
}
void loop()
{
// Read the state of the button
buttonVal = digitalRead(push_button);
// Test for button pressed and store the down time
if (buttonVal == HIGH && buttonLast == LOW && (millis() - btnUpTime) > long(debounce))
{
btnDnTime = millis();
}
// Test for button release and store the up time
if (buttonVal == LOW && buttonLast == HIGH && (millis() - btnDnTime) > long(debounce))
{
if (ignoreUp == false)
{
digitalWrite(trlpin_A, HIGH);
digitalWrite(trlpin_B, HIGH);
delay(2000);
digitalWrite(trlpin_A, LOW);
digitalWrite(trlpin_B, LOW);
}
else ignoreUp = false;
btnUpTime = millis();
}
// Test for button held down for longer than the hold time
if (buttonVal == HIGH && (millis() - btnDnTime) > long(holdTime))
{
digitalWrite(trlpin_C, HIGH);
digitalWrite(trlpin_E, HIGH);
delay(2000);
digitalWrite(trlpin_C, LOW);
digitalWrite(trlpin_E, LOW);
ignoreUp = true;
btnDnTime = millis();
}
buttonLast = buttonVal;
}
I am not able to join the two together so button1 can be either push..(run a function) push and hold (run another function)
Button 2 each press of the button turns on 1 LED
I have tried as per my next post: