element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum LED Night project
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 9 replies
  • Subscribers 401 subscribers
  • Views 729 views
  • Users 0 members are here
  • help
  • light
  • needed
  • tm1803
  • led
  • night
  • tri-color
  • arduino
Related

LED Night project

josh_j
josh_j over 12 years ago

Ok so a few months back I posted about this LED night light I'm making for my girlfriend. I decide that instead of getting a bunch of RGB LEDs, I went and bought the Tri-color LED strip instead because it seemed like a idiot proof thing to do. I downloaded the example code for it and it looks great! But here is my trouble, how do I add a dimmer dial to the code?

 

Here is a link to the code.https://github.com/Grid21/_2760339_Program

 

The strip is analog and uses three pins. It plugs into pins GND, VIN and A0 (analog 0) The chip on the strip is a TM1803 chip.

 

I did read over all the .PDF documentation but I still don't understand what I read. If someone here could look at the code, explain to me and then explain how to add a line of code that would use a variable resistor dial to adjust the brightness that would be fantastic! If need be I can also give links to the .PDFs I have on the tri-color LED Strip.

 

Thanks so much for the coming help!
Josh

 

Also could sciguy14 Help me?

Attachments:
image2760339_PM_EN.pdf
imageTM1803.pdf
  • Sign in to reply
  • Cancel
Parents
  • gadget.iom
    gadget.iom over 12 years ago

    OK....

     

    Have had a look into the code, and without any hardware this is difficult to test. But here goes...

     

    add the following code into the 'send_1M_pattern' function just ABOVE the 'send_strip(temp_data)' line.

     

    // Convert Hex to seperate RGB Values

    long r=(long)(temp_data>>16);

    long g=(long)(r>>8);

    long b=(long)temp_data;

     

    // Apply multiplication factor for brightness

    r = (float)r * (a_val/1024.0);

    g = (float)g * (a_val/1024.0);

    b = (float)b * (a_val/1024.0);

     

    // Convert RGB values back to Hex

    long temp_data = ((long)r << 16) | ((long)g << 8 ) | (long)b;

     

     

     

     

     

     

    This code will apply a scaling factor to the output dependent on the value of variable 'a_val' this value should be set through an AnalogueRead on the pin connected to your variable resistor. This AnaglogRead instruction can be added just ABOVE the 'for (i=0;i<pattern_no;i++)' line so that the analogue value is not being polled continuously during the loop.

     

     

    Let me know how you get on.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • gadget.iom
    gadget.iom over 12 years ago

    OK....

     

    Have had a look into the code, and without any hardware this is difficult to test. But here goes...

     

    add the following code into the 'send_1M_pattern' function just ABOVE the 'send_strip(temp_data)' line.

     

    // Convert Hex to seperate RGB Values

    long r=(long)(temp_data>>16);

    long g=(long)(r>>8);

    long b=(long)temp_data;

     

    // Apply multiplication factor for brightness

    r = (float)r * (a_val/1024.0);

    g = (float)g * (a_val/1024.0);

    b = (float)b * (a_val/1024.0);

     

    // Convert RGB values back to Hex

    long temp_data = ((long)r << 16) | ((long)g << 8 ) | (long)b;

     

     

     

     

     

     

    This code will apply a scaling factor to the output dependent on the value of variable 'a_val' this value should be set through an AnalogueRead on the pin connected to your variable resistor. This AnaglogRead instruction can be added just ABOVE the 'for (i=0;i<pattern_no;i++)' line so that the analogue value is not being polled continuously during the loop.

     

     

    Let me know how you get on.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
  • josh_j
    josh_j over 12 years ago in reply to gadget.iom

    Now where do I wire that variable resistor? Also could you explain how do I create a slow fade to the colors? I'm so new at this that I will need help in this coding.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • josh_j
    josh_j over 12 years ago in reply to gadget.iom

      {
        send_1M_pattern(pattern_test_rainbow, 10, 70);
      }
    
    
    
    
      /*
      frame++;
        if(frame<=10) LEDSTRIP_PATTERN_0();
        if(10<frame<=20) LEDSTRIP_PATTERN_0();
        if(20<frame<=30) LEDSTRIP_PATTERN_0();
        if(frame>30) frame=1;
       */
      //delay(1);
    }
    
    
    
    
    /*******************************************************************************
     * Function Name  : send_1M_pattern
     * Description    : Transmit pattern to whole 1 meter strip
     *                  
     * Input          : pointer to ROM pattern; pattern length; frame rate
     *                  
     * Output         : None
     * Return         : None
     *******************************************************************************/
    void send_1M_pattern(const unsigned long data[][10], int pattern_no, int frame_rate)
    
    
    {
      int i=0;
      int j=0;
      uint32_t temp_data;
    
    
      for (i=0;i<pattern_no;i++)
      {
        noInterrupts();
        for (j=0;j<10;j++)
        {
          // Convert Hex to seperate RGB Values
         long r=(long)(temp_data>>16);
         long g=(long)(r>>8);
         long b=(long)temp_data;
    
        // Apply multiplication factor for brightness
        r = (float)r * (a_val/1024.0);
        g = (float)g * (a_val/1024.0);
        b = (float)b * (a_val/1024.0);
    
    // Convert RGB values back to Hex
    long temp_data = ((long)r << 16) | ((long)g << 8 ) | (long)b;
          temp_data=pgm_read_dword_near(&data[i][j]);
          send_strip(temp_data);
        }
        interrupts();
    
    
        delay(frame_rate);
    
    
      }

     

    I wasn't sure where exactly to put it but when I did what you said to do I got this error.

     

    "Tri_Strip_Brightness.ino: In function 'void send_1M_pattern(const long unsigned int (*)[10], int, int)':

    Tri_Strip_Brightness:226: error: 'a_val' was not declared in this scope"

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • gadget.iom
    gadget.iom over 12 years ago in reply to josh_j

    Try moving the line "temp_data=pgm_read_dword_near(&data[i][j]);" above the code I sent you.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube