Valentin learns how to make:
--> a final idea ;-)
--> a Press-fit Construction Kit a rocked!
--> a USB - Microchipprogrammer
--> something big
--> a mold
--> a game based on a button and two leds
--> something that dose not fit in the printer, it got printed with
--> something for the refrigerator with sensors
--> The Earthquake-Pen!
--> Frequenz-Modulation for the Earthquake-Pen!
--> Update final project
--> something that feels the distance
--> The Earthquake-Pen DELUX 2000
------------------------------------------------------------------------------------------------------------------------------
Since attiny44A is the new arduino,
I wanted to test my new hardware development environment on a good old game concept.
It is called:
"I show you a pattern and you have to repeat it."
If you repeat it right, I show you a next pattern that is slightly more complicated.
Beside the class bord-design and code-examples, my example is build up on improvements by Jennifer Jakobs.
Here is the Video:
And here is the code:
// Valentin Heun // 10/30/11 // // Jenifer Jakobs // 10/27/11 // // Neil Gershenfeld // 12/8/10 // // (c) Massachusetts Institute of Technology 2010 // Permission granted for experimental and personal use; // license for commercial sale available from MIT. // #include#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 pin_test(pins,pin) (pins & pin) // test for port pin //#define read(port,pin) (port &= (~pin)) // read port pin #define clear(port,pin) (port &= (~pin)) // clear port pin #define led_delay() _delay_ms(700) // LED delay #define led_long() _delay_ms(700) // LED delay #define led_short() _delay_ms(300) // LED delay #define led_long2() _delay_ms(350) // LED delay #define led_short2() _delay_ms(150) // LED delay #define led_ultra() _delay_ms(80) // LED delay #define led_port PORTA #define led_direction DDRA #define led_pin1 (1 << PA7) #define led_pin2 (1 << PA3) #define button_port PORTB #define button_direction DDRB #define button_pins PINB #define button_pin (1 << PB2) int main(void) { // // main // // // set clock divider to /1 // CLKPR = (1 << CLKPCE); CLKPR = (0 << CLKPS3) | (0 << CLKPS2) | (0 << CLKPS1) | (0 << CLKPS0); // main loop // static int on; on = 0; clear(led_port, led_pin1); clear(led_port, led_pin2); output(led_direction, led_pin1); output(led_direction, led_pin2); set(button_port, button_pin); static int setup1 =0; static int levels =0; static int x1 =0; int steps[levels]; static int over = 0; set(led_port, led_pin2); led_long(); clear(led_port, led_pin2); led_delay(); while (1) { if (!pin_test(button_pins, button_pin)) { setup1 = 1; }else { setup1 = 0; } if (setup1 == 1) { on = 1; for (x1=0; x1<= levels; x1++) { steps[x1] = rand() %2; } setup1 =0; led_delay(); } if (on == 1){ // start blining for (x1=0; x1<= levels; x1++) { if (steps[x1]==0) { set(led_port, led_pin2); led_short(); clear(led_port, led_pin2); led_delay(); } if (steps[x1]==1) { set(led_port, led_pin2); led_long(); clear(led_port, led_pin2); led_delay(); } on = 0; } // start reading set(led_port, led_pin2); led_ultra(); clear(led_port, led_pin2); led_ultra(); set(led_port, led_pin2); led_ultra(); clear(led_port, led_pin2); led_delay(); for (x1=0; x1<= levels; x1++) { if (steps[x1]==0) { set(led_port, led_pin2); //breaking to game over led_short2(); if (pin_test(button_pins, button_pin)) { over =1; } led_short2(); clear(led_port, led_pin2); led_long2(); if (!pin_test(button_pins, button_pin)) { over =1; } led_long2(); } if (steps[x1]==1) { set(led_port, led_pin2); //breaking to game over led_long2(); if (pin_test(button_pins, button_pin)) { over =1; } led_long2(); clear(led_port, led_pin2); led_long2(); if (!pin_test(button_pins, button_pin)) { over =1; } led_long2(); } on = 0; } if (over == 1) { levels = 0; static int setup1 =0; static int levels =0; static int x1 =0; over == 0; set(led_port, led_pin1); led_long(); led_long(); led_long(); clear(led_port, led_pin1); } else { levels++; set(led_port, led_pin1); led_ultra(); clear(led_port, led_pin1); led_ultra(); set(led_port, led_pin1); led_ultra(); clear(led_port, led_pin1); } } } } text
------------------------------------------------------------------------------------------------------------------------------