Skip to content

Commit

Permalink
Initial version of SilverCrest Fan example
Browse files Browse the repository at this point in the history
  • Loading branch information
karol-brejna-i committed Sep 19, 2021
1 parent 5cd13df commit 41ba835
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 0 deletions.
112 changes: 112 additions & 0 deletions examples/SilverCrestFanExample/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* IRremoteESP8266: SilverCrestFanExample
*
* Copyright 2021 Karol Brejna, IRremoteESP8266 developers
*
* Demonstrates the usage of IRremoteESP8266 to send commands to a SilverCrest SSVS 85 A1 Fan.
*
* This program will read serial input (expects number from 0 to 5), translate to a selected
* command code and send it to the fan.
*
* Example circuit diagram:
* https://github.com/crankyoldgit/IRremoteESP8266/wiki#ir-sending
*
* Changes:
* September, 2021
* - Initial version of the example
*/

#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>

// GPIO to use to control the IR LED circuit. Recommended: 4 (D2).
const uint16_t kIrLed = 32;
// The Serial connection baud rate.
const uint32_t kBaudRate = 115200;

// define command/code tables
const uint16_t CODE_COUNT = 5;
String button_names[CODE_COUNT] = {"ON/OFF", "Speed", "Mist", "Timer", "OSC"};
uint64_t button_codes[CODE_COUNT] = {0x581, 0x582, 0x584, 0x588, 0x590};

IRsend irsend(kIrLed);

void initSerial(unsigned long rate)
{
#if defined(ESP8266)
Serial.begin(115200, SERIAL_8N1, SERIAL_TX_ONLY);
#else // ESP8266
Serial.begin(115200, SERIAL_8N1);
#endif // ESP8266
Serial.setTimeout(500);
while (!Serial)
{
delay(50);
}
}

void printOptions()
{
Serial.println("Available options:");
Serial.println("0 - Show program info");
Serial.println("1 - ON/OFF");
Serial.println("2 - Speed");
Serial.println("3 - Mist");
Serial.println("4 - Timer");
Serial.println("5 - OSC");
Serial.println("\nType your choice and confirm with ENTER (or wait for a while)...\n");
}

void setup()
{
initSerial(kBaudRate);
Serial.println("Setup finished.");
printOptions();

irsend.begin();

// pinMode(kIrLed, OUTPUT);
// digitalWrite(kIrLed, HIGH); //LEDOFF
}

void publishSerialData(const int index)
{
// get selected command name and code
String command = button_names[index - 1];
uint64_t code = button_codes[index - 1];

// send the code
Serial.printf("Sending command %s (code: %llu)\n", command.c_str(), code);
irsend.sendSymphony(code);
}

void loop()
{
// wait for serial input
if (Serial.available() > 0)
{
// read the input
char buf[501];
memset(buf, 0, 501);
Serial.readBytesUntil('\n', buf, 500);
Serial.printf("Received '%s'...\n", buf);

// change it to integer value
int index = atoi(buf);
if (index == 0) // handle help/unknown option
{
printOptions();
}
else if (index > CODE_COUNT) // handle unknown options
{
Serial.println("Unknown option.");
}
else // handle IR sending
{
publishSerialData(index);
}
}

delay(10);
}
23 changes: 23 additions & 0 deletions examples/SilverCrestFanExample/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[platformio]
src_dir = .

[env]
lib_extra_dirs = ../../
lib_ldf_mode = deep+
lib_ignore = examples
framework = arduino
monitor_speed = 115200
build_flags = ; -D_IR_LOCALE_=en-AU

[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2

[env:esp32dev]
platform = espressif32
board = esp32dev

[env:m5stick-c]
platform = espressif32
board = m5stick-c
upload_speed = 1500000

0 comments on commit 41ba835

Please sign in to comment.