Hi,
I’m a bit at an impasse. I’m trying to create a void function expshow() and no matter where the function call is, nothing happens. My other function blink() works like a charm anywhere in the code.
If I copy paste the content of expshow() where I want it, it works. The function just doesn’t want to work. Can you help me? There is no error message, the code compiles fine.
#define ENCODER_OPTIMIZE_INTERRUPTS
#include <Encoder.h>
#include <MIDI.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define SW1 4
#define SW2 5
#define SW3 6
#define SW4 7
#define Exp_SW 12
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Encoder myEnc(2, 3);
MIDI_CREATE_DEFAULT_INSTANCE();
int SW1Down = 0;
int SW2Down = 0;
int SW3Down = 0;
int SW4Down = 0;
int ExpDown = 0;
int counter = 0;
int encoderCounter = 0;
String MusicName = "BNA MIDIController";
int ExpPin = A7; // select the input pin for the potentiometer
int ExpValue = 0; // variable to store the value coming from the sensor
int midiCC = 0;
void setup() {
MIDI.begin();
Serial.begin(9600);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
//Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
delay(2000);
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0, 30);
{
pinMode(SW1, INPUT_PULLUP);
pinMode(SW2, INPUT_PULLUP);
pinMode(SW3, INPUT_PULLUP);
pinMode(SW4, INPUT_PULLUP);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(ExpPin, INPUT_PULLUP);
pinMode(Exp_SW, INPUT_PULLUP);
}
}
long oldPosition = -999;
unsigned long db = 150; //debounce de switch
unsigned long lastRead = millis();
byte chn = 2; // Midi channel
void loop()
{
int SW1Down = digitalRead(SW1);
int SW2Down = digitalRead(SW2);
int SW3Down = digitalRead(SW3);
int SW4Down = digitalRead(SW4);
int ExpDown = digitalRead(Exp_SW);
long newPosition = myEnc.read();
ExpValue = analogRead(ExpPin);
expshow();
if (newPosition != oldPosition)
{
if (encoderCounter >= 4)
{
encoderCounter = 0;
if (oldPosition > newPosition)
{
counter--;
}
else
{
counter++;
}
if (counter > 10)
{
counter = 0;
}
else if (counter < 0)
{
counter = 10;
}
//Serial.println(SW1);
//display.display();
switch (counter) {
case 0:
MusicName = "Mig1";
break;
case 1:
MusicName = "Mig2";
break;
case 2:
MusicName = "Mig3";
break;
case 3:
MusicName = "Mig4";
break;
case 4:
MusicName = "Mig5";
break;
case 5:
MusicName = "Mig6";
break;
case 6:
MusicName = "Mig7";
break;
case 7:
MusicName = "Mig8";
break;
case 8:
MusicName = "Mig9";
break;
case 9:
MusicName = "Mig10";
break;
case 10:
MusicName = "Mig11";
break;
}
}
}
else
{
encoderCounter++;
}
oldPosition = newPosition;
if (SW1Down == LOW || SW2Down == LOW || SW3Down == LOW || SW4Down == LOW) {
switch (counter) {
case 0:
if (SW1Down == LOW) {
}
else if (SW2Down == LOW) {
}
else if (SW3Down == LOW) {
}
else if (SW4Down == LOW) {
}
break;
case 1:
if (SW1Down == LOW) {
}
break;
case 2:
if (SW1Down == LOW) {
}
break;
case 3:
if (SW1Down == LOW) {
}
break;
case 4:
if (SW1Down == LOW) {
}
break;
case 5:
if (SW1Down == LOW) {
}
break;
case 6:
if (SW1Down == LOW) {
}
break;
case 7:
if (SW1Down == LOW) {
}
break;
case 8:
if (SW1Down == LOW) {
}
break;
case 9:
if (SW1Down == LOW) {
}
break;
case 10:
if (SW1Down == LOW) {
}
break;
}
blink();
}
else {
display.clearDisplay();
display.invertDisplay(false);
display.setTextSize(2);
display.setCursor(0, 32);
display.println(MusicName);
display.display();
}
}
void blink()
{
display.invertDisplay(true);
display.println(MusicName);
display.display();
display.setCursor(0, 20);
display.clearDisplay();
}
void expshow()
{
if (ExpDown == HIGH) {
digitalWrite(LED_BUILTIN, HIGH);
}
else {
digitalWrite(LED_BUILTIN, LOW);
}
}