12-Kanal-Gummiballlauflicht



Wir benutzen unser Attiny2313-Experimentierboard, um einen Lichteffekt zu erzeugen, der wie ein hüpfender Gummiball aussieht.



// Programm "Gummiball-Lauflicht"
// www.mikrocontrollerspielwiese.de

#include <avr/io.h>

#define F_CPU 8000000UL  	// 8 MHz (fuer delay.h)
#include <util/delay.h>

#include "boarddefs.h" //stellt die Befehle "led x on/off" zur Verfuegung



int main(void){

	DDRB = 255; DDRD = 120;
	
	while (1){
		led1on;  _delay_ms(12); led1off;
		led2on;  _delay_ms(11); led2off;
		led3on;  _delay_ms(10); led3off;
		led4on;  _delay_ms(9); led4off;
		led5on;  _delay_ms(8); led5off;
		led6on;  _delay_ms(7); led6off;
		led7on;  _delay_ms(6); led7off;
		led8on;  _delay_ms(5); led8off;
		led9on;  _delay_ms(4); led9off;
		led10on; _delay_ms(3); led10off;
		led11on; _delay_ms(2); led11off;
		led12on; _delay_ms(1); led12off;
		
		led11on; _delay_ms(1); led11off;
		led10on; _delay_ms(2.22); led10off;
		led9on; _delay_ms(3.44); led9off;
		led8on; _delay_ms(4.66); led8off;
		led7on; _delay_ms(5.88); led7off;
		led6on; _delay_ms(7.11); led6off;
		led5on; _delay_ms(8.33); led5off;
		led4on; _delay_ms(9.55); led4off;
		led3on; _delay_ms(10.77); led3off;
		led2on; _delay_ms(12); led2off;
		
		led3on;  _delay_ms(12); led3off;
		led4on;  _delay_ms(11); led4off;
		led5on;  _delay_ms(10); led5off;
		led6on;  _delay_ms(9); led6off;
		led7on;  _delay_ms(8); led7off;
		led8on;  _delay_ms(7); led8off;
		led9on;  _delay_ms(6); led9off;
		led10on; _delay_ms(5); led10off;
		led11on; _delay_ms(4); led11off;
		led12on; _delay_ms(3); led12off;
		
		led11on; _delay_ms(1); led11off;
		led10on; _delay_ms(2.37); led10off;
		led9on; _delay_ms(3.74); led9off;
		led8on; _delay_ms(5.11); led8off;
		led7on; _delay_ms(6.48); led7off;
		led6on; _delay_ms(7.85); led6off;
		led5on; _delay_ms(9.22); led5off;
		led4on; _delay_ms(11.59); led4off;
		led3on; _delay_ms(12); led3off;
		
		led4on; _delay_ms(12); led4off;
		led5on;  _delay_ms(11); led5off;
		led6on;  _delay_ms(10); led6off;
		led7on;  _delay_ms(9); led7off;
		led8on;  _delay_ms(8); led8off;
		led9on;  _delay_ms(7); led9off;
		led10on; _delay_ms(6); led10off;
		led11on; _delay_ms(5); led11off;
		led12on; _delay_ms(4); led12off;
		
		led11on; _delay_ms(1); led11off;
		led10on; _delay_ms(2.57); led10off;
		led9on; _delay_ms(4.14); led9off;
		led8on; _delay_ms(5.71); led8off;
		led7on; _delay_ms(7.28); led7off;
		led6on; _delay_ms(8.85); led6off;
		led5on; _delay_ms(10.42); led5off;
		led4on; _delay_ms(12); led4off;
	
		led5on;  _delay_ms(12); led5off;
		led6on;  _delay_ms(11); led6off;
		led7on;  _delay_ms(10); led7off;
		led8on;  _delay_ms(9); led8off;
		led9on;  _delay_ms(8); led9off;
		led10on; _delay_ms(7); led10off;
		led11on; _delay_ms(6); led11off;
		led12on; _delay_ms(5); led12off;
		
		
		led11on; _delay_ms(1); led11off;
		led10on; _delay_ms(2.83); led10off;
		led9on; _delay_ms(4.66); led9off;
		led8on; _delay_ms(6.49); led8off;
		led7on; _delay_ms(8.32); led7off;
		led6on; _delay_ms(10.15); led6off;
		led5on; _delay_ms(12); led5off;
		
		led6on;  _delay_ms(12); led6off;
		led7on;  _delay_ms(11); led7off;
		led8on;  _delay_ms(10); led8off;
		led9on;  _delay_ms(9); led9off;
		led10on; _delay_ms(8); led10off;
		led11on; _delay_ms(7); led11off;
		led12on; _delay_ms(6); led12off;
		
		led11on; _delay_ms(1); led11off;
		led10on; _delay_ms(3.2); led10off;
		led9on; _delay_ms(5.4); led9off;
		led8on; _delay_ms(7.6); led8off;
		led7on; _delay_ms(9.8); led7off;
		led6on; _delay_ms(12); led6off;
		
		led7on;  _delay_ms(12); led7off;
		led8on;  _delay_ms(11); led8off;
		led9on;  _delay_ms(10); led9off;
		led10on; _delay_ms(9); led10off;
		led11on; _delay_ms(8); led11off;
		led12on; _delay_ms(7); led12off;
		
		led11on; _delay_ms(1); led11off;
		led10on; _delay_ms(3.75); led10off;
		led9on; _delay_ms(6.5); led9off;
		led8on; _delay_ms(9.25); led8off;
		led7on; _delay_ms(12); led7off;
		
		led8on;  _delay_ms(12); led8off;
		led9on;  _delay_ms(11); led9off;
		led10on; _delay_ms(10); led10off;
		led11on; _delay_ms(9); led11off;
		led12on; _delay_ms(8); led12off;
		
		led11on; _delay_ms(1); led11off;
		led10on; _delay_ms(4.66); led10off;
		led9on; _delay_ms(8.32); led9off;
		led8on; _delay_ms(12); led8off;
		
		led9on;  _delay_ms(12); led9off;
		led10on; _delay_ms(11); led10off;
		led11on; _delay_ms(10); led11off;
		led12on; _delay_ms(9); led12off;
		
		led11on; _delay_ms(1); led11off;
		led10on; _delay_ms(6.5); led10off;
		led9on; _delay_ms(12); led9off;
		
		led10on; _delay_ms(12); led10off;
		led11on; _delay_ms(11); led11off;
		led12on; _delay_ms(10); led12off;
		
		led11on; _delay_ms(1); led11off;
		led10on; _delay_ms(12); led10off;
		
		led11on; _delay_ms(1); led11off;
		
		led12on; _delay_ms(12);led12off;
		
		_delay_ms(255);
		_delay_ms(255);
		_delay_ms(255);
		
	}

return 0;
}

Hier gibt's den Quelltexte-Ordner zum Programmieren.



Anmerkungen:

  • Wenn Du hier irgendwas nicht verstehst, solltest Du Dir unbedingt das Projekt Hello World - Attiny2313  ganz durchlesen.