{"id":342,"date":"2007-10-13T15:22:31","date_gmt":"2007-10-13T14:22:31","guid":{"rendered":"http:\/\/www.evertdekker.com\/wp\/?p=342"},"modified":"2023-01-11T21:09:01","modified_gmt":"2023-01-11T20:09:01","slug":"rgb-dimmer-fading","status":"publish","type":"post","link":"https:\/\/evertdekker.com\/wp\/?p=342","title":{"rendered":"Rgb dimmer fading"},"content":{"rendered":"<hr \/>\n<p>Rgb dimmers are most of the time dimming according figure 1. It&#8217;s simple code, just increase al the colors 1 step a time,\u00a0 but the disadvange is that blue is ready first and red the last and that looks not that realistic. It would be neater when all 3 colors will start and finishing together as seen in figure 2.<br \/>\nThis code will fade all colors together.<br \/>\nTimer3 is used to controle the 3 pwm channels.<br \/>\nTimer0 is the delay for the steps. It&#8217;s with this xtal and preload an delay of 20ms. If you are going to use a other crystal then you need recalculate the timer0 preload.<\/p>\n<div class=\"n2_ss_slider_publish__option_code\" dir=\"ltr\" data-mode=\"id\"><\/div>\n<p>&nbsp;<\/p>\n<h4>Syntax<\/h4>\n<p><span style=\"color: #3366ff;\">Fade<\/span> Red,Green,Blue,Steps<\/p>\n<h4>Remarks<\/h4>\n<table class=\"alignleft\" style=\"border-color: #000000;\" border=\"2\" cellspacing=\"2\" cellpadding=\"2\">\n<tbody>\n<tr>\n<td>\u00a0Red<\/td>\n<td>\u00a0Constant or variable with new RED value.<\/td>\n<\/tr>\n<tr>\n<td>\u00a0Green<\/td>\n<td>\u00a0Constant or variable with new GREEN value.<\/td>\n<\/tr>\n<tr>\n<td>\u00a0Blue<\/td>\n<td>\u00a0Constant or variable with new BLUE value.<\/td>\n<\/tr>\n<tr>\n<td>\u00a0Steps<\/td>\n<td>\u00a0Number of steps to fade between old and new value<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/evertdekker.com\/Joomla\/images\/stories\/CodeVault\/RgbDimmer\/Rgbdimmer.zip\">Dowload the code here\u00a0<\/a><\/p>\n<p>See the code below in action;<br \/>\n<div class=\"lyte-wrapper\" title=\"RGB dimmer fade\" style=\"width:420px;max-width: 100%;margin:5px;\"><div class=\"lyMe hidef\" id=\"WYL_RKG2kObqazw\" itemprop=\"video\" itemscope itemtype=\"https:\/\/schema.org\/VideoObject\"><div><meta itemprop=\"thumbnailUrl\" content=\"https:\/\/i.ytimg.com\/vi\/RKG2kObqazw\/hqdefault.jpg\" \/><meta itemprop=\"embedURL\" content=\"https:\/\/www.youtube.com\/embed\/RKG2kObqazw\" \/><meta itemprop=\"uploadDate\" content=\"2007-08-10T20:15:21.000Z\" \/><\/div><div id=\"lyte_RKG2kObqazw\" data-src=\"https:\/\/i.ytimg.com\/vi\/RKG2kObqazw\/hqdefault.jpg\" class=\"pL\"><div class=\"tC\"><div class=\"tT\" itemprop=\"name\">RGB dimmer fade<\/div><\/div><div class=\"play\"><\/div><div class=\"ctrl\"><div class=\"Lctrl\"><\/div><div class=\"Rctrl\"><\/div><\/div><\/div><noscript><a href=\"https:\/\/youtu.be\/RKG2kObqazw\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i.ytimg.com\/vi\/RKG2kObqazw\/0.jpg\" alt=\"\" width=\"420\" height=\"216\" \/><br \/>Watch this video on YouTube<\/a><\/noscript><meta itemprop=\"description\" content=\"Bascom RGB dimmer fade demo. For more details; http:\/\/www.mcselec.com\/index2.php?option=com_forum&amp;Itemid=59&amp;page=viewtopic&amp;t=4581\"><\/div><\/div><div class=\"lL\" style=\"max-width:100%;width:420px;margin:5px;\"><\/div><\/p>\n<p>&nbsp;<\/p>\n<pre class=\"brush: vb; gutter: true\">$regfile = &quot;m128def.DAT&quot;\r\n$crystal = 7372800\r\n$baud = 19200\r\n\r\n\r\nConfig Timer3 = Pwm , Prescale = 64 , Pwm = 8 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down , Compare C Pwm = Clear Down\r\nConfig Timer0 = Timer , Prescale = 1024\r\n\r\nOn Ovf0 Rgbint\r\nEnable Timer3\r\nEnable Ovf0\r\nEnable Interrupts\r\nStart Timer3\r\nTimer0 = &amp;H70\r\nStop Timer0\r\n\r\n\r\nDeclare Sub Fade(byval Newrood As Byte , Byval Newgroen As Byte , Byval Newblauw As Byte , Byval Stappen As Byte)\r\nDim Staprood As Single\r\nDim Stapgroen As Single\r\nDim Stapblauw As Single\r\nDim Roodw As Single\r\nDim Blauww As Single\r\nDim Groenw As Single\r\nDim Stappen As Byte\r\nDim Temps As Single\r\nDim Tempint As Integer\r\nDim Stap2 As Byte\r\n\r\nRood Alias Compare3a\r\nBlauw Alias Compare3b\r\nGroen Alias Compare3c\r\n\r\nRood = 0\r\nBlauw = 0\r\nGroen = 0\r\n\r\n\r\nDo\r\nFade 25 , 25 , 25 , 10\r\nWait 2\r\nFade 255 , 0 , 0 , 50\r\nWait 2\r\nFade 0 , 255 , 0 , 50\r\nWait 2\r\nFade 0 , 0 , 255 , 50\r\nWait 2\r\nFade 150 , 150 , 75 , 50\r\nWait 2\r\nFade 0 , 0 , 0 , 10\r\nWait 2\r\nFade 225 , 225 , 225 , 100\r\nWait 2\r\nLoop\r\n\r\n\r\n\r\n\r\nSub Fade(newrood As Byte , Newgroen As Byte , Newblauw As Byte , Stappen As Byte )\r\nStap2 = Stappen\r\nRoodw = Rood : Groenw = Groen : Blauww = Blauw\r\nTemps = Newrood - Rood\r\nStaprood = Temps \/ Stappen\r\nTemps = Newgroen - Groen\r\nStapgroen = Temps \/ Stappen\r\nTemps = Newblauw - Blauw\r\nStapblauw = Temps \/ Stappen\r\nStart Timer0\r\nEnd Sub\r\n\r\n\r\nRgbint:\r\nRoodw = Roodw + Staprood\r\nGroenw = Groenw + Stapgroen\r\nBlauww = Blauww + Stapblauw\r\nTempint = Round(roodw)\r\nRood = Tempint\r\nTempint = Round(blauww)\r\nBlauw = Tempint\r\nTempint = Round(groenw)\r\nGroen = Tempint\r\nDecr Stap2\r\nIf Stap2 = 0 Then\r\n Stop Timer0\r\nEnd If\r\nTimer0 = &amp;H70\r\nReturn<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Rgb dimmers are most of the time dimming according figure 1. It&#8217;s simple code, just increase al the colors 1 step a time,\u00a0 but the disadvange is that blue is ready first and red the last and that looks not that realistic. It would be neater when all 3 colors will start and finishing together [&#8230;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[26,42],"class_list":["post-342","post","type-post","status-publish","format-standard","hentry","category-bascom","tag-bascom","tag-rgb-dimmer"],"_links":{"self":[{"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/342","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=342"}],"version-history":[{"count":16,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/342\/revisions"}],"predecessor-version":[{"id":2126,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/342\/revisions\/2126"}],"wp:attachment":[{"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=342"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=342"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=342"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}