Close
0%
0%

MightyLight

The incredible flickering LED!(Okay, it's more about what I learned)

Similar projects worth following
It's a flickering LED that also only turns on when it's relatively dark. Some adjustment may be required depending on your environment as far as turning the flickering LED on/off when it comes to amount of light in the room.

This is one of those projects where the things that I'm learning are more valuable than the end result.




Hardware/software used for this project (read the parts list for a more comprehensive list of hardware):

  • AVR-GCC toolchain
  • My T85 Target board (click here for the project page for the details of the board)
  • a breadboard with a photoresistor, some jumper wires and a resistor

I've used avr-size to determine that my compiled program uses less than 1KB for the HaD 1kB challenge.

Interesting things that I've learned so far:

The internal temperature sensor in the Attiny85 (connected to ADC4) for my purposes makes a better seed source for random number generation than an ADC pin that's unconnected. Another plus to using the internal temperature sensor is that random number generation is unaffected by having my programmer plugged in/not plugged into my development board.

Char can be used in place of int if you only need to deal with numbers <= 255 which helps save on RAM usage.

The rand() function takes up less space than random() which allowed my program to to be within the 1 KB challenge limit, but still takes up quite a bit of flash compared to the rest of my program's code.

t85flicker.c

The program source file.

plain - 1.57 kB - 11/22/2016 at 16:44

Download

makefile

The makefile that I use to automate the compilation and the uploading of the .hex file to my dev board.

makefile - 686.00 bytes - 11/22/2016 at 16:44

Download

t85flicker.hex

The compiled program that is 978 bytes according to avr-size.

hex - 2.71 kB - 11/22/2016 at 16:44

Download

  • 1 × T85 Target board
  • 1 × Photoresistor
  • 1 × Breadboard Electronic Components / Misc. Electronic Components
  • 1 × 10K ohm resistor
  • 3 × jumper wires

View all 6 components

  • A demo of a prototype

    mcu_nerd12/09/2016 at 21:36 0 comments

    Sorry about the delay, I've been busy for these past few weeks with various activities including configuring a new laptop. Anyways I got a chance this afternoon to take a video of it. Sorry about it not exactly being 1080p but I don't own any "newish" camcorders (the one I used was a hand-me-down from a relative.)


  • Planned improvments

    mcu_nerd11/23/2016 at 03:47 0 comments

    Okay, the bright white flickering LED on the dev board doesn't look that impressive. I've been experimenting tonight with different materials to diffuse the light and a yellow LED. It looks similar to a flickering candle. I found that a spare NyQuil-like measuring cap diffuses the light nicely although I want something a bit longer.

    I just tried some wax paper rolled into a cylinder. It doesn't look half-bad but it's a bit flimsy.

    UPDATE: I just added a photo of my experimentation of using wax paper to diffuse the light from a yellow LED.

  • It begins

    mcu_nerd11/22/2016 at 17:44 0 comments

    Okay, I'll admit that right now the flickering LED doesn't look all of interesting. I'm brainstorming ways to make it more interesting. The journey on the other hand is a bit more interesting, and I'll be talking about what I learned in the project details and I'll talk about some of what I learned here.

    Creating the program has been a good refresher as it involves things such as interrupts, ADCs, hysteresis, the watchdog timer, and more.

    I did create something somewhat similar a while back under the Arduino IDE but for this project I went with using the AVR-GCC toolchain directly for a few reasons. The first reason is program size. While the Arduino IDE is very convenient to get things up and running, that conveniencence does come at a price: generally larger compiled program size in comparison to using AVR-GCC. You can make things a bit leaner by doing mostly coding things in the same way that you would under AVR-GCC such as direct port manipulation.

    As I test, I decided to to a comparison of my program size at the time of this writing under both AVR-GCC and and the Arduino IDE. I did have to make a few slight modifications for it to work under the Arduino IDE but here are the end results:

    AVR-GCC compiled size: 978 bytes

    Arduino IDE compiled size: 1190 bytes

    The Arduino IDE compiled program size is about 22% larger vs compiling it under AVR-GCC which isn't too bad but the binary generated by the Arduino IDE would clearly puts me over the HaD 1kB size limit. Now if I started using the things that you typically use under the Arduino IDE such as pinMode() it would have been much worse and I may do a demonstration of this in a later project log.

    Another reason I decided to use AVR-GCC is to gain a deeper understanding of AVR microcontrollers. Under the Arduino IDE I can easily do a lot without reading the datasheet for the Attiny85, but using AVR-GCC makes me rummage though the datasheet which results me in learning some interesting things. I learned about the internal temperature sensor in the Attiny85 when I was reading up on ADC. I also learned that there is much more to PWM than what analogWrite() provides.

    Anyways this project log has gotten pretty long, so I'll end it here.

View all 3 project logs

Enjoy this project?

Share

Discussions

SarahC wrote 12/25/2016 at 04:08 point

Have you looked at a https://en.wikipedia.org/wiki/Linear-feedback_shift_register ?

It takes a tiny amount of code to implement, and gives a good pseudo random result.

http://www.cs.miami.edu/home/burt/learning/Csc609.022/random_numbers.html

.

Here's one  I wrote awhile ago - the bit of interest is right at the end... the lfsr variable.

.

.

  // Move into the pseudo random sequence by 255 numbers.

  // This gets the variable nicely "warmed".

  lfsr = 1; 

  for(; ++ctr < 255 ;)

        lfsr = (lfsr >> 1) ^ (-(lfsr & 1u) & 0xd0000001u); // taps 32 31 29 1

.

.

    //New random number... starts here.

    //Fiddle the bits, then take the left hand few bits for the random number.

    lfsr = (lfsr >> 1) ^ (-(lfsr & 1u) & 0xd0000001u); // taps 32 31 29 1 

.

    //Get two random numbers from the most recent bit twiddling.

    newRandom1 = unsigned char)(lfsr >> 20) & 31 // Take the 20th to 24th bit for the timer. Range: 0-31

    newRandom2 = (unsigned char)(lfsr >> 24) & 255); // and 24th to 29th bit for the brightness. Range: 0-63

  Are you sure? yes | no

mcu_nerd wrote 02/04/2017 at 18:28 point

Thanks for the suggestion! Sorry for the late response, other things got in the way and didn't have time to work on it.  I'll resume work on it sometime.

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates