Hello all.
I'm driving 16 LEDs with a Tlc5940 and I would like to have the LiquidCrystal_I2C library tell me what is going on via a 16x2 display. The LEDs work the way I want them to, so I'm fairly confident with the wiring. I've also copied my wiring and code for the LCD display from another successful project I've done.
I have commented out every line of code until I found the conflict... lcd.begin(). The moment I uncomment that line below (line 36), nothing works. Any ideas of how I would go about resolving this issue or perhaps I can can further debug this application? I've followed the wiring diagram here.
Many thanks.
#include <Tlc5940.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
/* BUTTON VARIABLES */
int ok_to_send=0;
const int btnOn=5;
const int btnOff=4;
/* I WANT TO SWITCH BETWEEN EVENS AND ODDS */
boolean lightUpOdds=false;
/* FOR DEBUGGING */
boolean maxSpeedAttained=false;
/* NEEDED FOR TIMING */
long previous_milliseconds=0;
/* THIS IS THE DURATION BETWEEN ODDS AND EVENS */
int wait_time=2500;
int wait_time_reset=wait_time;
/* THE FASTEST SPEED, IN MILLISECONDS. THE SMALLER THE NUMBER, THE FASTER. */
int max_speed=20;
int max_speed_reset=max_speed;
/* THE SPEED INCREASE... A PERCENTAGE. */
int speed_increase=10;
int speed_increase_reset=speed_increase;
/* FOR REPORTING */
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
void setup() {
/* CONFIGURE THE LCD DISPLAY */
//lcd.begin(16,2); // initialize the lcd for 16 chars 2 lines
/* SET UP THE PWM DRIVER */
Tlc.init();
/* USED FOR DEBUGGING */
Serial.begin(9600);
/* SET THE INPUT PINS */
pinMode(btnOn, INPUT_PULLUP);
pinMode(btnOff, INPUT_PULLUP);
/* INSTRUCTIONS */
display_start_instructions();
}
void loop() {
/*
GET THE CURRENT STATE OF THE BUTTONS.
WHEN PRESSED, SET VALUES TO VARIABLES READ ELSEWHERE.
*/
if (digitalRead(btnOn) == LOW) {
ok_to_send = 1;
}
if (digitalRead(btnOff) == LOW) {
ok_to_send = 0;
reset_everything();
}
/* CALL THE FUNCTION WHICH LIGHTS THE LEDS*/
sendSignals();
}
void sendSignals() {
if(ok_to_send==1) {
/* FOR COMPARING TIME */
unsigned long current_milliseconds=millis();
/* USE VARIABLES INSTEAD OF delay() */
if(current_milliseconds-previous_milliseconds >= wait_time) {
/* RESET */
previous_milliseconds=current_milliseconds;
/* CLEAR OUT EVERYTHING IN THE 16-CHANNEL PWM DRIVER */
Tlc.clear();
/* EVENS OR ODDS? */
if(lightUpOdds==true) {
for(int i=0; i<16; i++) {
if(i%2!=0) {
Tlc.set(i, 4095);
}
}
lightUpOdds=false;
} else {
for(int i=0; i<16; i++) {
if(i%2==0) {
Tlc.set(i, 4095);
}
}
lightUpOdds=true;
}
/* DECREASE THE INTERVAL BETWEEN ODDS/EVENS BY A PERCENTAGE (speed_increase). */
if(wait_time>=max_speed) {
/* SPEED UP THE INTERVAL */
wait_time-=(wait_time/speed_increase);
}
/* UPDATE THE PWM DRIVER */
Tlc.update();
/* FOR DEBUGGING */
if(wait_time>=max_speed) {
debug_wait_time();
} else {
debug_max_speed();
}
}
}
}
void debug_wait_time() {
if(maxSpeedAttained==false) {
/* LCD MONITORING */
//lcd.clear();
//lcd.setCursor(0,0);
//lcd.print("wait time: ");
//lcd.print(wait_time);
}
}
void debug_max_speed() {
if(maxSpeedAttained==false) {
/* NO NEED TO EXECUTE THIS CODE MORE THAN ONCE */
maxSpeedAttained=true;
/* LCD MONITORING */
//lcd.clear();
//lcd.setCursor(0,0);
//lcd.print("max speed: ");
//lcd.print(max_speed);
//lcd.print("ms");
//lcd.setCursor(0,1);
//lcd.print("2nd btn resets");
}
}
void display_start_instructions() {
/* INSTRUCTIONS */
//lcd.clear();
//lcd.setCursor(0,0);
//lcd.print("press the button");
}
void reset_everything() {
/* RESET THE PWM DRIVER */
Tlc.clear();
Tlc.update();
/* THESE VARIABLES AND FUNCTIONS BASICALLY PUT EVERYTHING BACK TO THEIR ORIGINAL STATES */
lightUpOdds=false;
maxSpeedAttained=false;
previous_milliseconds=0;
wait_time=wait_time_reset;
max_speed=max_speed_reset;
speed_increase=speed_increase_reset;
display_start_instructions();
}