diff options
Diffstat (limited to 'arduino_sketch')
| -rw-r--r-- | arduino_sketch/arcerino/arcerino.ino | 137 | 
1 files changed, 116 insertions, 21 deletions
diff --git a/arduino_sketch/arcerino/arcerino.ino b/arduino_sketch/arcerino/arcerino.ino index 869f3e4..32af3f9 100644 --- a/arduino_sketch/arcerino/arcerino.ino +++ b/arduino_sketch/arcerino/arcerino.ino @@ -1,15 +1,22 @@  #define PORTC3 0  #define PORTC2 0 -#include "U8glib.h" -  #include <Wire.h>  #include <wiinunchuck.h> +#if 0 +#define LCD +#endif + +#define JOY_MAX 100 + +#ifdef LCD + +#include "U8glib.h" +  U8GLIB_TLS8204_84X48 u8g(15, 16, 13, 4, 5);             // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 4, Reset = 5  #define LCD_MAX 24 -#define JOY_MAX 100  #define LCD_0X 42  #define LCD_0Y 24 @@ -22,6 +29,29 @@ U8GLIB_TLS8204_84X48 u8g(15, 16, 13, 4, 5);             // SPI Com: SCK = 13, MO  #define FONT_SMALL u8g_font_5x7  #define FONT_BIG u8g_font_9x15 +#else /* TV */ + +#include <TVout.h> +#include <fontALL.h> + +TVout TV; + +#define LCD_MAX 48 +#define LCD_0X 60 +#define LCD_0Y 48 + +#define TOP_TEXT_Y 8 +#define MIDDLE_TEXT_Y 48 +#define BOTTOM_TEXT_Y 96 + +#define LOAD_TEXT_X 60 + +#define FONT_SMALL font6x8 +#define FONT_BIG font8x8 + +#endif /* LCD/TV */ + +  char x,y=0;  char drift_x,drift_y=0; @@ -29,6 +59,13 @@ char score=0;  char arrows=10;  bool play=true; +#ifdef LCD + +void output_init() { +    u8g.setColorIndex(1); +    u8g.setContrast(192); +} +  void draw_board() {      u8g.setFont(FONT_SMALL);      u8g.setPrintPos(0,TOP_TEXT_Y); @@ -49,6 +86,7 @@ void draw_game() {          u8g.drawVLine(x+LCD_0X,y-4+LCD_0Y,9);          u8g.drawHLine(x-4+LCD_0X,y+LCD_0Y,9);      } while(u8g.nextPage()); +    delay(100);  }  void draw_score() { @@ -57,6 +95,7 @@ void draw_score() {          draw_board();          u8g.drawDisc(x+LCD_0X,y+LCD_0Y,3);      } while(u8g.nextPage()); +    delay(3000);  }  void draw_title() { @@ -69,6 +108,7 @@ void draw_title() {          u8g.setPrintPos(LOAD_TEXT_X,BOTTOM_TEXT_Y);          u8g.print("Loading...");      } while(u8g.nextPage()); +    delay(4000);  }  void draw_wait() { @@ -97,8 +137,77 @@ void draw_wait() {              u8g.print("E");          }      } while(u8g.nextPage()); +    delay(100); +} + +#else /* TV */ + +void output_init() { +    nunchuk_setpowerpins(); +    TV.begin(PAL,120,96); +} + +void draw_board() { +    TV.select_font(FONT_SMALL); +    TV.print(0,TOP_TEXT_Y,score,DEC); +    TV.print(0,BOTTOM_TEXT_Y,"->"); +    TV.print(arrows,DEC); +    TV.draw_circle(LCD_0X,LCD_0Y,LCD_MAX,WHITE); +    TV.draw_circle(LCD_0X,LCD_0Y,LCD_MAX*2/3,WHITE); +    TV.draw_circle(LCD_0X,LCD_0Y,LCD_MAX/3,WHITE); +    TV.draw_circle(LCD_0X,LCD_0Y,LCD_MAX/6,WHITE); +} + +void draw_game() { +    TV.clear_screen(); +    draw_board(); +    TV.draw_line(x+LCD_0X,y-4+LCD_0Y,x+LCD_0X,y+4+LCD_0Y,WHITE); +    TV.draw_line(x-4+LCD_0X,y+LCD_0Y,x+4+LCD_0X,y+LCD_0Y,WHITE); +    TV.delay(100);  } +void draw_score() { +    TV.clear_screen(); +    draw_board(); +    TV.draw_circle(x+LCD_0X,y+LCD_0Y,6,WHITE,WHITE); +    TV.delay(3000); +} + +void draw_title() { +    TV.clear_screen(); +    TV.select_font(FONT_BIG); +    TV.print(0,MIDDLE_TEXT_Y,"Arcerino..."); +    TV.select_font(FONT_SMALL); +    TV.print(LOAD_TEXT_X,BOTTOM_TEXT_Y,"Loading..."); +    TV.delay(4000); +} + +void draw_wait() { +    TV.clear_screen(); +    TV.select_font(FONT_SMALL); +    TV.print(0,TOP_TEXT_Y,"Your score: "); +    TV.print(0,TOP_TEXT_Y+13,score,DEC); +    TV.print(0,BOTTOM_TEXT_Y,"Press Z to start"); +    TV.print(0,MIDDLE_TEXT_Y,"Rank: "); +    TV.select_font(FONT_BIG); +        if (score >= 100) { +            TV.print("A++"); +        } else if (score >= 90) { +            TV.print("A"); +        } else if (score >= 80) { +            TV.print("B"); +        } else if (score >= 60) { +            TV.print("C"); +        } else if (score >= 30) { +            TV.print("D"); +        } else { +            TV.print("E"); +        } +    TV.delay(100); +} + +#endif /* LCD/TV */ +  void update_position() {      drift_x = drift_x + random(-1,2);      drift_x = constrain(drift_x,-LCD_MAX,LCD_MAX); @@ -142,12 +251,10 @@ void new_round() {  }  void setup() { +    output_init();      nunchuk_init(); -    u8g.setColorIndex(1); -    u8g.setContrast(192);      nunchuk_get_data();      draw_title(); -    delay(4000);      new_arrow();      new_round();  } @@ -159,21 +266,13 @@ void loop() {          if (nunchuk_zbutton()) {              score = score + get_score();               new_arrow(); -            u8g.firstPage(); -            do { -                draw_score(); -            } while(u8g.nextPage()); -            delay(3000); +            draw_score();              if ( arrows <= 0 ) {                  play = false;              }          } else {              update_position(); -            u8g.firstPage(); -            do { -                draw_game(); -            } while(u8g.nextPage()); -            delay(100); +            draw_game();          }      } else {          if (nunchuk_zbutton()) { @@ -181,11 +280,7 @@ void loop() {              play=true;              delay(200);          } else { -            u8g.firstPage(); -            do { -                draw_wait(); -            } while(u8g.nextPage()); -            delay(100); +            draw_wait();          }      }  }  | 
