add led
This commit is contained in:
parent
37c038bcf7
commit
37223d78b2
@ -207,28 +207,28 @@ class LEDController:
|
||||
self._show_moving_colors(colors, speed=0.1)
|
||||
|
||||
def _waiting_nfc_effect(self):
|
||||
"""等待NFC效果 - 蓝色呼吸灯"""
|
||||
self._breathing_effect((0, 100, 255), min_brightness=0.1, max_brightness=0.8, speed=0.05)
|
||||
"""等待NFC效果 - 彩虹效果"""
|
||||
self._rainbow_effect()
|
||||
|
||||
def _calibrating_effect(self):
|
||||
"""校准效果 - 黄色跑马灯"""
|
||||
self._running_light_effect((255, 255, 0), speed=0.15)
|
||||
|
||||
def _idle_monitoring_effect(self):
|
||||
"""空闲监听效果 - 绿色微弱闪烁"""
|
||||
self._gentle_blink_effect((0, 255, 0), intensity=0.3, speed=1.0)
|
||||
"""空闲监听效果 - 脉冲效果"""
|
||||
self._pulse_effect_enhanced((0, 255, 0), speed=0.05)
|
||||
|
||||
def _recording_effect(self):
|
||||
"""录音效果 - 红色脉冲"""
|
||||
self._pulse_effect((255, 0, 0), speed=0.3)
|
||||
"""录音效果 - 脉冲效果"""
|
||||
self._pulse_effect_enhanced((255, 0, 0), speed=0.05)
|
||||
|
||||
def _processing_effect(self):
|
||||
"""处理效果 - 紫色旋转"""
|
||||
self._rotating_effect((128, 0, 128), speed=0.2)
|
||||
"""处理效果 - 剧院追逐效果"""
|
||||
self._theater_chase_effect()
|
||||
|
||||
def _playing_effect(self):
|
||||
"""播放效果 - 青色流动"""
|
||||
self._wave_effect((0, 255, 255), speed=0.4)
|
||||
"""播放效果 - 彩虹循环效果"""
|
||||
self._rainbow_cycle_effect()
|
||||
|
||||
def _character_switch_effect(self):
|
||||
"""角色切换效果 - 彩色波浪"""
|
||||
@ -245,6 +245,118 @@ class LEDController:
|
||||
|
||||
# ===== 基础特效函数 =====
|
||||
|
||||
def _rainbow_effect(self):
|
||||
"""彩虹效果"""
|
||||
if not hasattr(self, '_rainbow_phase'):
|
||||
self._rainbow_phase = 0
|
||||
|
||||
colors = []
|
||||
for i in range(self.led_count):
|
||||
color_index = (i + self._rainbow_phase) % 7
|
||||
colors.append(self._get_rainbow_color(color_index))
|
||||
|
||||
self._show_colors(colors)
|
||||
self._rainbow_phase = (self._rainbow_phase + 1) % 7
|
||||
time.sleep(0.1)
|
||||
|
||||
def _pulse_effect_enhanced(self, color: Tuple[int, int, int], speed=0.05):
|
||||
"""真正的脉冲效果"""
|
||||
if not hasattr(self, '_pulse_enhanced_state'):
|
||||
self._pulse_enhanced_state = {
|
||||
'phase': 'expand', # 'expand' 或 'contract'
|
||||
'position': 0,
|
||||
'max_position': self.led_count // 2
|
||||
}
|
||||
|
||||
state = self._pulse_enhanced_state
|
||||
colors = [(0, 0, 0)] * self.led_count
|
||||
|
||||
if state['phase'] == 'expand':
|
||||
# 从中心向外扩散
|
||||
if state['position'] <= state['max_position']:
|
||||
# 设置左右对称的LED
|
||||
if state['position'] < self.led_count:
|
||||
colors[state['position']] = color
|
||||
colors[self.led_count - 1 - state['position']] = color
|
||||
|
||||
state['position'] += 1
|
||||
else:
|
||||
# 切换到收缩阶段
|
||||
state['phase'] = 'contract'
|
||||
state['position'] = state['max_position']
|
||||
|
||||
elif state['phase'] == 'contract':
|
||||
# 从边缘向中心收缩
|
||||
if state['position'] >= 0:
|
||||
# 设置左右对称的LED
|
||||
if state['position'] < self.led_count:
|
||||
colors[state['position']] = color
|
||||
colors[self.led_count - 1 - state['position']] = color
|
||||
|
||||
state['position'] -= 1
|
||||
else:
|
||||
# 切换到扩散阶段
|
||||
state['phase'] = 'expand'
|
||||
state['position'] = 0
|
||||
|
||||
self._show_colors(colors)
|
||||
time.sleep(speed)
|
||||
|
||||
def _theater_chase_effect(self):
|
||||
"""剧院追逐效果"""
|
||||
if not hasattr(self, '_theater_chase_phase'):
|
||||
self._theater_chase_phase = 0
|
||||
|
||||
colors = []
|
||||
for i in range(self.led_count):
|
||||
if (i + self._theater_chase_phase) % 3 == 0:
|
||||
colors.append((255, 255, 0)) # 黄色
|
||||
else:
|
||||
colors.append((0, 0, 0))
|
||||
|
||||
self._show_colors(colors)
|
||||
self._theater_chase_phase = (self._theater_chase_phase + 1) % 3
|
||||
time.sleep(0.1)
|
||||
|
||||
def _rainbow_cycle_effect(self):
|
||||
"""彩虹循环效果"""
|
||||
if not hasattr(self, '_rainbow_cycle_phase'):
|
||||
self._rainbow_cycle_phase = 0
|
||||
|
||||
colors = []
|
||||
for i in range(self.led_count):
|
||||
pixel_index = (self._rainbow_cycle_phase * 256 // self.led_count + i) % 256
|
||||
colors.append(self._wheel(pixel_index))
|
||||
|
||||
self._show_colors(colors)
|
||||
self._rainbow_cycle_phase = (self._rainbow_cycle_phase + 1) % 256
|
||||
time.sleep(0.02)
|
||||
|
||||
def _get_rainbow_color(self, index):
|
||||
"""获取彩虹颜色"""
|
||||
rainbow_colors = [
|
||||
(150, 0, 0), # 红
|
||||
(150, 75, 0), # 橙
|
||||
(150, 150, 0), # 黄
|
||||
(0, 150, 0), # 绿
|
||||
(0, 0, 150), # 蓝
|
||||
(50, 0, 100), # 靛
|
||||
(100, 0, 150) # 紫
|
||||
]
|
||||
return rainbow_colors[index % len(rainbow_colors)]
|
||||
|
||||
def _wheel(self, pos):
|
||||
"""生成彩虹颜色(来自wheel函数)"""
|
||||
pos = 255 - pos
|
||||
if pos < 85:
|
||||
return (255 - pos * 3, 0, pos * 3)
|
||||
elif pos < 170:
|
||||
pos -= 85
|
||||
return (0, pos * 3, 255 - pos * 3)
|
||||
else:
|
||||
pos -= 170
|
||||
return (pos * 3, 255 - pos * 3, 0)
|
||||
|
||||
def _breathing_effect(self, color: Tuple[int, int, int], min_brightness=0.1, max_brightness=0.8, speed=0.05):
|
||||
"""呼吸效果"""
|
||||
steps = 50
|
||||
|
||||
Loading…
Reference in New Issue
Block a user