CODE HELP: How to exit first loop > Digital Capacitive Sensor > LCD

Hi guys, I wonder if you can help. I am stuck with my code. I use LCD MAX7219 and two digital capacitive sensors. By touching one sensor (using if statement in void loop) I turn the LEDs on on the LCD. This step is succesful. Now I want to use a second digital touch sensor to clear the LCD. I used to if statements in void loop() - see in the code below. I tried to use Serial.println() and found out then the first if statement keeps looping my updateLEDs function and never actually moves on to the second but when the LCD is meant to clear.

I have been trying many solutions for last two days including using exit(), clear(), lc.clearDisplay(0) and different ways of if and else if statements. It’s probably a basic solution but if anyone can advice me I would appreciate it so much.

THANKS A MILION!

My full code:

#include “LedControl.h”

#define sensorPin1 8 // capactitive digital touch sensor to turn on LEDs
#define sensorPin2 7 // capactitive digital touch sensor to clear LCD

LedControl lc = LedControl(11, 13, 10, 256);

unsigned long delaytime = 10;
int rows[32] = {0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0};
int columns[8] = {0, 1, 1, 0, 0, 1, 1, 0};

void clearDisplay(int addr);

void setup() {
pinMode(sensorPin1, INPUT);
pinMode(sensorPin2, INPUT);
Serial.begin(9600);
//we have already set the number of devices when we created the LedControl
int devices = lc.getDeviceCount();
//we have to init all devices in a loop
for (int address = 0; address < devices; address++) {
lc.shutdown(address, false);
lc.setIntensity(address, 10);
lc.clearDisplay(address);
}
}

void loop() {

int senseValue1 = digitalRead(sensorPin1);
int senseValue2 = digitalRead(sensorPin2);

if (senseValue1 == HIGH) {
updateLEDs();
}

if (senseValue2 == HIGH) { // HOW DO IT CLEAR THE DISPLAY HERE?
lc.clearDisplay(0);

delay(1000);
}
}

void update() {

}

void updateLEDs() {
for (int i = 8; i < 32; i–) {
for (int j = 0; j < 8; j++) {
delay(20);
if (i < 8) {
Serial.println(“First panel”);
lc.setLed(0, j, i, true);
}

if (i < 8 && i < 16) {
Serial.println(“Second panel”);
lc.setLed(1, j, i, true);

}

if (i < 24 && i < 32) {
Serial.println(“Third panel”);
lc.setLed(2, j, i, true);

}
if (i < 32) {
Serial.println(“Forth panel”);
lc.setLed(3, j, i, true);
}

}
}
}

How are the inputs wired ?

Have you got pulldown resistors to keep that at a known LOW state when the buttons are not pressed or are they floating at an unknown voltage which could be HIGH even when the buttons are not pressed ?

What do you see if you print the value of senseValue1 and senseValue2 at the start of loop() ?

  for (int i = 8; i < 32; i--)

What will the values of i be in this for loop ?
Try printing it if you are not sure

Your if statements are dodgy too. If i < 8 or 16 or 24 then it’s also always going to be <16 or 24 or 32. Perhaps some of those < should be > or >= ?

Steve