-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9417dad
Showing
10 changed files
with
1,661 additions
and
0 deletions.
There are no files selected for viewing
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,25 @@ | ||
on: | ||
workflow_dispatch: | ||
push: | ||
pull_request: | ||
|
||
permissions: | ||
contents: read | ||
pull-requests: read | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: install avr tool chain | ||
run: | | ||
sudo apt-get update \ | ||
&& sudo apt-get install -y \ | ||
avrdude \ | ||
gcc-avr \ | ||
gdb-avr \ | ||
avr-libc \ | ||
binutils-avr | ||
- name: make | ||
run: make all |
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,55 @@ | ||
build/ | ||
.vscode/ | ||
|
||
# Prerequisites | ||
*.d | ||
|
||
# Object files | ||
*.o | ||
*.ko | ||
*.obj | ||
*.elf | ||
|
||
# Linker output | ||
*.ilk | ||
*.map | ||
*.exp | ||
|
||
# Precompiled Headers | ||
*.gch | ||
*.pch | ||
|
||
# Libraries | ||
*.lib | ||
*.a | ||
*.la | ||
*.lo | ||
|
||
# Shared objects (inc. Windows DLLs) | ||
*.dll | ||
*.so | ||
*.so.* | ||
*.dylib | ||
|
||
# Executables | ||
*.exe | ||
*.out | ||
*.app | ||
*.i*86 | ||
*.x86_64 | ||
*.hex | ||
|
||
# Debug files | ||
*.dSYM/ | ||
*.su | ||
*.idb | ||
*.pdb | ||
|
||
# Kernel Module Compile Results | ||
*.mod* | ||
*.cmd | ||
.tmp_versions/ | ||
modules.order | ||
Module.symvers | ||
Mkfile.old | ||
dkms.conf |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,70 @@ | ||
# AVR project Makefile | ||
|
||
# Microcontroller | ||
MCU = atmega328p | ||
|
||
# F_CPU (in Hz) | ||
F_CPU = 16000000UL | ||
|
||
# Programmer | ||
PROGRAMMER = -c arduino -P /dev/ttyACM0 -b 115200 | ||
|
||
# Compiler | ||
CC = avr-gcc | ||
OBJCOPY = avr-objcopy | ||
OBJDUMP = avr-objdump | ||
SIZE = avr-size | ||
AVRDUDE = avrdude | ||
|
||
# Compiler flags | ||
CFLAGS = -g -Wall -Os -mmcu=$(MCU) -DF_CPU=$(F_CPU) -fexceptions | ||
|
||
# Source directory | ||
SRC_DIR = src | ||
|
||
# Build directory | ||
BUILD_DIR = build | ||
|
||
# Source files | ||
SRCS = main.c $(wildcard $(SRC_DIR)/libs/**/*.c) | ||
|
||
# Object files | ||
OBJS = $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(SRCS)) | ||
|
||
# Output files | ||
TARGET = main | ||
ELF = $(TARGET).elf | ||
HEX = $(TARGET).hex | ||
MAP = $(TARGET).map | ||
EEP = $(TARGET).eep | ||
|
||
# Rules | ||
all: $(HEX) | ||
|
||
$(HEX): $(ELF) | ||
$(OBJCOPY) -O ihex -R .eeprom $(ELF) $(HEX) | ||
|
||
$(ELF): $(OBJS) | ||
$(CC) $(CFLAGS) $(OBJS) -o $(ELF) | ||
$(OBJDUMP) -h -S $(ELF) > $(MAP) | ||
$(SIZE) --format=avr --mcu=$(MCU) $(ELF) | ||
|
||
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c | $(BUILD_DIR) $(dir $(OBJS)) | ||
$(CC) $(CFLAGS) -c $< -o $@ | ||
|
||
$(BUILD_DIR): | ||
mkdir -p $(BUILD_DIR) | ||
|
||
$(dir $(OBJS)): | ||
mkdir -p $@ | ||
|
||
flash: $(HEX) | ||
$(AVRDUDE) $(PROGRAMMER) -p $(MCU) -U flash:w:$(HEX):i | ||
|
||
eeprom: $(EEP) | ||
$(AVRDUDE) $(PROGRAMMER) -p $(MCU) -U eeprom:w:$(EEP):i | ||
|
||
clean: | ||
rm -rf $(BUILD_DIR) $(ELF) $(HEX) $(MAP) $(EEP) | ||
|
||
.PHONY: all flash eeprom clean |
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,70 @@ | ||
# AVR IR remote LED lamp | ||
|
||
This project implements an infrared (IR) remote-controlled LED system using an AVR microcontroller. It allows users to adjust LED brightness and toggle RGB LED colors using a compatible IR remote control. | ||
|
||
## Features | ||
|
||
- Adjust RGB LED colors with volume up and down commands. | ||
- Control LED brightness with channel up and down commands. | ||
- Turn off all LEDs with the power command. | ||
- Smooth LED dimming achieved through software PWM. | ||
|
||
## Hardware Requirements | ||
|
||
- AVR microcontroller (e.g., ATmega328P or Arduino uno) | ||
- 1x IR receiver module | ||
- 5x LEDs | ||
- 4x single-color | ||
- 1x RKGB | ||
- 7x 330 Ohm resistors | ||
- 1x IR remote control | ||
- 1x Power supply (9V) | ||
|
||
## Diagram | ||
|
||
![Diagram](Diagram.png) | ||
|
||
## Software Requirements | ||
|
||
- AVR-GCC toolchain | ||
- AVRDUDE (for flashing the microcontroller) | ||
- Required AVR libraries (included in the [`./src/libs`](./src/libs) directory) | ||
- [IRremote.h](./src/libs/IRremote.h) | ||
- [softwarePWM.h](./src/libs/softwarePWM.h) | ||
- [uart.h](./src/libs/uart.h) (Optional) | ||
|
||
## Installation | ||
|
||
1. Connect the hardware components according to the schematic. | ||
2. Clone this repository to your local machine. | ||
3. Compile the source code using the AVR-GCC toolchain. | ||
```bash | ||
make all | ||
``` | ||
4. Flash the compiled binary onto the AVR microcontroller using AVRDUDE. | ||
```bash | ||
make flash | ||
``` | ||
|
||
## Usage | ||
|
||
1. Power on the system. | ||
2. Point the IR remote control towards the IR receiver module. | ||
3. Press the appropriate buttons on the remote control to control the LEDs: | ||
- Volume up/down: Change RGB LED colors. | ||
- Channel up/down: Adjust LED brightness. | ||
- Power: Turn off all LEDs. | ||
4. LED status updates will be displayed via UART communication (if needed). | ||
|
||
## Notes | ||
- Uncomment uart if needed. | ||
- You may need to change command codes according to your IR remote, use uart to find your codes. | ||
- Changing ports have to be changed in [softwarePWM.h](./src/libs/softwarePWM.h)'s channel sections. | ||
|
||
## References | ||
- [IRremote.h](https://www.programming-electronics-diy.xyz/2022/08/ir-remote-control-library-for-avr.html) - Liviu Istrate | ||
- [softwarePWM.h](https://www.programming-electronics-diy.xyz/2021/02/multi-channel-software-pwm-library-for.html) - Liviu Istrate | ||
|
||
## Contributions | ||
|
||
Contributions are welcome! Feel free to submit bug reports, feature requests, or pull requests. |
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,9 @@ | ||
FROM ubuntu | ||
|
||
RUN apt update | ||
RUN apt install \ | ||
avrdude \ | ||
gcc-avr \ | ||
gdb-avr \ | ||
avr-libc \ | ||
binutils-avr |
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,145 @@ | ||
/*___________________________________________________________________________________________________ | ||
Title: | ||
AVR LED IR remote lamp | ||
Description: | ||
This code is designed for controlling LED brightness and color using an IR remote control. | ||
It utilizes software PWM for smooth LED dimming and toggling of RGB LEDs. | ||
Author: | ||
QuintusJoyal | ||
_____________________________________________________________________________________________________*/ | ||
|
||
#include <avr/io.h> // AVR standard I/O definitions | ||
#include <util/delay.h> // Functions to create time delays | ||
#include <avr/interrupt.h> // AVR interrupt handling functions | ||
// #include "./src/libs/uart.h" // UART communication library | ||
#include "./src/libs/IRremote.h" // IR remote control library | ||
#include "./src/libs/softwarePWM.h" // Software PWM library | ||
|
||
#define F_CPU 16000000UL // Define CPU frequency | ||
#define BAUDRATE 9600 // Define baud rate for UART communication | ||
|
||
#define VOL_UP 25 // IR command code for volume up | ||
#define VOL_DOWN 22 // IR command code for volume down | ||
#define CH_UP 21 // IR command code for channel up | ||
#define CH_DOWN 7 // IR command code for channel down | ||
#define POWER 69 // IR command code for power | ||
|
||
#define BRIGHTNESS_STEP (uint8_t) 15 // Step size for adjusting brightness | ||
|
||
uint8_t brightness = 20; // Initial brightness level | ||
uint8_t level = 0; // Initial LED level | ||
|
||
// Function to set LED brightness according to level | ||
void LED_brightness() { | ||
for (uint8_t i = 0; i < level; i++) { | ||
softwarePWM_Set(i, brightness); | ||
} | ||
} | ||
|
||
// Function to turn on a specific LED | ||
void LED_turn_on(uint8_t led) { | ||
softwarePWM_Set(led, brightness); | ||
} | ||
|
||
// Function to turn off a specific LED | ||
void LED_turn_off(uint8_t led) { | ||
softwarePWM_Set(led, 0); | ||
} | ||
|
||
// Function to toggle RGB LEDs based on level | ||
void RGB_toggle() { | ||
uint8_t m = (level - 1) % 3; | ||
softwarePWM_Set(4, brightness * (m == 0)); | ||
softwarePWM_Set(5, brightness * (m == 1)); | ||
softwarePWM_Set(6, brightness * (m == 2)); | ||
} | ||
|
||
// Function to increase volume level | ||
void vol_up() { | ||
if (level > 6) { | ||
RGB_toggle(); // Toggle RGB LEDs | ||
level = (level <= 9) ? level + 1 : 7; // Increment level, limit at 7 | ||
return; | ||
} | ||
LED_turn_on(level++); // Turn on LED at current level | ||
} | ||
|
||
// Function to decrease volume level | ||
void vol_down() { | ||
if (level > 7) { | ||
--level; | ||
RGB_toggle(); // Toggle RGB LEDs | ||
return; | ||
} | ||
if (level == 7) { | ||
// Turn on RGB LEDs at level 7 | ||
LED_turn_on(4); | ||
LED_turn_on(5); | ||
LED_turn_on(6); | ||
--level; | ||
return; | ||
} | ||
LED_turn_off(level--); // Turn off LED at current level | ||
if (level == UINT8_MAX) level = 0; // Wrap level around if overflow | ||
} | ||
|
||
// Function to increase brightness | ||
void ch_up() { | ||
brightness = (brightness + BRIGHTNESS_STEP < UINT8_MAX) ? | ||
brightness + (level > 0) * BRIGHTNESS_STEP : UINT8_MAX; // Increase brightness, limit at maximum | ||
LED_brightness(); // Adjust LED brightness | ||
} | ||
|
||
// Function to decrease brightness | ||
void ch_down() { | ||
brightness = (brightness - BRIGHTNESS_STEP > 0) ? | ||
brightness - (level > 0) * BRIGHTNESS_STEP : 0; // Decrease brightness, limit at minimum | ||
LED_brightness(); // Adjust LED brightness | ||
} | ||
|
||
// Function to turn off all LEDs | ||
void power() { | ||
for (int8_t i = 6; i >= 0; i--) LED_turn_off(i); // Turn off all LEDs | ||
level = 0; // Reset LED levels | ||
} | ||
|
||
// Function to control LEDs based on received IR command | ||
void LED_control(uint16_t command) { | ||
switch (command) { | ||
case VOL_UP: vol_up(); break; // Volume up command | ||
case VOL_DOWN: vol_down(); break; // Volume down command | ||
case CH_UP: ch_up(); break; // Channel up command | ||
case CH_DOWN: ch_down(); break; // Channel down command | ||
case POWER: power(); break; // Power command | ||
default: break; | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
uint16_t address = 0; // Variable to store IR address | ||
uint16_t command = 0; // Variable to store IR command | ||
|
||
IR_init(); // Initialize IR remote control | ||
// uart_init(); // Initialize UART communication | ||
softwarePWM_Init(); // Initialize software PWM | ||
|
||
// uart_puts("Well I'm working here!\r\n"); // Send message indicating successful initialization | ||
while (1) { | ||
if (IR_codeAvailable()) { // Check if IR code is available | ||
if (!IR_isRepeatCode()) { // Check if IR code is not a repeat | ||
IR_getCode(&address, &command); // Get IR address and command | ||
LED_control(command); // Control LEDs based on received command | ||
// uart_putU16(address); // Send IR address over UART | ||
// uart_puts(", "); | ||
// uart_putU16(command); // Send IR command over UART | ||
// uart_puts(", "); | ||
// uart_putU8(level); // Send current LED level over UART | ||
// uart_puts("\r\n"); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.