The main thing here is that the transistors are being used as switches, the setup for this is:
The switches and ground represent pins of the microcontroller.
#include#include #include #define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n)) #define DIT 160 /* unit time for morse code */ #define L(x,y) ((1<<(2+(x))) | (1<<(5+(y)))) int main(void) { // set for 16 MHz clock, and make sure the LED is off CPU_PRESCALE(0); DDRC |= 0xF; PORTC = 0; while (1) { cw(); cw(); cw(); cw(); cw(); fig8(); cw(); cw(); cw(); strip(); strip(); } } #define P(x,y) {PORTC = L(x,y); _delay_ms(DIT);} void cw(void) { P(0,0); P(1,0); P(2,0); P(2,1); P(2,2); P(1,2); P(0,2); P(0,1); } void strip(void) { P(0,0); P(0,1); P(0,2); P(1,0); P(1,1); P(1,2); P(2,0); P(2,1); P(2,2); } void fig8(void) { P(0,0); P(1,0); P(1,1); P(1,2); P(2,2); P(2,1); P(2,0); P(1,0); P(1,1); P(1,2); P(0,2); P(1,2); }
No comments:
Post a Comment