int main(void) { printf ("Traffic light demo\n"); // Map the I/O sections setup_io(); // Set 12 GPIO pins to output mode setup_gpio(); GPIO_CLR0 = ALL_LEDS; //Turn all LEDs off int i = 1; while(i < 4) //Loop forever { printf("Traffic lights loop %d\n", i); GPIO_SET0 = RED_NORTH | GRN_EAST; // Turn on North red. Turn on East green long_wait(80); // Wait a bit GPIO_CLR0 = ALL_LEDS; // Turn led off GPIO_SET0 = RED_NORTH | YEL_EAST; // Turn on North red. Turn on East yellow long_wait(20); // Wait a short bit GPIO_CLR0 = ALL_LEDS; // Turn led off GPIO_SET0 = RED_NORTH | RED_EAST; long_wait(20); GPIO_CLR0 = ALL_LEDS; GPIO_SET0 = YEL_NORTH | RED_EAST; long_wait(20); GPIO_CLR0 = ALL_LEDS; GPIO_SET0 = GRN_NORTH | RED_EAST; long_wait(80); GPIO_CLR0 = ALL_LEDS; GPIO_SET0 = YEL_NORTH | RED_EAST; long_wait(20); GPIO_CLR0 = ALL_LEDS; GPIO_SET0 = RED_NORTH | RED_EAST; long_wait(20); GPIO_CLR0 = ALL_LEDS; GPIO_SET0 = RED_NORTH | YEL_EAST; long_wait(20); GPIO_CLR0 = ALL_LEDS; i++; } GPIO_CLR0 = ALL_LEDS; //Turn all LEDs off restore_io(); } // main
int main(void) { //int p, r, last; ALL_LEDS = (L1|L2|L3|L4|L5|L6|L7|L8|L9|L10|L11|L12); setup_gpio(); int x = 0; for(;;) { GPIO_SET0 = leds2[x]; long_wait(1); GPIO_SET0 = 0; leds_off(); long_wait(1); x++; if(x == 23) {x =0;} } return 0; } // main
// // Quick play all patterns // int main(void) { int p,r,last; printf ("These are the connections for the LEDs test:\n"); printf ("jumpers in every out location (U3-out-B1, U3-out-B2, etc)\n"); printf ("GP25 in J2 --- B1 in J3\n"); printf ("GP24 in J2 --- B2 in J3\n"); printf ("GP23 in J2 --- B3 in J3\n"); printf ("GP22 in J2 --- B4 in J3\n"); printf ("GP21 in J2 --- B5 in J3\n"); printf ("GP18 in J2 --- B6 in J3\n"); printf ("GP17 in J2 --- B7 in J3\n"); printf ("GP11 in J2 --- B8 in J3\n"); printf ("GP10 in J2 --- B9 in J3\n"); printf ("GP9 in J2 --- B10 in J3\n"); printf ("GP8 in J2 --- B11 in J3\n"); printf ("GP7 in J2 --- B12 in J3\n"); printf ("(If you don't have enough straps and jumpers you can install\n"); printf ("just a few of them, then run again later with the next batch.)\n"); printf ("When ready hit enter.\n"); (void) getchar(); // Map the I/O sections setup_io(); // Set 12 GPIO pins to output mode setup_gpio(); /* for testing purposes... GPIO_SET0 = 0x180; (void) getchar(); GPIO_CLR0 = 0x100; (void) getchar(); */ for (p=0; p<3; p++) { // run pattern several times start_new_pattern(p); for (r=0; r<2; r++) { do { last = led_step(); long_wait(3); } while (!last); } // run the pattern 2 times } // loop over patterns leds_off(); restore_io(); } // main
int main() { sys_init(); flash_fast(16); while(1) { process_button_down(); sleep_cpu(); wdt_reset(); if(!(PIND & 0b01000000) || !run) { // ambient light continue; } PORTD = 0b00100011; _delay_ms(50); if(!(PIND & 0b01000000)) { // reflected light long_wait(); } PORTD = 0b00100000; } return 0; }