int columnPins[] = { 7, 6, 5, 4 };
int numbers[] = {1,2,3,55,4,5,6,66,7,8,9,77,88,0,99,100};
bool prevStates[16];
unsigned long pressTimes[16];
unsigned int delayTime = 20;
bool buttonsFiltered[16];
int redbright = 255;
int bluebright = 255;
int greenbright = 255;
int redPin = 3;
int bluePin = 11;
int greenPin = 10;
bool lightOn = false;
long time = 0;
bool isLight = false;
void setup() {
for (int i = 0; i < 4; i++) {
pinMode(rowPins[i], OUTPUT);
pinMode(columnPins[i], INPUT_PULLUP);
}
Serial.begin(9600);
}
void loop() {
for (int r = 0; r < 4; r++) {
digitalWrite(rowPins[r], LOW);
for (int c = 0; c < 4; c++) {
bool buttonReading = !digitalRead(columnPins[c]);
int buttonIndex = r * 4 + c;
if (buttonReading != prevStates[buttonIndex]) {
pressTimes[buttonIndex] = millis();
}
if (millis() - pressTimes[buttonIndex] >= delayTime) {
if (buttonsFiltered[buttonIndex] != buttonReading) {
buttonsFiltered[buttonIndex] = buttonReading;
if (buttonsFiltered[buttonIndex]) {
Serial.println(numbers[buttonIndex]);
if ((numbers[buttonIndex] = 100) || (numbers[buttonIndex] = 77) || (numbers[buttonIndex] = 66) || (numbers[buttonIndex] = 55)){
// lightOn = !lightOn;
if (numbers[buttonIndex] = 55){
analogWrite(redPin, redbright);
}
if (numbers[buttonIndex] = 66){
analogWrite(redPin, redbright);
}
if (numbers[buttonIndex] = 77){
analogWrite(bluePin, bluebright);
}
}
}
}
}
prevStates[buttonIndex] = buttonReading;
}
digitalWrite(rowPins[r], HIGH);
}
if (lightOn) {
if (millis()-time>1000) {
time=millis();
turn();
}
// analogWrite(redPin, redbright);
// analogWrite(bluePin, bluebright);
// analogWrite(greenPin, greenbright);
}
}
void turn() {
isLight=!isLight;
digitalWrite(13, isLight);
}