Basically the code kinda works. It's random like sometimes I'll press the buttons and the light wont turn on.
Also I kinda wanted to implement a send button which I have no idea how to do. So if I hit the button B and then the button 1 the led for B1 would only light up if I hit the send button. That way it can keep the led b1 on and reset the button states for button b and 1. Anybody catch me on that idea?
Diagram - Dropbox - Error - Simplify your life
Btw I am using 3 buttons, The B column button and the Row 1 and Row 2 button so I'm trying to turn on the B1 or B2 Led at my command of hitting the right combination of buttons.
const int ledPinB1 = 13;
const int ledPinB2 = 12;
const int ledPinI1 = 11;
const int ledPinI2 = 10;
const int buttonPin1 = A0;
const int buttonPin2 = A1;
const int buttonPinB = A2;
const int buttonPinI = A3;
// Variables will change:
int buttonPushCounter1 = 0;
int buttonState1 = 0;
int lastButtonState1 = 0;
int buttonPushCounter2 = 0;
int buttonState2 = 0;
int lastButtonState2 = 0;
int buttonPushCounterB = 0;
int buttonStateB = 0;
int lastButtonStateB = 0;
int buttonPushCounterI = 0;
int buttonStateI = 0;
int lastButtoneStateI = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
buttonPush1();
buttonPush2();
buttonPushB();
if (buttonPushCounter1 % 2 == 1 && buttonPushCounterB % 2 == 1) {
digitalWrite(ledPinB1, HIGH);
} else {
digitalWrite(ledPinB1, LOW);
}
if (buttonPushCounter2 % 2 == 1 && buttonPushCounterB % 2 == 1) {
digitalWrite(ledPinB2, HIGH);
} else {
digitalWrite(ledPinB2, LOW);
}
}
void buttonPush1() {
buttonState1 = digitalRead(buttonPin1);
if (buttonState1 != lastButtonState1) {
if (buttonState1 == HIGH) {
buttonPushCounter1 ++;
}
else {
Serial.println("off");
}
}
lastButtonState1 = buttonState1;
}
void buttonPushB() {
buttonStateB = digitalRead(buttonPinB);
if (buttonStateB != lastButtonStateB) {
if (buttonStateB == HIGH) {
buttonPushCounterB ++;
}
else {
Serial.println("off");
}
}
}
void buttonPush2() {
buttonState2 = digitalRead(buttonPin2);
if (buttonState2 != lastButtonState2) {
if (buttonState2 == HIGH) {
buttonPushCounter2 ++;
}
else {
Serial.println("off");
}
}
}