I'm trying to program a little "game" (if you can call it that) to get warm with OLED displays and input triggers. I have a IR remote controller and a 1.3" OLED screen connected to the Arduino (Mega 2560). I need the serial monitor to print the button presses while the OLED is also running to be able to debug the stuff i code. This is the code i have so far:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH1106.h>
#include <IRremote.h>
const byte COLS = 4;
const byte ROWS = 4;
int IRpin = 2;
#define OLED_RESET 4
Adafruit_SH1106 display(OLED_RESET);
#if (SH1106_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SH1106.h!");
#endif
int trigstat = 0;
void setup() {
randomSeed(random(127));
Serial.begin(9600);
IrReceiver.begin(IRpin);
display.clearDisplay();
display.fillScreen(0);
display.display();
display.begin(SH1106_SWITCHCAPVCC, 0x3C);
}
void loop() {
if (IrReceiver.decode())
{
delay(20);
IrReceiver.resume();
if (IrReceiver.decodedIRData.command > 0 && IrReceiver.decodedIRData.command < 95)
{
Serial.print("Button value: ");
Serial.print(IrReceiver.decodedIRData.command);
Serial.print(" -> ");
if (IrReceiver.decodedIRData.command == 21) Serial.println("Arrow down");
}
}
display.clearDisplay();
//player();
display.display();
}
void player() {
int XPOS = 0;
int YPOS = 0;
while (1) {
display.writeFillRect(XPOS, YPOS,5,5,1);
display.display();
}
if (IrReceiver.decodedIRData.command == 21){
YPOS += 1;
display.clearDisplay();
display.writeFillRect(XPOS, YPOS,5,5,1);
display.display();
}
}
//random(display.width()) für Zufallsposition
The serial monitor works fine and shows which button i press on the remote.
But if i integrate player()
* to the loop the rectangle is positioned on the OLED as it should be, but there are no lines printed on the serial monitor anymore when i press a button, so i am stuck here. I can't figure out if the code is wrong or if for some reason using OLED and the serial monitor exclude each other.
The question is tough to google, because a lot of people want the Serial to be printed on OLED, which is not what i want obviously.
*i know its not working, but this isn't my question right now.
Thanks in advance