add diffrent brightness leds
This commit is contained in:
11
src/defs.h
11
src/defs.h
@@ -35,4 +35,13 @@
|
||||
|
||||
#define PROBE_EXT_PIN PA3
|
||||
#define PROBE_EXT_DDR DDRA
|
||||
#define PROBE_EXT_PORT PORTA
|
||||
#define PROBE_EXT_PORT PORTA
|
||||
|
||||
|
||||
#define LED_LEFT_GREEN() (LED12_SW_PORT &= ~(1 << LED12_SW_PIN))
|
||||
#define LED_LEFT_RED() (LED12_SW_PORT |= (1 << LED12_SW_PIN))
|
||||
#define LED_RIGHT_GREEN() (LED34_SW_PORT &= ~(1 << LED34_SW_PIN))
|
||||
#define LED_RIGHT_RED() (LED34_SW_PORT |= (1 << LED34_SW_PIN))
|
||||
|
||||
#define LED_GREEN_BRIGHTNESS 10
|
||||
#define LED_RED_BRIGHTNESS 80
|
||||
67
src/led_pwm.c
Normal file
67
src/led_pwm.c
Normal file
@@ -0,0 +1,67 @@
|
||||
#include <avr/io.h>
|
||||
#include "defs.h"
|
||||
#include "led_pwm.h"
|
||||
|
||||
static void led_pwm_init(void)
|
||||
{
|
||||
// Ustaw pin PB1 (OC1A) jako wyjście
|
||||
LED_PWM_DDR |= (1 << LED_PWM1_PIN) | (1 << LED_PWM2_PIN);
|
||||
|
||||
// Fast PWM, 8-bit mode, non-inverting mode
|
||||
TCCR1A = (1 << COM1A1) | (1 << COM1B1) | (1 << WGM10); // Clear OC1A on compare match
|
||||
TCCR1B = (1 << WGM12) | (1 << CS11) | (1 << CS10); // Prescaler 64
|
||||
|
||||
OCR1A = 0;
|
||||
OCR1B = 0;
|
||||
|
||||
}
|
||||
|
||||
void led_init(void)
|
||||
{
|
||||
// Set pins for LED control as output
|
||||
LED12_SW_DDR |= (1 << LED12_SW_PIN);
|
||||
LED34_SW_DDR |= (1 << LED34_SW_PIN);
|
||||
|
||||
// Turn on red LEDs initially
|
||||
LED_LEFT_RED();
|
||||
LED_RIGHT_RED();
|
||||
|
||||
// Initialize PWM for LEDs
|
||||
led_pwm_init();
|
||||
}
|
||||
|
||||
void led_set_color(led_color_t color, led_side_t side)
|
||||
{
|
||||
uint8_t pwm_percent = 0;
|
||||
|
||||
if (side && LED_LEFT)
|
||||
{
|
||||
if (color == LED_COLOR_GREEN)
|
||||
{
|
||||
LED_LEFT_GREEN();
|
||||
pwm_percent = LED_GREEN_BRIGHTNESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
LED_LEFT_RED();
|
||||
pwm_percent = LED_RED_BRIGHTNESS;
|
||||
}
|
||||
OCR1A = (pwm_percent * 255) / 100; // Set PWM duty cycle for left LED
|
||||
}
|
||||
|
||||
if (side && LED_RIGHT)
|
||||
{
|
||||
if (color == LED_COLOR_GREEN)
|
||||
{
|
||||
LED_RIGHT_GREEN();
|
||||
pwm_percent = LED_GREEN_BRIGHTNESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
LED_RIGHT_RED();
|
||||
pwm_percent = LED_RED_BRIGHTNESS;
|
||||
}
|
||||
OCR1B = (pwm_percent * 255) / 100; // Set PWM duty cycle for right LED
|
||||
}
|
||||
|
||||
}
|
||||
15
src/led_pwm.h
Normal file
15
src/led_pwm.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
typedef enum {
|
||||
LED_COLOR_RED,
|
||||
LED_COLOR_GREEN,
|
||||
} led_color_t;
|
||||
|
||||
typedef enum {
|
||||
LED_LEFT = 1,
|
||||
LED_RIGHT = 2,
|
||||
LED_BOTH = 3,
|
||||
} led_side_t;
|
||||
|
||||
void led_init(void);
|
||||
void led_set_color(led_color_t color, led_side_t side);
|
||||
Reference in New Issue
Block a user