fluorescent test python and effect improvement
This commit is contained in:
parent
87fc8d12b2
commit
94abea021a
|
@ -282,21 +282,49 @@ void loopHandler()
|
||||||
//mosquitto_pub -h raum.ctdo.de -t "homie/esp-deckenlicht/strip/fluorescent/set" -m "255"
|
//mosquitto_pub -h raum.ctdo.de -t "homie/esp-deckenlicht/strip/fluorescent/set" -m "255"
|
||||||
|
|
||||||
if (millis() > fluorescentLastUpdated+FLUORESCENTUPDATEINTERVAL){ //Update values
|
if (millis() > fluorescentLastUpdated+FLUORESCENTUPDATEINTERVAL){ //Update values
|
||||||
fluorescentTemp+=random(0, 5); //min (inclusive), max (exclusive)
|
fluorescentLastUpdated=millis();
|
||||||
|
|
||||||
|
/*
|
||||||
|
fluorescentTemp+=random(0, 3); //min (inclusive), max (exclusive)
|
||||||
fluorescentLastUpdated=millis();
|
fluorescentLastUpdated=millis();
|
||||||
|
|
||||||
if (random(0,256)<fluorescentTemp*1.0/FLUORESCENTTEMPMAX*256){ //the warmer, the more often
|
if (random(0,256)<fluorescentTemp*1.0/FLUORESCENTTEMPMAX*256){ //the warmer, the more often
|
||||||
if (random(0,10)==0){ //ignite
|
if (random(0,40)==0){ //ignite
|
||||||
fluorescentCurrentBrightness=fluorescentSet*0.9;
|
fluorescentCurrentBrightness=fluorescentSet/100.0*random(50,100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (random(0,256)>fluorescentTemp*1.0/FLUORESCENTTEMPMAX*256){ //the colder, the more often
|
if (random(0,256)>fluorescentTemp*1.0/FLUORESCENTTEMPMAX*256){ //the colder, the more often
|
||||||
if (fluorescentCurrentBrightness<5){ //not on
|
if (fluorescentCurrentBrightness<5){ //not on
|
||||||
if (random(0,20)==0){ //ignite
|
if (random(0,50)==0){ //ignite
|
||||||
fluorescentCurrentBrightness=fluorescentSet*0.9;
|
fluorescentCurrentBrightness=fluorescentSet/100.0*random(50,100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fluorescentCurrentBrightness-=50;
|
if (fluorescentCurrentBrightness>20){ //minimum brightness
|
||||||
|
fluorescentCurrentBrightness-=random(20,40);
|
||||||
|
}else{
|
||||||
|
fluorescentCurrentBrightness+=random(2,3)-2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
fluorescentTemp+=1+ random(0,20*fluorescentTemp/FLUORESCENTTEMPMAX);
|
||||||
|
//fluorescentTemp+=3;
|
||||||
|
|
||||||
|
if (random(0,80)==0){ //ignite
|
||||||
|
fluorescentCurrentBrightness=fluorescentSet*random(50,100)/100;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fluorescentTemp>200){ // warm enough to glow
|
||||||
|
if (fluorescentCurrentBrightness<20){ //if under glow brightness
|
||||||
|
fluorescentCurrentBrightness+=5; //start glowing
|
||||||
|
}else if(fluorescentCurrentBrightness>50){ //too bright to glow
|
||||||
|
fluorescentCurrentBrightness-=random(0,30); //reduce intensity
|
||||||
|
}
|
||||||
|
}else{ //not warm enough to glow
|
||||||
|
if (fluorescentCurrentBrightness>0){
|
||||||
|
fluorescentCurrentBrightness-=random(20,50); //reduce intensity
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,113 @@
|
||||||
|
|
||||||
|
import pygame
|
||||||
|
import random
|
||||||
|
|
||||||
|
pygame.init()
|
||||||
|
|
||||||
|
# Set the height and width of the screen
|
||||||
|
size = (400, 100)
|
||||||
|
screen = pygame.display.set_mode(size)
|
||||||
|
|
||||||
|
pygame.display.set_caption("Blafoo")
|
||||||
|
|
||||||
|
# Loop until the user clicks the close button.
|
||||||
|
done = False
|
||||||
|
clock = pygame.time.Clock()
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
FLUORESCENTTEMPMAX=400
|
||||||
|
|
||||||
|
fluorescentCurrentBrightness=0
|
||||||
|
fluorescentTemp=0
|
||||||
|
fluorescentActive=True
|
||||||
|
|
||||||
|
|
||||||
|
fluorescentSet=255
|
||||||
|
|
||||||
|
|
||||||
|
# Loop as long as done == False
|
||||||
|
while not done:
|
||||||
|
ms = time.time()*1000.0
|
||||||
|
|
||||||
|
for event in pygame.event.get(): # User did something
|
||||||
|
if event.type == pygame.QUIT: # If user clicked close
|
||||||
|
done = True # Flag that we are done so we exit this loop
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
if (fluorescentActive):
|
||||||
|
fluorescentTemp+=random.randint(0,3 +1)
|
||||||
|
|
||||||
|
if (random.randint(0, 256+1) < fluorescentTemp*1.0/FLUORESCENTTEMPMAX*256):
|
||||||
|
if (random.randint(0, 40+1) ==0): #ignite
|
||||||
|
fluorescentCurrentBrightness=fluorescentSet*random.randint(50,100)/100
|
||||||
|
|
||||||
|
if (random.randint(0, 256+1) > fluorescentTemp*1.0/FLUORESCENTTEMPMAX*256):
|
||||||
|
if (fluorescentCurrentBrightness<5):
|
||||||
|
if (random.randint(0,50 +1)==0): #ignite
|
||||||
|
fluorescentCurrentBrightness=fluorescentSet*random.randint(50,100)/100
|
||||||
|
if (fluorescentCurrentBrightness>20):
|
||||||
|
fluorescentCurrentBrightness-=30
|
||||||
|
|
||||||
|
if (fluorescentTemp>=FLUORESCENTTEMPMAX):
|
||||||
|
fluorescentActive=False
|
||||||
|
fluorescentCurrentBrightness=fluorescentSet
|
||||||
|
|
||||||
|
|
||||||
|
if (fluorescentCurrentBrightness>255):
|
||||||
|
fluorescentCurrentBrightness=255
|
||||||
|
if (fluorescentCurrentBrightness<0):
|
||||||
|
fluorescentCurrentBrightness=0
|
||||||
|
|
||||||
|
COLOR = (fluorescentCurrentBrightness,fluorescentCurrentBrightness,fluorescentCurrentBrightness)
|
||||||
|
else:
|
||||||
|
COLOR = (fluorescentSet,fluorescentSet,fluorescentSet)
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
if (fluorescentActive):
|
||||||
|
fluorescentTemp+=1+ random.randint(0,20* fluorescentTemp/FLUORESCENTTEMPMAX)
|
||||||
|
#fluorescentTemp+=3
|
||||||
|
|
||||||
|
|
||||||
|
if (random.randint(0,80 +1)==0): #ignite
|
||||||
|
fluorescentCurrentBrightness=fluorescentSet*random.randint(50,100)/100
|
||||||
|
|
||||||
|
if (fluorescentTemp>200): #warm enough to glow
|
||||||
|
if (fluorescentCurrentBrightness<20): #if under glow brightness
|
||||||
|
fluorescentCurrentBrightness+=5 #start glowing
|
||||||
|
elif (fluorescentCurrentBrightness>50): #too bright for glow
|
||||||
|
fluorescentCurrentBrightness-=random.randint(0,30) #reduce intencity (flashing effect)
|
||||||
|
else: #not warm enough to glow
|
||||||
|
if (fluorescentCurrentBrightness>0): #too bright for glow
|
||||||
|
fluorescentCurrentBrightness-=random.randint(20,50) #reduce intencity (flashing effect)
|
||||||
|
|
||||||
|
if (fluorescentTemp>=FLUORESCENTTEMPMAX):
|
||||||
|
fluorescentActive=False
|
||||||
|
fluorescentCurrentBrightness=fluorescentSet
|
||||||
|
print("Finished")
|
||||||
|
|
||||||
|
if (fluorescentCurrentBrightness>255):
|
||||||
|
fluorescentCurrentBrightness=255
|
||||||
|
if (fluorescentCurrentBrightness<0):
|
||||||
|
fluorescentCurrentBrightness=0
|
||||||
|
|
||||||
|
COLOR = (fluorescentCurrentBrightness,fluorescentCurrentBrightness,fluorescentCurrentBrightness)
|
||||||
|
else:
|
||||||
|
COLOR = (fluorescentSet,fluorescentSet,fluorescentSet)
|
||||||
|
|
||||||
|
|
||||||
|
screen.fill(COLOR)
|
||||||
|
|
||||||
|
pygame.display.flip()
|
||||||
|
|
||||||
|
# This limits the while loop to a max of 60 times per second.
|
||||||
|
# Leave this out and we will use all CPU we can.
|
||||||
|
clock.tick(50)
|
||||||
|
|
||||||
|
# Be IDLE friendly
|
||||||
|
pygame.quit()
|
Loading…
Reference in New Issue