The code I used is as follows.
The module used is an 8x32 dot matrix, PCA9685 servomotor driver.
When a current flows through pins 2 to 9, the number of the pin through which the current flows appears on the serial monitor and the score in the 8x32 dot matrix increases by 10.
In the circuit, VCC was connected to 5V, 8x32 dot matrix was connected to 10, 11, and 12 pins in the order of CS, CLK, and DIN, and PCA9685 was connected to A4 and A5.
But the problem arises here.
As a result of the execution, the serial monitor showed a pin number and continued to increase the score without electric current flowing through the lines plugged into pins 2 to 9 or even without plugging in the lines themselves.
I changed the board itself for fear of poor contact, but the results were the same.
It was confirmed through the serial monitor that electric current flowed through 8 to 12 pins every few seconds.
No matter how hard I look, I don't know the cause of the problem.
If you know the cause, please help.
#include "LedControl.h"
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
LedControl lc=LedControl(12,11,10,4);
Adafruit_PWMServoDriver pwm=Adafruit_PWMServoDriver();
int point = 0;
int t2,t3,t4,t5,t6,t7,t8,t9;
byte num[11][8] = {
{
B00111000,
B01000100,
B01000100,
B01000100,
B01000100,
B01000100,
B01000100,
B00111000
},
{
B00010000,
B00110000,
B00010000,
B00010000,
B00010000,
B00010000,
B00010000,
B00111000
},
{
B00111000,
B01000100,
B00000100,
B00000100,
B00001000,
B00010000,
B00100000,
B01111100
},
{
B00111000,
B01000100,
B00000100,
B00011000,
B00000100,
B00000100,
B01000100,
B00111000
},
{
B00000100,
B00001100,
B00010100,
B00100100,
B01000100,
B01111110,
B00000100,
B00000100
},
{
B01111100,
B01000000,
B01000000,
B01111000,
B00000100,
B00000100,
B01000100,
B00111000
},
{
B00111000,
B01000100,
B01000000,
B01111000,
B01000100,
B01000100,
B01000100,
B00111000
},
{
B01111100,
B00000100,
B00000100,
B00001000,
B00010000,
B00100000,
B00100000,
B00100000
},
{
B00111000,
B01000100,
B01000100,
B00111000,
B01000100,
B01000100,
B01000100,
B00111000
},
{
B00111000,
B01000100,
B01000100,
B01000100,
B00111100,
B00000100,
B01000100,
B00111000
},
{
B00000000,
B01111100,
B01100110,
B01100110,
B01100110,
B01111100,
B01100000,
B01100000
}
};
void sb() {
int s1 = point/100;
int s2 = point%100/10;
int s3 = point%100%10/1;
for (int i=0; i<10; i++) {
for (int j=0; j<8; j++) {
lc.setRow(0, j, num[s3][j]);
}
}
for (int i=0; i<10; i++) {
for (int j=0; j<8; j++) {
lc.setRow(1, j, num[s2][j]);
}
}
for (int i=0; i<10; i++) {
for (int j=0; j<8; j++) {
lc.setRow(2, j, num[s1][j]);
}
}
for (int i=0; i<10; i++) {
for (int j=0; j<8; j++) {
lc.setRow(3, j, num[10][j]);
}
}
}
void setup() {
Serial.begin(9600);
for(int i=0; i<4; i++) {
lc.shutdown(i,false);
lc.setIntensity(i,2);
lc.clearDisplay(i);
}
pwm.begin();
pwm.setPWMFreq(51);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
for (int fs=0; fs<10; fs++) {
pwm.setPWM(fs,0,0);
}
}
void loop() {
sb();
int pin2 = digitalRead(2);
int pin3 = digitalRead(3);
int pin4 = digitalRead(4);
int pin5 = digitalRead(5);
int pin6 = digitalRead(6);
int pin7 = digitalRead(7);
int pin8 = digitalRead(8);
int pin9 = digitalRead(9);
if (pin2 == 1) {
point = point+10;
pwm.setPWM(2,0,175);
Serial.println("2");
}
if (pin3 == 1) {
point = point+10;
int r3 = constrain(map(10, 0, 180, 150, 600), 150, 600);
pwm.setPWM(3,0,r3);
Serial.println("3");
}
if (pin4 == 1) {
point = point+10;
int r4 = constrain(map(10, 0, 180, 150, 600), 150, 600);
pwm.setPWM(4,0,r4);
Serial.println("4");
}
if (pin5 == 1) {
point = point+10;
int r5 = constrain(map(10, 0, 180, 150, 600), 150, 600);
pwm.setPWM(5,0,r5);
Serial.println("5");
}
if (pin6 == 1) {
point = point+10;
int r6 = constrain(map(10, 0, 180, 150, 600), 150, 600);
pwm.setPWM(6,0,r6);
Serial.println("6");
}
if (pin7 == 1) {
point = point+10;
int r7 = constrain(map(10, 0, 180, 150, 600), 150, 600);
pwm.setPWM(7,0,r7);
Serial.println("7");
}
if (pin8 == 1) {
point = point+10;
int r8 = constrain(map(10, 0, 180, 150, 600), 150, 600);
pwm.setPWM(8,0,r8);
Serial.println("8");
}
if (pin9 == 1) {
point = point+10;
int r9 = constrain(map(10, 0, 180, 150, 600), 150, 600);
pwm.setPWM(9,0,r9);
Serial.println("9");
}
}