Hi,
My IR sensors working well, I added a OLED work well.
as long as added: #include <RH_ASK.h> // Radiohead Library
the OLED start failed. why?
I set the reset pin of OLED as -1 still not work.
Thank for help.
Adam
#define DECODE_SONY
#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
////// Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
#include <RH_ASK.h> // Radiohead Library
#define IR_RECEIVE_PIN 2 // To be compatible with interrupt example, pin 2 is chosen here.
#define IR_SEND_PIN 3
#define TONE_PIN 4
#define APPLICATION_PIN 5
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
#define _IR_TIMING_TEST_PIN 7
#include <IRremote.hpp>
int LED1 = 8;
int LED2 = 9;
void setup() {
Serial.begin(115200);
// Just to know which program is running on my Arduino
Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));
/*
Start the receiver, enable feedback LED and take LED feedback pin from the internal boards definition
*/
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN);
Serial.print(F("Ready to receive IR signals of protocols: "));
printActiveIRProtocols(&Serial);
Serial.print(F("at pin "));
Serial.println(IR_RECEIVE_PIN);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
}
display.display();
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(4, 0);
display.println("ADAMDIY");
display.display();
display.setTextSize(1);
display.setCursor(4, 20);
display.println("Hello world!");
display.display();
}
void loop() {
/*
Check if received data is available and if yes, try to decode it.
Decoded result is in the IrReceiver.decodedIRData structure.
E.g. command is in IrReceiver.decodedIRData.command
address is in command is in IrReceiver.decodedIRData.address
and up to 32 bit raw data in IrReceiver.decodedIRData.decodedRawData
*/
if (IrReceiver.decode()) {
// Print a short summary of received data
IrReceiver.printIRResultShort(&Serial);
if (IrReceiver.decodedIRData.protocol == UNKNOWN) {
// We have an unknown protocol here, print more info
IrReceiver.printIRResultRawFormatted(&Serial, true);
}
Serial.println();
/*
!!!Important!!! Enable receiving of the next value,
since receiving has stopped after the end of the current received data packet.
*/
IrReceiver.resume(); // Enable receiving of the next value
/*
Finally, check the received data and perform actions according to the received command
*/
// if (IrReceiver.decodedIRData.command == 0x10) {
if (IrReceiver.decodedIRData.command == 0x34) {
// do something
digitalWrite(LED1, HIGH);
} else if (IrReceiver.decodedIRData.command == 0x80) {
// do something else
digitalWrite(LED2, HIGH);
}
/////////////////////////////////////////////////////////
display.display();
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(4, 0);
display.println("ADAMDIY");
display.display();
display.setTextSize(1);
display.setCursor(4, 20);
display.println("Hello world!");
display.display();
/////////////////////////////////////////////////////
}
}