Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ConnorWGarvey/6c7c8e96b6c3c7bbff372096a8f089c8 to your computer and use it in GitHub Desktop.
Save ConnorWGarvey/6c7c8e96b6c3c7bbff372096a8f089c8 to your computer and use it in GitHub Desktop.
Convert Crunch Labs Laser Tag Hack Pack to a one-button IR remote
/*
************************************************************************************
* MIT License
*
* Copyright (c) 2025 Crunchlabs LLC (Laser Tag Code)
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
************************************************************************************
*/
// >>>>>>>>>>>>>>>>>>>>>>>>>>>> PIN DEFINITIONS <<<<<<<<<<<<<<<<<<<<<<<<<<<<
#define IR_SEND_PIN 3
#define _IR_TIMING_TEST_PIN 7
#define BUTTON_PIN 12
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> LIBRARIES <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#define DECODE_NEC // defines RIR Protocol (Apple and Onkyo)
#include <IRremote.hpp>
#include <Arduino.h>
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SETUP <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
void setup() {
pinMode(BUTTON_PIN, INPUT_PULLUP);
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(115200);
IrSender.begin();
}
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> LOOP <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
void loop() {
unsigned long currentMillis = millis();
handleButton(currentMillis);
}
// >>>>>>>>>>>>>>>>>>>>>>>>>>>> Remote functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
void handleButton(unsigned long currentMillis) {
if (ReadButton()) { // button is pressed
sendIr();
}
}
// Send signal
void sendIr() {
Serial.flush();
// LG TV power off command and use the standard 32 bit command length
IrSender.sendNEC(0x20DFA35C, 32);
// Haven't figured out Sony stuff
//delay(100); // wait so signals don't get confused
// Sony protocol uses a 12-bit code
//unsigned long powerOffCode = 0x2F;
//int numberOfBits = 12;
//int sonyAddress = 0x1; // Common address for Sony receivers
//IrSender.sendSony((sonyAddress << 7) | powerOffCode, numberOfBits);
delay(400); // wait before trying to send again
}
bool ReadButton() {
int buttonValue = digitalRead(BUTTON_PIN);
return buttonValue == LOW;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment