// Travis Rich 10/22/12 // an iteration on top of the following attribution: // // hello.arduino.168.blink.c // // test blinking LED // // Neil Gershenfeld // 3/14/11 // // (c) Massachusetts Institute of Technology 2011 // Permission granted for experimental and personal use; // license for commercial sale available from MIT. // #include #include #define output(directions,pin) (directions |= pin) // set port direction for output #define input(directions,pin) (directions &= (~pin)) // set port direction for input #define set(port,pin) (port |= pin) // set port pin #define clear(port,pin) (port &= (~pin)) // clear port pin #define pin_test(pins,pin) (pins & pin) // test for port pin #define bit_test(byte,bit) (byte & (1 << bit)) // test for bit set #define led_delay() _delay_ms(1000) // LED delay #define led_port PORTA #define led_direction DDRA #define led_pin (1 << PA7) // #define button_port PORTA // #define button_direction DDRA // #define button_pin (1 << PA6) #define input_port PORTB #define input_direction DDRB #define input_pin (1 << PB2) #define input_pins PINB int main(void) { // // main // // set clock divider to /1 // CLKPR = (1 << CLKPCE); CLKPR = (0 << CLKPS3) | (0 << CLKPS2) | (0 << CLKPS1) | (0 << CLKPS0); // // initialize LED pin // clear(led_port, led_pin); output(led_direction, led_pin); clear(input_port, input_pin); // turn on pull-down input(input_direction, input_pin); // // main loop // // while (1) { // set(led_port, led_pin); // led_delay(); // clear(led_port, led_pin); // led_delay(); // } // } while (1) { // // wait for button down // if (0 != pin_test(input_pins,input_pin)){ clear(led_port, led_pin); led_delay(); } set(led_port, led_pin); } }