I am trying to merge two sketches together with no luck. I am using four buttons to present a code to the Arduino to release a door while a cycle of LEDs circles the display. I used the Keypad library for the buttons part and just moved the colums to 1 to provide for four buttons. This is for a trophy case for my daughter. The sketches work properly separately, but only the buttons work on compiling. Debugging I see that the LEDs are being processed, but I think something might be conflicting with my TLC5490. Any ideas? Maybe I should attack the buttons in a different manner.
#include "Tlc5940.h"
#include "tlc_fades.h"
#include <Keypad.h>
TLC_CHANNEL_TYPE channel;
const byte ROWS = 4; //four rows
const byte COLS = 1; //three columns
const int debounceTime = 20; //debounce time
char keys[ROWS][COLS] = {{'A'},{'B'},{'C'},{'D'}}; //reduced to four buttons
byte rowPins[ROWS] = {3, 4, 5, 6}; //connect to the row pinouts
byte colPins[COLS] = {2}; //connect to the column/common pinout
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
char inputArray[3]; //password length
char Main[3] = {'A','B','C'}; //main password
#define releasePin 8 //releases doors
int j = 0;
void setup() /* setup: Runs Once */
{/* Fades */
Tlc.init();
/* Buttons */
Serial.begin(9600); //open serial port
pinMode(releasePin, OUTPUT); //define led pin as output
}
void loop() /* loop: Runs Constantly */
{
Fades();
Buttons();
}
void Fades()
{int intensity = 4095;
int speed = 600; //speed at which it flows
Tlc.set(20-24, intensity);
if (tlc_fadeBufferSize < TLC_FADE_BUFFER_LENGTH - 2) {
if (!tlc_isFading(channel))
Serial.println(channel);
{uint16_t duration = speed;
int maxValue = 1023 ;
uint32_t startMillis = millis() + 50;
uint32_t endMillis = startMillis + duration;
tlc_addFade(channel, 0, maxValue, startMillis, endMillis);
tlc_addFade(channel, maxValue, 0, endMillis, endMillis + duration);}
if (channel++ == 35) //Number of channels to display
{channel = 0;}}
tlc_updateFades();
}
void Buttons()
{
{char key = kpd.getKey();
if(key) //if a key is pressed
{inputArray[j] = key; //store entry into array
j++; //increase array by one
Serial.println(key); //print keypad character entry to serial port
if (j == 3) //if 3 presses have been made
{if (inputArray[0] == Main[0] && //match input array to Main array
inputArray[1] == Main[1] &&
inputArray[2] == Main[2])
{Serial.println("Release"); // releases doors after correct code
digitalWrite(releasePin, HIGH);
delay(2000);
digitalWrite(releasePin, LOW);
delay(500);}
{j=0; //reset j
Serial.println("Reset");}}}};
}