Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7756595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:51:50+00:00 2026-06-01T12:51:50+00:00

I’ve been playing with LEDs a lot recently, powered by 8-bit micro controllers. Sometimes

  • 0

I’ve been playing with LEDs a lot recently, powered by 8-bit micro controllers. Sometimes it’s necessary to use purely software implementations of Pulse Width Modulation to control LED brightness – that is turning the light on and off rapidly varying the ratio of time on and off. This works great until I get down to about 5% brightness, where the strobing starts looking uncomfortably flickery to the eye.

Implementing the PWM as a loop, it steps through each number from 0-255 setting the light on or off for that moment. A light which is set at the 20 value will be on for the first 20 loops then turned off.

I’m looking for a good function which will shuffle around those numbers, so instead of looping through 0, 1, 2, 3… my loop could sample semi-randomly from the pool of possibilities. The aggregate brightness over time is the same, but a light at 20 brightness value may switch on and off a dozen or so times spread across 256 loops instead of just lighting once then turning off for most of the loop. This reduces the flickering effect even if the loop runs slightly slower.

A good dithering function would need to return every number in the 8-bit range when called with every 8-bit number. It would therefore also need to produce no duplicate numbers – not random, just shuffled. It’s best if it tends not to put similar numbers together in sequence – the difference between each number aught to be high – ideally about 64-127 I figure.

The limitations are also interesting – it’s a time critical application. Addition, subtraction, and bitwise operations cost 1 arbitrary unit of time, multiplication costs 2 units, and division costs 4 units. Floats are out of the questions, and the costs roughly double for every multiple of 8 bits used in an intermediate number. Lookup tables are possible, but would use roughly half of the total memory capacity of the device – so fast algorithms are best for reusability, but good quality slow algorithms are also very useful when there’s space to precompute.

Thanks for helping me out with any ideas or musings. 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:51:51+00:00Added an answer on June 1, 2026 at 12:51 pm

    Not 100% sure I understand correctly, but basically I think that any numbers that doesn’t divide 256 will generate the group of numbers 0..255 if you just keep adding it to itself modulo 256. Some flashbacks from the abstract algebra class…

    like this:

    s = {}
    
    n = 157
    for i in range(0, 256):
       s[n] = True
       print n
       n += 157
       n %= 256
    
    print "check: has to be 256: ", len(s) 
    

    EDIT: replaced small generator with a larger one to make the distribution more “random”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.