I had a project that was working perfectly using a SevSeg display. Then I switched the display for one with an I2C backpack, so that I could consolidate the 14 wires into 4. The display works with the example code, but not with my project.
Below is the simple version of the project where I use a rotary switch to move through 3 modes. Each mode should print the mode number in the serial monitor and display the number on the display. Without any of the matrix.writeDisplay() lines, it works. As soon as I add any of these lines back, it stops working (the serial monitor stops).
Also, do you know how to make this display go blank? Without the backpack, I could use "sevseg.blank()". But I'm not finding anything such code for this version.
Thanks!!
#include <Wire.h> // Enable this line if using Arduino Uno, Mega, etc.
#include <Adafruit_GFX.h>
#include "Adafruit_LEDBackpack.h"
Adafruit_7segment matrix = Adafruit_7segment();
const int mode2 = A4; // switch set to mode 2 - counts
const int mode3 = A5; // switch set to mode 3 - timer
void setup() {
Serial.begin(115200);
pinMode(mode2, INPUT_PULLUP);
pinMode(mode3, INPUT_PULLUP);
matrix.begin(0x70);
}
void loop() {
if (digitalRead(mode2) == LOW){
Serial.println("mode 2");
matrix.print(0002);
matrix.writeDisplay();
}
else if (digitalRead(mode3) == LOW){
Serial.println("mode 3");
matrix.print(0003);
matrix.writeDisplay();
}
else {
Serial.println("mode 1");
matrix.print(0001);
matrix.writeDisplay();
}
}
Weird. I have the backpack plugged into SCL and SDA pins on the Arduino. And I don't see any markings on the board to indicate that A4 and A5 are special, but I just tried A2 and A3 and it works as expected. I also tried some digital pins and those worked too. So I guess I just happened to pick the only 2 pins that wouldn't work. Thanks!
It couldn't have been Nano because that doesn't have pins labelled SCL & SDA. @fishysam would have needed to connect the display to A4 & A5, so it would have (hopefully) been obvious that those same pins could not be used for button inputs.
(Although they could if an I2C I/O expander chip was used!)