From 7cc436f6bae456f797004b61bb9a539550cfe2f2 Mon Sep 17 00:00:00 2001 From: Tyler Perkins Date: Tue, 29 Mar 2022 20:15:28 -0400 Subject: [PATCH] Add button configuration logic --- remote/config.h | 99 +++++++++++++++++++++++++++++++++++++++++++++++ remote/remote.ino | 49 +++++++++++++++-------- 2 files changed, 132 insertions(+), 16 deletions(-) create mode 100644 remote/config.h diff --git a/remote/config.h b/remote/config.h new file mode 100644 index 0000000..3194f39 --- /dev/null +++ b/remote/config.h @@ -0,0 +1,99 @@ +/////////////////////////////////////////////////////////////////////////////// +// Tyler Perkins +// 29-03-22 +// Button configuration +// + +#ifndef _CONFIG_H_ +#define _CONFIG_H_ + +// Button configuration +// Fill in with appropriate address and command +/////////////////////////////////////// +// Per Rev 1.0, the button layout is as follows on the provided PCB +// [10][ ][ ] +// [07][08][09] +// [04][05][06] +// [01][02][03] +// +// BUTTON**_PIN is based on the hardware configutation, and is currently set to +// the latest hardware iteration, rev 1.1 +// +// BUTTON**_ADDR and BUTTON**_CMD are the NEC address and command respctivly. +// They are used by the IRsend library. You will need to edit remote.ino if +// your remote is not using NEC, however NEC is the very common +// +// NOTE: It is planned to make button 10 switch through several "virtual" +// buttons, however this is a planned feature and not implemented + +/////////////////////////////////////// +// BUTTON 01 +// Prev song +#define BUTTON01_PIN 10 +#define BUTTON01_ADDR 0x7080 +#define BUTTON01_CMD 0xAE + +/////////////////////////////////////// +// BUTTON 02 +// Next song +#define BUTTON02_PIN 11 +#define BUTTON02_ADDR 0x7080 +#define BUTTON02_CMD 0xAF + +/////////////////////////////////////// +// BUTTON 03 +// Mute +#define BUTTON03_PIN 12 +#define BUTTON03_ADDR 0x7080 +#define BUTTON03_CMD 0xB9 + +/////////////////////////////////////// +// BUTTON 04 +// AUX input +#define BUTTON04_PIN 13 +#define BUTTON04_ADDR 0x7080 +#define BUTTON04_CMD 0xB4 + +/////////////////////////////////////// +// BUTTON 05 +// Bluetooth input +#define BUTTON05_PIN 7 +#define BUTTON05_ADDR 0x7080 +#define BUTTON05_CMD 0xBA + +/////////////////////////////////////// +// BUTTON 06 +// RCA input +#define BUTTON06_PIN 6 +#define BUTTON06_ADDR 0x7080 +#define BUTTON06_CMD 0xF9 + +/////////////////////////////////////// +// BUTTON 07 +// VOL- +#define BUTTON07_PIN 5 +#define BUTTON07_ADDR 0x7080 +#define BUTTON07_CMD 0xC8 + +/////////////////////////////////////// +// BUTTON 08 +// 2.1/5.1 Toggle +#define BUTTON08_PIN 4 +#define BUTTON08_ADDR 0x7080 +#define BUTTON08_CMD 0xEC + +/////////////////////////////////////// +// BUTTON 09 +// VOL+ +#define BUTTON09_PIN 8 +#define BUTTON09_ADDR 0x7080 +#define BUTTON09_CMD 0xC7 + +/////////////////////////////////////// +// BUTTON 10 +// Power button +#define BUTTON10_PIN 9 +#define BUTTON10_ADDR 0x7484 +#define BUTTON10_CMD 0xFF + +#endif //!_CONFIG_H_ diff --git a/remote/remote.ino b/remote/remote.ino index 6527b48..92b9a28 100644 --- a/remote/remote.ino +++ b/remote/remote.ino @@ -7,6 +7,8 @@ #include #include "LowPower.h" +#include "config.h" + // IR library IRsend irsend; @@ -16,13 +18,16 @@ void setup() { pinMode(2, INPUT); //buttons - pinMode(9, INPUT); - pinMode(10, INPUT); - pinMode(11, INPUT); - - //pinMode(13, OUTPUT); - - //attachInterrupt(digitalPinToInterrupt(2),readInput, RISING); + pinMode(BUTTON01_PIN, INPUT); + pinMode(BUTTON02_PIN, INPUT); + pinMode(BUTTON03_PIN, INPUT); + pinMode(BUTTON04_PIN, INPUT); + pinMode(BUTTON05_PIN, INPUT); + pinMode(BUTTON06_PIN, INPUT); + pinMode(BUTTON07_PIN, INPUT); + pinMode(BUTTON08_PIN, INPUT); + pinMode(BUTTON09_PIN, INPUT); + pinMode(BUTTON10_PIN, INPUT); irsend.begin(3, ENABLE_LED_FEEDBACK); } @@ -36,15 +41,27 @@ void loop() { } void readInput(){ - if(digitalRead(10) == HIGH){ - //vol + - irsend.sendNEC(0x7080, 0xC7, 1); - } else if(digitalRead(11) == HIGH){ - //vol - - irsend.sendNEC(0x7080, 0xC8, 1); - } else if(digitalRead(9) == HIGH){ - // 2.1/5.1 - irsend.sendNEC(0x7080, 0xEC, 1); + if(digitalRead(BUTTON01_PIN) == HIGH){ + irsend.sendNEC(BUTTON01_ADDR, BUTTON01_CMD, 1); + } else if(digitalRead(BUTTON02_PIN) == HIGH){ + irsend.sendNEC(BUTTON02_ADDR, BUTTON02_CMD, 1); + } else if(digitalRead(BUTTON03_PIN) == HIGH){ + irsend.sendNEC(BUTTON03_ADDR, BUTTON03_CMD, 1); + } else if(digitalRead(BUTTON04_PIN) == HIGH){ + irsend.sendNEC(BUTTON04_ADDR, BUTTON04_CMD, 1); + } else if(digitalRead(BUTTON05_PIN) == HIGH){ + irsend.sendNEC(BUTTON05_ADDR, BUTTON05_CMD, 1); + } else if(digitalRead(BUTTON06_PIN) == HIGH){ + irsend.sendNEC(BUTTON06_ADDR, BUTTON06_CMD, 1); + } else if(digitalRead(BUTTON07_PIN) == HIGH){ + irsend.sendNEC(BUTTON07_ADDR, BUTTON07_CMD, 1); + } else if(digitalRead(BUTTON08_PIN) == HIGH){ + irsend.sendNEC(BUTTON08_ADDR, BUTTON08_CMD, 1); + } else if(digitalRead(BUTTON09_PIN) == HIGH){ + irsend.sendNEC(BUTTON09_ADDR, BUTTON09_CMD, 1); + } else if(digitalRead(BUTTON10_PIN) == HIGH){ + irsend.sendNEC(BUTTON10_ADDR, BUTTON10_CMD, 1); } + delay(25); }