Hi. I could use a little assistance please. My diagram attached is for testing to get it right and then I will implement it into the car I am building it for. the pushbuttons are actually toggle switches for testing. It is just used to display the gear (R,N,1,2,3) the transmission is in. "R" displays fine, "N" displays fine, "1" will display fine when first triggered, but when I go to display "2" or then "3" or go back down to the prior "1", or "2" as it will function in the car, the led display more times than not it will still have a previous digit displayed and it will be displaying both over top of each other. The car transmission has a lever to select between neutral, forward/first gear and reverse. When in forward/first gear the following gears,2 and 3 are then activated in order so when in 3rd gear all 3 inputs on my uno will be triggered. The LED Driver is connected via I2C. here is my code.
#include <Wire.h>
#include <Arduino.h>
#include <Adafruit_GFX.h>
#include <Adafruit_IS31FL3731.h>
Adafruit_IS31FL3731 ledmatrix = Adafruit_IS31FL3731();
const int neutralinput = 2; // assigning pin 2 to the neutral switch
const int reversegearinput = 3; // assigning pin 3 to the reverse switch
const int firstgearinput = 4; // assigning pin 4 to the foward/first gear switch
const int secondgearinput = 5; // assigning pin 5 to the second gear switch
const int thirdgearinput = 6; // assigning pin 6 to the third gear switch
int gear(); //variable to compare to in my switch case
void setup() {
Serial.begin(9600);
if (! ledmatrix.begin()) {
Serial.println("IS31 not found");
while (1);
}
Serial.println("IS31 found!");
pinMode(neutralinput, INPUT_PULLUP); // designating the neutral safety switch input pin 2 as an input on the arduino and utilizing the internal resistors to bring high
pinMode(reversegearinput, INPUT_PULLUP); // designating the reverse switch input pin 3 as an input on the arduino and utilizing the internal resistors to bring high
pinMode(firstgearinput, INPUT_PULLUP); // designating the foward/first gear switch input pin 4 as an input on the arduino and utilizing the internal resistors to bring high
pinMode(secondgearinput, INPUT_PULLUP); // designating the 2nd gear switch input pin 5 as an input on the arduino and utilizing the internal resistors to bring high
pinMode(thirdgearinput, INPUT_PULLUP); // designating the 3rd gear switch input pin 6 as an input on the arduino and utilizing the internal resistors to bring high
ledmatrix.setTextColor(50); //setting the led display paramters so the characters display properly
ledmatrix.setCursor(-1, 1);
ledmatrix.setTextSize(2);
ledmatrix.setRotation(1);
// put your setup code here, to run once:
}
void loop() {
int gear =(0);
// the digitalReads are to set my variable for the actions happening
if (digitalRead(neutralinput) ==LOW)
gear =(1);
if (digitalRead(reversegearinput) ==LOW)
gear =(2);
if (digitalRead(firstgearinput) == LOW && digitalRead(secondgearinput) == HIGH && digitalRead(thirdgearinput) == HIGH)
gear =(3);
if (digitalRead(firstgearinput) == LOW && digitalRead(secondgearinput) == LOW && digitalRead(thirdgearinput) == HIGH)
gear =(4);
if (digitalRead(firstgearinput) == LOW && digitalRead(secondgearinput) == LOW && digitalRead(thirdgearinput) == LOW)
gear =(5);
switch(gear) {
case 1:
ledmatrix.print("N") ;
break;
case 2:
ledmatrix.print("R") ;
break;
case 3:
ledmatrix.print("1");
break;
case 4:
ledmatrix.print("2");
break;
case 5:
ledmatrix.print("3");
break;
default:
ledmatrix.clear();
break;
}
}
I have changed my ledmatrix.print("1,2,or 3") to Serial.print("1,2, or 3") instead and watch the serial monitor as I was switching the different toggles for 1st, 2nd and 3rd gear on and off and it was printing properly as the switching happened. I've tried adding ledmatrix.clear(), or a delay in between each case before or after the break and at the top of the switch and still will have the overlapping numbers displayed most of the time. ive spent days reading different forums, instructional posts and watched a ton of videos to try and learn this, I'm sure basic program to most, as it is my first time doing any type of programming at all. I am amazed at what can be done and plan to keep learning by trying but I am at a roadblock with this. Any suggestions are greatly appreciated.
Thank you,
Mike.
