Загрузка...

Juno AVR timer/counter simple LED clock -- button Software PWM

Can you understand this line of code? if( (tms%(240/((tsec%15)+1))) ==0 ) { DOT[0]^=0x80; } Well, the 4 dot LEDs on the 7-segment are used to indicate second by means of blinking its 4 dot LEDs at different speed, so if second == 0, it's blinking slowly; and it's blinking fastest at 14 seconds, and the one line of code above does just that for one dot. Coding like this is magical and so fun, and this simple LED clock is designed just for that. More advanced software code can be developed and tested on this board, and it's also designed for beginners to learn to code a MCU. 1, 4*15=60 seconds, so (tsec%15) == to the time mark for each dot with a range from 0-14 (tsec is with a range of 0-59); 2, (240/((tsec%15)+1)), 240 is the frequency for the loop, or exactly 1 second, so this provides a number from (240/1)-(240/15); 3, ( tms % 240 == 0) blinks the LED at 0.5Hz; ( tms % (240/15) == 0) blinks the LED at 8Hz because (240/15)=16/2=8; So the 4 dot leds are blinking from 0.5-8Hz when second is from 0-14, 15-29, 30-44, 45-59; so every second the blinking LED speed is increasing. PS. the blinking LED dots are more smooth in real life.

Видео Juno AVR timer/counter simple LED clock -- button Software PWM автора Технологии в действии
Страницу в закладки Мои закладки
Все заметки Новая заметка Страницу в заметки