Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Snowflakes spark effect for Rainbowleds

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here
View previous topic :: View next topic  
Author Message
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Fri Dec 20, 2019 6:36 pm    Post subject: Snowflakes spark effect for Rainbowleds Reply with quote

I should share this beautifull effect that I write from scratch and this is not a some another language translate. I was thinkinig about this effect My own.
Program should randomly choose from leds with 0 PWM and SPARK! them into 255 PWM. Then this LED slowly dissapear Very Happy

This is the part of the bigger project - "Octopus on the disco club" so this project have more and more scenarios with scenarios autorotation, peak measure so leds are active like VU and even AGC (auto gain control)..but after all if no music in the club this mode will in Very Happy SNOWEFFECT Very Happy

Sorry for the late share but maybe for this Christmas...

I cant record on the camera how this effect looks like. I have two telephones. iPhone SE cant record this effect. record that I link was made by Xiaomi Remi 7A. Not good - you know Very Happy But better can show how snowlake effect works.

Link to the snowflake_effect short movie ->LINK

If anyone interested how my octopus software works with music on the christmass three then you can watch this link where snowflake_effect is visible when music stops Very Happy ->LINK

Snowflake_effect - code
Code:
$regfile = "m328pdef.dat"
$crystal = 16000000
$hwstack = 64
$swstack = 32
$framesize = 128
$baud = 115200

Const Number_of_leds = 45

'*******************************************************
'*          TIMER SETTINGS FOR TIME BASE               *
'*******************************************************
 Config Timer0 = Timer , Prescale = 1024 , Clear_timer = 1

  'Compare0a = 124                                          '2ms @16MHz/256
   Compare0a = 77                                           '5ms @16MHz/1024
  'Compare0a = 155                                          '10ms @16MHz/1024

'*******************************************************
'*             MULTIPURPOSE VARIABLES                  *
'*******************************************************
  Dim Helpb As Byte , N As Byte

'*******************************************************
'*               RAINBOWLEDS SETTINGS                  *
'*******************************************************

Config Rainbow = 1 , Rb0_len = Number_of_leds , Rb0_port = Portc , Rb0_pin = 0
 Rb_selectchannel 0                                         'wybierz kanal
  Rb_clearcolors : Rb_send                                  'i czysc po reset

Dim Color(3) As Byte

Const Snow_max = 20

Dim Numleds As Byte
Dim Flash As Byte , Sparked As Byte
Dim Los As Byte , Active As Byte , Running As Byte
Dim Wait_time As Byte , Countdown As Byte

Dim Spark(3) As Byte
 Spark(1) = &HFF
 Spark(2) = &HFF
 Spark(3) = &HFF
Dim Heat(255) As Byte

Numleds = Number_of_leds


Do

 If Tifr0.ocf0a = 1 Then
  Tifr0.ocf0a = 1

    If Running = 0 Then
        Running = 1

      Color(1) = Snow_max
      Color(2) = Snow_max
      Color(3) = Snow_max                             ' define a color

      For N = 0 To Numleds -1
        Rb_setcolor N , Color(1)
      Next

    Else

     If Flash = 1 Then
      Flash = 0
       Rb_setcolor Sparked , Color(1)
        'Rb_send
     End If


     Helpb = Rnd(5)
     If Helpb > 0 Then

       Los = Rnd(numleds)
       Color(1) = Rb_getcolor(los)
        Helpb = Color(1)

       Select Case Heat(los)
        Case 0
         'If Active < Numleds Then
          Heat(los) = 1
           'Incr Active
         'End If
        Case 1
         If Helpb > 0 Then
          Decr Helpb

          Color(1) = Helpb
          Color(2) = Helpb
          Color(3) = Helpb
           Rb_setcolor Los , Color(1)
             'Rb_send
         Else
          Heat(los) = 2
         End If

        Case 2
         If Color(1) < Snow_max Then
          Helpb = Rnd(snow_max)
          Helpb = Helpb / 4
          Color(1) = Color(1) + Helpb
          If Color(1) > Snow_max Then
           Color(1) = Snow_max
          End If
          Color(2) = Color(1)
          Color(3) = Color(1)
           Rb_setcolor Los , Color(1)
             'Rb_send
         Else
          Heat(los) = 0
           If Active > 0 Then Decr Active
         End If
       End Select

     End If

    End If

    Rb_send

   If Countdown > 0 Then
     Decr Countdown
   Else
     '-------------------------------------------[SNOW]--
     'time to time spark one pixel
      If Running = 1 Then
       Sparked = Rnd(numleds)
        Color(1) = Rb_getcolor(sparked)
         Rb_setcolor Sparked , Spark(1)
          Rb_send
         Wait_time = Rnd(200)
           Flash = 1
      End If



    Countdown = Wait_time
   End If



 'end if 2ms
 End If

Loop


 


[Edited] There is a one hidden constant in this code "Const Snow_max = 20"
Play whith it for brightness
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Tue Dec 24, 2019 10:53 am    Post subject: Reply with quote

hi EDC

Thank you for sharing and the nice video demos.
Amazing that with relatively little code you can create that snow flake effect. I find it beautiful. Very Happy

The music synchronized color effect is great too, but not for the Xmas tree for me Very Happy
But in a Disco this will be a great effect.

Thanks for sharing the whole year all your great projects!

_________________
Mark
Back to top
View user's profile Visit poster's website
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Tue Dec 24, 2019 11:04 am    Post subject: Reply with quote

I know that this is not for christmas tree but I simply have some spare Rainbowleds tape and AGC music response hardware Very Happy.. and when music is gone the tree will shine with snow effect. This is very interresting when someone "hit" the door Very Happy The tree is responsive ahahahah Very Happy
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Tue Dec 24, 2019 11:23 am    Post subject: Reply with quote

Yes i understood that Very Happy

I was walking in a shop few days ago and there i had some laughs. There was a toy that was sound activated and recorded and played back (with higher pitch) everything.
So i was talking to Sharon and i was not expecting that Very Happy

I also remember a sound activated Christmas toy that started work when you clapped your hands. But it also did when not expecting it : when opening a can/tin for example Wink

_________________
Mark
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum