-
Notifications
You must be signed in to change notification settings - Fork 778
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2958 from FoamyGuy/sparkle_motion_examples
sparkle motion IR control neopixels examples
- Loading branch information
Showing
3 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
89 changes: 89 additions & 0 deletions
89
...kle_Motion_Examples/Arduino_Sparkle_Motion_IR_Remote/Arduino_Sparkle_Motion_IR_Remote.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries | ||
// SPDX-FileCopyrightText: 2025 Tim Cocks for Adafruit Industries | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
/* | ||
* Based on the SimpleReceiver.cpp and SimpleSender.cpp from the | ||
* Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. | ||
* by Armin Joachimsmeyer | ||
************************************************************************************ | ||
* MIT License | ||
* | ||
* Copyright (c) 2020-2023 Armin Joachimsmeyer | ||
* | ||
*/ | ||
|
||
#include <Arduino.h> | ||
|
||
#include <IRremote.hpp> // include the library | ||
#include <Adafruit_NeoPixel.h> | ||
|
||
#define NEOPIXEL_STRIP_PIN 21 | ||
#define NUM_PIXELS 8 | ||
|
||
#define IR_RECEIVE_PIN 32 | ||
|
||
Adafruit_NeoPixel NEOPIXEL_STRIP(NUM_PIXELS, NEOPIXEL_STRIP_PIN, NEO_GRB + NEO_KHZ800); | ||
|
||
uint8_t upCmd = 0x5; | ||
uint8_t downCmd = 0xD; | ||
uint8_t rightCmd = 0xA; | ||
uint8_t leftCmd = 0x8; | ||
|
||
uint16_t pixelHue = 0; | ||
uint8_t brightness = 25; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
while (!Serial) | ||
; | ||
Serial.println("Adafruit Sparkle Motion IR Remote Control NeoPixels Demo"); | ||
IrReceiver.begin(IR_RECEIVE_PIN); | ||
Serial.print("IRin on pin "); | ||
Serial.print(IR_RECEIVE_PIN); | ||
NEOPIXEL_STRIP.begin(); | ||
NEOPIXEL_STRIP.setBrightness(25); | ||
} | ||
|
||
void loop() { | ||
/* | ||
* Check if received data is available and if yes, try to decode it. | ||
* When left or right buttons are pressed, change the pixelHue. | ||
* When up or down buttons are pressed, change the brightness. | ||
*/ | ||
if (IrReceiver.decode()) { | ||
if (IrReceiver.decodedIRData.protocol == UNKNOWN) { | ||
Serial.println("unknown"); | ||
IrReceiver.printIRResultRawFormatted(&Serial, true); | ||
IrReceiver.resume(); | ||
} else { | ||
IrReceiver.resume(); | ||
//IrReceiver.printIRResultShort(&Serial); | ||
|
||
// Ignore repeat codes from holding down the button | ||
if (IrReceiver.decodedIRData.flags == 0){ | ||
//Serial.printf("Command: %d\n",IrReceiver.decodedIRData.command); | ||
if (IrReceiver.decodedIRData.command == upCmd){ | ||
Serial.println("UP btn"); | ||
brightness = min(brightness + 25, 255); | ||
}else if (IrReceiver.decodedIRData.command == downCmd){ | ||
Serial.println("DOWN btn"); | ||
brightness = max(brightness - 25, 0); | ||
}else if (IrReceiver.decodedIRData.command == leftCmd){ | ||
Serial.println("LEFT btn"); | ||
pixelHue = (pixelHue - 8192) % 65536; | ||
}else if (IrReceiver.decodedIRData.command == rightCmd){ | ||
Serial.println("RIGHT btn"); | ||
pixelHue = (pixelHue + 8192) % 65536; | ||
} | ||
|
||
NEOPIXEL_STRIP.setBrightness(brightness); | ||
NEOPIXEL_STRIP.fill(NEOPIXEL_STRIP.gamma32(NEOPIXEL_STRIP.ColorHSV(pixelHue))); | ||
NEOPIXEL_STRIP.show(); | ||
delay(100); | ||
} | ||
} | ||
Serial.println(); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
Sparkle_Motion_Examples/CircuitPython_Sparkle_Motion_IR_Remote/code.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries | ||
# SPDX-FileCopyrightText: 2025 Tim Cocks for Adafruit Industries | ||
# SPDX-License-Identifier: MIT | ||
"""CircuitPython Adafruit Sparkle Motion IR remote control NeoPixels example.""" | ||
import time | ||
|
||
import board | ||
import pulseio | ||
from rainbowio import colorwheel | ||
|
||
import neopixel | ||
import adafruit_irremote | ||
|
||
pulsein = pulseio.PulseIn(board.IR, maxlen=120, idle_state=True) | ||
decoder = adafruit_irremote.NonblockingGenericDecode(pulsein) | ||
|
||
IR_CODE_UP = (0, 253, 160, 95) | ||
IR_CODE_DOWN = (0, 253, 176, 79) | ||
|
||
IR_CODE_RIGHT = (0, 253, 80, 175) | ||
IR_CODE_LEFT = (0, 253, 16, 239) | ||
|
||
t0 = next_heartbeat = time.monotonic() | ||
|
||
pixel = neopixel.NeoPixel(board.NEOPIXEL, 1) | ||
|
||
brightness = 1 | ||
pixel.brightness = brightness / 10 | ||
|
||
color_number = 160 | ||
pixel.fill(colorwheel(color_number)) | ||
while True: | ||
for message in decoder.read(): | ||
print(f"t={time.monotonic() - t0:.3} New IR Message") | ||
if isinstance(message, adafruit_irremote.IRMessage): | ||
if message.code == IR_CODE_UP: | ||
brightness = min(brightness + 1, 10) | ||
elif message.code == IR_CODE_DOWN: | ||
brightness = max(brightness - 1, 0) | ||
elif message.code == IR_CODE_RIGHT: | ||
color_number = (color_number + 32) % 256 | ||
elif message.code == IR_CODE_LEFT: | ||
color_number = (color_number - 32) % 256 | ||
|
||
pixel.brightness = brightness / 10 | ||
pixel.fill(colorwheel(color_number)) | ||
|
||
print("Decoded:", message.code) | ||
print("Brightness: ", brightness/10, " Color: ", hex(colorwheel(color_number))) | ||
elif isinstance(message, adafruit_irremote.NECRepeatIRMessage): | ||
print("NEC repeat!") | ||
elif isinstance(message, adafruit_irremote.UnparseableIRMessage): | ||
print("Failed to decode", message.reason) | ||
print("----------------------------") |