Add button configuration logic

This commit is contained in:
Tyler Perkins 2022-03-29 20:15:28 -04:00
parent 58214be88a
commit 7cc436f6ba
2 changed files with 132 additions and 16 deletions

99
remote/config.h Normal file
View File

@ -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_

View File

@ -7,6 +7,8 @@
#include <IRremote.h>
#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);
}