From 94abea021a86731bbd10479b45b63305982b7f4c Mon Sep 17 00:00:00 2001 From: Fisch Date: Wed, 21 Nov 2018 00:33:56 +0100 Subject: [PATCH] fluorescent test python and effect improvement --- esp-deckenlicht.ino | 40 ++++++++++++--- lighttest/lighttest.py | 113 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+), 6 deletions(-) create mode 100644 lighttest/lighttest.py diff --git a/esp-deckenlicht.ino b/esp-deckenlicht.ino index 85d5f52..287e0eb 100644 --- a/esp-deckenlicht.ino +++ b/esp-deckenlicht.ino @@ -282,21 +282,49 @@ void loopHandler() //mosquitto_pub -h raum.ctdo.de -t "homie/esp-deckenlicht/strip/fluorescent/set" -m "255" 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(); if (random(0,256)fluorescentTemp*1.0/FLUORESCENTTEMPMAX*256){ //the colder, the more often if (fluorescentCurrentBrightness<5){ //not on - if (random(0,20)==0){ //ignite - fluorescentCurrentBrightness=fluorescentSet*0.9; + if (random(0,50)==0){ //ignite + 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 + } } diff --git a/lighttest/lighttest.py b/lighttest/lighttest.py new file mode 100644 index 0000000..e230c6b --- /dev/null +++ b/lighttest/lighttest.py @@ -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()