I've building a sort of signalling system for a bicycle - using an Arduino Uno to prototype, and a Pro Mini for the final installations. I'm having trouble getting the Arduino to register the button presses. There are two separate libraries being used for two separate applications.
Im using the FastLED library to drive Adafruit Dotstars.
leds[0].setRGB( 255, 68, 221);
FastLED.show();
delay(500);
This works great. I'm able to display patterns fairly well. But Im having trouble with a system so that combinations of button presses call different functions.
For example.
I have 6 buttons - five with 2 states, one with 3states.
lets say when they are all unpressed, after first turning the arduino on, they display a default function. 000000
I have the function set up so that different button presses affect different sections of the image. So I dont have to program complete patterns separately for each combination of buttons (2x2x2x2x2x3)
I started by following a tutorial for button states, but I am unalbe to find a if-else or switch-case that gets the states read.
I will provide some snippets to show you the approach I used so far
CheckButtonState (BTN_BLINK, BLINKbuttonPushCounter, BLINKbuttonState, BLINKlastButtonState, twostate);
CheckButtonState (BTN_SIGNAL_LEFT, LSbuttonPushCounter, LSbuttonState, LSlastButtonState, twostate);
CheckButtonState (BTN_SIGNAL_RIGHT, RSbuttonPushCounter, RSbuttonState, RSlastButtonState, twostate);
char set_light_mode(int buttonPushCounter)
{
if ((HLbuttonState == 0) &&
(BLINKbuttonState == 0))
{
headlightOFF();
}
else if ((HLbuttonState == 1) &&
(BLINKbuttonState == 0))
{
headlightLOW();
}
else if ((HLbuttonState == 2) &&
(BLINKbuttonState == 0)) {
headlightHIGH();
}
void CheckButtonState (int buttonPin, int &buttonPushCounter, int &buttonState, int &lastButtonState, int statenum)
{
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);
// compare the buttonState to its previous state
if (buttonState != lastButtonState)
{
// if the state has changed, increment the counter
if (buttonState == HIGH)
{
// if the current state is HIGH then the button
// wend from off to on:
buttonPushCounter++;
if (buttonPin == BTN_SIGNAL_LEFT)
{
CheckSignal(RSbuttonPushCounter);
}
if (buttonPin == BTN_SIGNAL_RIGHT)
{
CheckSignal(LSbuttonPushCounter);
}
//this resets the counter to 0 after the count reaches the number of different modes
if (buttonPushCounter == statenum)
{
buttonPushCounter = 0;
}
}
}
}
Any help would be really really appreciated. Thanks very much!