Friday 11 October 2019

Knight Rider, con ATTiny atmel

con ATTiny,  SIN programador, Sin Complicaciones, usa bateria tipo boton CR


codigo:



/**************************************************************************
darus67
20 October 2007
**************************************************************************/

#include // this contains all the IO port definitions
#define FADE_RATE 20 // the larger this value, the slower
// the LED will fade
#define INITIAL_WIDTH 128 // the starting value of the PWM pulse
// this is about 50% pulse width

void fade(char bit){
/**************************************************************************
Use pulse width modulation to cause LEDs on Port B to fade out
LEDs corresponding to high bits in 'bit' will fade out
**************************************************************************/
unsigned char rate = FADE_RATE;
unsigned char pulse_width = INITIAL_WIDTH;
unsigned char count;

while(pulse_width){ // as long as pulse_width is non-zero
// loop through the PWM routine

PORTB |= bit; // turn on the LED

for(count=0; count<<=1){ // Instead of incrementing, b gets shifted left. // When the 1 bit shifts off the left side // b == 0 and the loop terminates PORTB = b; // turn on the LED fade(b>>1); // call fade to fade out the LED to the right of
// the currently lit one
}

// scan from left to right, with the trailing LED fading out
for(b=0x40; b; b>>=1){ // We're shifting b right instead of left this time

PORTB = b; // turn on the LED

fade(b<<1);>
**************************************************************************

No comments:

Post a Comment