Hello all. I have a LED panel, nano, ultrasonic sensor. parking system. The problem is when I get to the STOP distance after 30 sec I have the program clear screen. I does that but when the screen is off I have random pixels lighting up every couple seconds. I think it may have to do with the loop still measuring distance, in the serial monitor I can see it is still measuring distance. The question is, is it a code problem with the loop, or maybe need a resistor in line somewhere?
Here is a copy of the code.
/* Author Erik
* parking sensor with seediuno nano
* Sept. 2022 V1
*/
#include <DMD2.h>
#include <fonts/SystemFont5x7.h>
SoftDMD dmd(1,1); // DMD controls the entire display
#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include <Ultrasonic.h>
#define RANGERPIN A5
Ultrasonic ultrasonic(RANGERPIN);
int counter = 0; // Counter value to check if the object has stopped moving
void setup()
{
Serial.begin(9600);
dmd.setBrightness(255);
dmd.selectFont(SystemFont5x7);
dmd.begin();
dmd.clearScreen();
}
void loop()
{
int inches {0};
int new_stop_distance {18}; //enter new stop distance here
inches = ultrasonic.MeasureInInches( );
inches = inches - new_stop_distance;
Serial.print(inches);//0~157 in
Serial.println(" inch");
delay(250);
dmd.clearScreen();
if (inches > 110){
dmd.drawString(10,4,"OK",7,SystemFont5x7);
}
else if ((inches < 110)&&(inches >1)){
dmd.drawString(10,4,String(inches),7, SystemFont5x7);
}
else if (inches <= 0){
dmd.drawString (5,4,"STOP",7,SystemFont5x7);
dmd.drawFilledBox (0,0,3,3);
dmd.drawFilledBox (0,15,3,12);
dmd.drawFilledBox (28,3,31,0);
dmd.drawFilledBox (28,12,31,15);
if (counter >= 30){
Serial.println("No movement detected, turning off the lights");
dmd.clearScreen();
} else {
counter++;
}
} else {
counter = 0; // Reset counter if there is a movement
}
}