Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

X simply increments with time as a 16 bit signed value so it wraps. Consider it signed value q15 so range is +/-1. Y is then (1-x^2)^2 which approximates a sine wave for brightness (0 to 1). The accumulator "a" gets this added on, but it's as 12 bit accumulator and the overflow/carry bit goes to the led. The carry is cleared on the following iteration. By the mask just before adding in y again. The rate of overflows determines the brightness.

All in constant execution time too!



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: