Skip to content

Commit 50d5fe5

Browse files
authored
Merge pull request #3040 from adafruit/ir_stick
adding ir remote example
2 parents e503ce1 + 114ab9a commit 50d5fe5

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

Sparkle_Motion_Stick_Examples/Arduino_Sparkle_Motion_Stick_IR_Remote/.feather_esp32_v2.test.only

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries
2+
// SPDX-FileCopyrightText: 2025 Tim Cocks for Adafruit Industries
3+
//
4+
// SPDX-License-Identifier: MIT
5+
6+
/*
7+
* Based on the SimpleReceiver.cpp and SimpleSender.cpp from the
8+
* Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
9+
* by Armin Joachimsmeyer
10+
************************************************************************************
11+
* MIT License
12+
*
13+
* Copyright (c) 2020-2023 Armin Joachimsmeyer
14+
*
15+
*/
16+
17+
#include <Arduino.h>
18+
19+
#include <IRremote.hpp> // include the library
20+
#include <Adafruit_NeoPixel.h>
21+
22+
#define NEOPIXEL_STRIP_PIN 21
23+
#define NUM_PIXELS 8
24+
25+
#define IR_RECEIVE_PIN 10
26+
27+
Adafruit_NeoPixel NEOPIXEL_STRIP(NUM_PIXELS, NEOPIXEL_STRIP_PIN, NEO_GRB + NEO_KHZ800);
28+
29+
uint8_t upCmd = 0x5;
30+
uint8_t downCmd = 0xD;
31+
uint8_t rightCmd = 0xA;
32+
uint8_t leftCmd = 0x8;
33+
34+
uint16_t pixelHue = 0;
35+
uint8_t brightness = 25;
36+
37+
void setup() {
38+
Serial.begin(115200);
39+
//while (!Serial);
40+
Serial.println("Adafruit Sparkle Motion IR Remote Control NeoPixels Demo");
41+
IrReceiver.begin(IR_RECEIVE_PIN);
42+
Serial.print("IRin on pin ");
43+
Serial.print(IR_RECEIVE_PIN);
44+
NEOPIXEL_STRIP.begin();
45+
NEOPIXEL_STRIP.setBrightness(25);
46+
}
47+
48+
void loop() {
49+
/*
50+
* Check if received data is available and if yes, try to decode it.
51+
* When left or right buttons are pressed, change the pixelHue.
52+
* When up or down buttons are pressed, change the brightness.
53+
*/
54+
if (IrReceiver.decode()) {
55+
if (IrReceiver.decodedIRData.protocol == UNKNOWN) {
56+
Serial.println("unknown");
57+
IrReceiver.printIRResultRawFormatted(&Serial, true);
58+
IrReceiver.resume();
59+
} else {
60+
IrReceiver.resume();
61+
//IrReceiver.printIRResultShort(&Serial);
62+
63+
// Ignore repeat codes from holding down the button
64+
if (IrReceiver.decodedIRData.flags == 0){
65+
//Serial.printf("Command: %d\n",IrReceiver.decodedIRData.command);
66+
if (IrReceiver.decodedIRData.command == upCmd){
67+
Serial.println("UP btn");
68+
brightness = min(brightness + 25, 255);
69+
}else if (IrReceiver.decodedIRData.command == downCmd){
70+
Serial.println("DOWN btn");
71+
brightness = max(brightness - 25, 0);
72+
}else if (IrReceiver.decodedIRData.command == leftCmd){
73+
Serial.println("LEFT btn");
74+
pixelHue = (pixelHue - 8192) % 65536;
75+
}else if (IrReceiver.decodedIRData.command == rightCmd){
76+
Serial.println("RIGHT btn");
77+
pixelHue = (pixelHue + 8192) % 65536;
78+
}
79+
80+
NEOPIXEL_STRIP.setBrightness(brightness);
81+
NEOPIXEL_STRIP.fill(NEOPIXEL_STRIP.gamma32(NEOPIXEL_STRIP.ColorHSV(pixelHue)));
82+
NEOPIXEL_STRIP.show();
83+
delay(100);
84+
}
85+
}
86+
Serial.println();
87+
}
88+
}

0 commit comments

Comments
 (0)