program PotzBlitz_Funktion sub procedure Interrupt() StrikeCount = StrikeCount + 32 if StrikeCount >= 255 then 'More then 8 Strikes in 1 Second ? StrikeCount = 255 'More then 8 strikes per second don't happen naturaly end if if level < 6000 then LED_Red = 1 end if PIR2.C1IF = 0 'Clear the comparator flag end sub main: While(1) 'Main loop For AnalysisCounter = 0 To 31 'Measure for 32 seconds StrikeCount = 0 'Reset the count of the lightning strikes if ((((AnalysisCounter + 1) mod 4) = 0) and (Level < 2000)) then 'Flash each fourt cycle the green "In Operation" LED LED_Green = 1 'Also wait 30ms delay_ms(30) LED_Green = 0 else delay_ms(30) end if for tempus = 0 to 96 'Wait for 970ms If Level < 6000 then 'Reset the red LED, if set by interrupt LED_Red = 0 end if delay_ms(10) next tempus If StrikeCount > 32 Then 'min 2 Impulse Level = Level + StrikeCount 'Count End If Decay = Hi(Level) 'Calculate the decay Level = Level - Decay 'Level decreasing If Level < 1000 Then 'Set PWM Level to 62.5% PWM2_Set_Duty (PWM62Percent) end if If Level > 3000 Then 'Set PWM Level to 50% PWM2_Set_Duty (PWM50Percent) end if If Level >= 7000 Then 'limit the level Level = 7000 end if If Level >= 6000 Then 'Flash red LED LED_Green = 0 LED_Yellow = 0 LED_Red = Not LED_Red goto LEDanalyseDone end if If Level >= 4000 Then 'Flash yellow LED LED_Green = 0 LED_Yellow = NOT LED_Yellow LED_Red = 0 goto LEDanalyseDone end if If Level >= 2000 Then 'Flash green LED LED_Green = Not LED_Green LED_Yellow = 0 LED_Red = 0 goto LEDanalyseDone end if If Level < 2000 Then LED_Green = 0 LED_Yellow = 0 LED_Red = 0 end if LEDanalyseDone: Next AnalysisCounter wend 'Next main loop end.