Guest User

crashy

a guest
May 13th, 2013
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. #include <TVout.h>
  2.  
  3. /* TV Library */
  4. TVout TV;
  5.  
  6. /* Button Pins */
  7. const int buttonAPin = 11;
  8. const int buttonBPin = 12;
  9. const int buttonCPin = 13;
  10.  
  11. /* Buttons */
  12. int buttonA = 0;
  13. int buttonB = 0;
  14. int buttonC = 0;
  15.  
  16. /* Pieces */
  17. int pieceX = 0;
  18. int pieceY = 0;
  19.  
  20. /* Counter */
  21. int counter = 0;
  22.  
  23. /* Board */
  24. int board[8][47] = {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  25. {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  26. {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  27. {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  28. {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  29. {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  30. {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  31. {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
  32.  
  33. /* Init */
  34. void setup() {
  35. TV.begin(NTSC,120,96);
  36. Serial.begin(9600);
  37.  
  38. pinMode(buttonAPin, INPUT); // A STATUS
  39. pinMode(buttonBPin, INPUT); // B STATUS
  40. pinMode(buttonCPin, INPUT); // C STATUS
  41. }
  42.  
  43. void clrPiece(int x, int y) {
  44. for (int i = 0; i < 5; i++) {
  45. for (int j = -2; j < 5; j++) {
  46. TV.set_pixel(x+i,y+j,0);
  47. }
  48. }
  49. }
  50.  
  51. void piece(int t, int b, int x, int y) {
  52. Serial.print("X:");
  53. Serial.print(x);
  54. Serial.print('\n');
  55.  
  56. Serial.print("Y:");
  57. Serial.print(y);
  58. Serial.print('\n');
  59.  
  60. TV.set_pixel(x,y,1);
  61. TV.set_pixel(x+1,y,1);
  62. TV.set_pixel(x+2,y,1);
  63. TV.set_pixel(x+3,y,1);
  64. TV.set_pixel(x+4,y,1);
  65.  
  66. TV.set_pixel(x,y+2,1);
  67. TV.set_pixel(x+1,y+2,1);
  68. TV.set_pixel(x+2,y+2,1);
  69. TV.set_pixel(x+3,y+2,1);
  70. TV.set_pixel(x+4,y+2,1);
  71.  
  72. TV.set_pixel(x,y+4,1);
  73. TV.set_pixel(x+1,y+4,1);
  74. TV.set_pixel(x+2,y+4,1);
  75. TV.set_pixel(x+3,y+4,1);
  76. TV.set_pixel(x+4,y+4,1);
  77.  
  78. TV.set_pixel(x,y+1,1);
  79. TV.set_pixel(x+4,y+1,1);
  80.  
  81. TV.set_pixel(x,y+3,1);
  82. TV.set_pixel(x+4,y+3,1);
  83. }
  84.  
  85. void checkBoard(int pX,int pY) {
  86. int vLine[5] = {0,0,0,0,0};
  87.  
  88. vLine[0] = board[pX][pY-1];
  89. vLine[1] = board[pX][pY];
  90.  
  91. if (pY < 45) {
  92. vLine[2] = board[pX][pY+1];
  93. vLine[3] = board[pX][pY+2];
  94. }
  95.  
  96. if (pY < 44) {
  97. vLine[4] = board[pX][pY+3];
  98. }
  99. }
  100.  
  101. /* Main */
  102. void loop() {
  103. buttonA = digitalRead(buttonAPin);
  104. buttonB = digitalRead(buttonBPin);
  105. buttonC = digitalRead(buttonCPin);
  106.  
  107. clrPiece(pieceX*5,pieceY*2);
  108.  
  109. if (buttonA == HIGH) {
  110. if (pieceX > 0 && pieceX < 8 && pieceY > 0 && pieceY < 46) {
  111. if (board[pieceX-1][pieceY] == 0 && board[pieceX][pieceY+1] == 0) {
  112. pieceX -= 1; // <------ Problem starts here. Comment out for working TV output.
  113. }
  114. }
  115. }
  116.  
  117. if (buttonB == HIGH) {
  118. if (pieceX < 7 && pieceY < 46) {
  119. // if (board[pieceX+1][pieceY] == 0 && board[pieceX][pieceY+1] == 0) {
  120. //pieceX += 1;
  121. // }
  122. }
  123. }
  124.  
  125. piece(0,0,pieceX*5,pieceY*2);
  126.  
  127. counter += 1;
  128.  
  129. /*
  130. if (counter == 5) {
  131. if (pieceY*2 < 91) {
  132. if (board[pieceX][pieceY+1] == 0) {
  133. pieceY += 1;
  134. } else {
  135. board[pieceX][pieceY-1] = 1;
  136. board[pieceX][pieceY] = 1;
  137.  
  138. checkBoard(pieceX,pieceY);
  139. pieceY = 0;
  140. }
  141.  
  142. } else {
  143. board[pieceX][pieceY-1] = 1;
  144. board[pieceX][pieceY] = 1;
  145.  
  146. checkBoard(pieceX,pieceY);
  147. pieceY = 0;
  148. }
  149.  
  150. counter = 0;
  151. }
  152. */
  153.  
  154. delay(100); // Fix frame
  155. }
Advertisement
Add Comment
Please, Sign In to add comment