int main(void) { setup_mcu(); keyboard_setup(); setup_usb(); sei(); /* init modules */ serial_init(); keyboard_init(); host_set_driver(&lufa_driver); #ifdef SLEEP_LED_ENABLE sleep_led_init(); #endif print("Keyboard start.\n"); while (1) { while (USB_DeviceState == DEVICE_STATE_Suspended) { print("[s]"); matrix_power_down(); suspend_power_down(); if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) { USB_Device_SendRemoteWakeup(); } } keyboard_task(); #if !defined(INTERRUPT_CONTROL_ENDPOINT) USB_USBTask(); #endif } }
int main() { seed_rand(); setup_mcu(); led_driver_init(); pwm_timer_init(); pir_init(); // the PIR sensor takes a few seconds _delay_ms(5000); sei(); uint8_t lower_pwm= 1; uint8_t upper_pwm= 70; uint8_t base_delay_interval= 10; while(1) { while( !(PIND && PD2) ); uint8_t pins[4]= { PB1, PB2, PB3, PB4 }; uint8_t pin_starts[4]; uint8_t pin_pwm[4]; uint16_t delay_count= 0; uint8_t still_fading= 1; for( uint8_t i= 0; i < 4; ++i ) { // number of base_delay_interval intervals to wait before lighting them up pin_starts[i]= range_rand(50); pin_pwm[i]= lower_pwm; } // fade them up delay_count= 0; still_fading= 1; while( still_fading ) { still_fading= 0; for( uint8_t i= 0; i < 4; ++i ) { if( delay_count >= pin_starts[i] && pin_pwm[i] < upper_pwm ) { pin_pwm[i]++; start_pwm( pins[i], pin_pwm[i] ); } if( pin_pwm[i] < upper_pwm ) still_fading= 1; } _delay_ms( base_delay_interval ); delay_count++; } // wait for no more motion for 5 seconds delay_count= 0; while( delay_count < (5000/base_delay_interval) ) { if( PIND && PD2 ) { delay_count= 0; continue; } _delay_ms( base_delay_interval ); delay_count++; } // fade them off for( uint8_t i= 0; i < 4; ++i ) { // number of base_delay_interval intervals to wait before shutting them down pin_starts[i]= range_rand(60); pin_pwm[i]= upper_pwm; } delay_count= 0; still_fading= 1; while( still_fading ) { still_fading= 0; for( uint8_t i= 0; i < 4; ++i ) { if( delay_count >= pin_starts[i] ) { if( pin_pwm[i] > lower_pwm ) { pin_pwm[i]--; start_pwm( pins[i], pin_pwm[i] ); } if( pin_pwm[i] <= lower_pwm ) stop_pwm( pins[i] ); } if( pin_pwm[i] > lower_pwm ) still_fading= 1; } _delay_ms( base_delay_interval ); delay_count++; } _delay_ms(2000); } return 0; }