Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <TVout.h>
- /* TV Library */
- TVout TV;
- /* Button Pins */
- const int buttonAPin = 11;
- const int buttonBPin = 12;
- const int buttonCPin = 13;
- /* Buttons */
- int buttonA = 0;
- int buttonB = 0;
- int buttonC = 0;
- /* Pieces */
- int pieceX = 0;
- int pieceY = 0;
- /* Counter */
- int counter = 0;
- /* Board */
- 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},
- {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},
- {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},
- {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},
- {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},
- {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},
- {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},
- {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}};
- /* Init */
- void setup() {
- TV.begin(NTSC,120,96);
- Serial.begin(9600);
- pinMode(buttonAPin, INPUT); // A STATUS
- pinMode(buttonBPin, INPUT); // B STATUS
- pinMode(buttonCPin, INPUT); // C STATUS
- }
- void clrPiece(int x, int y) {
- for (int i = 0; i < 5; i++) {
- for (int j = -2; j < 5; j++) {
- TV.set_pixel(x+i,y+j,0);
- }
- }
- }
- void piece(int t, int b, int x, int y) {
- Serial.print("X:");
- Serial.print(x);
- Serial.print('\n');
- Serial.print("Y:");
- Serial.print(y);
- Serial.print('\n');
- TV.set_pixel(x,y,1);
- TV.set_pixel(x+1,y,1);
- TV.set_pixel(x+2,y,1);
- TV.set_pixel(x+3,y,1);
- TV.set_pixel(x+4,y,1);
- TV.set_pixel(x,y+2,1);
- TV.set_pixel(x+1,y+2,1);
- TV.set_pixel(x+2,y+2,1);
- TV.set_pixel(x+3,y+2,1);
- TV.set_pixel(x+4,y+2,1);
- TV.set_pixel(x,y+4,1);
- TV.set_pixel(x+1,y+4,1);
- TV.set_pixel(x+2,y+4,1);
- TV.set_pixel(x+3,y+4,1);
- TV.set_pixel(x+4,y+4,1);
- TV.set_pixel(x,y+1,1);
- TV.set_pixel(x+4,y+1,1);
- TV.set_pixel(x,y+3,1);
- TV.set_pixel(x+4,y+3,1);
- }
- void checkBoard(int pX,int pY) {
- int vLine[5] = {0,0,0,0,0};
- vLine[0] = board[pX][pY-1];
- vLine[1] = board[pX][pY];
- if (pY < 45) {
- vLine[2] = board[pX][pY+1];
- vLine[3] = board[pX][pY+2];
- }
- if (pY < 44) {
- vLine[4] = board[pX][pY+3];
- }
- }
- /* Main */
- void loop() {
- buttonA = digitalRead(buttonAPin);
- buttonB = digitalRead(buttonBPin);
- buttonC = digitalRead(buttonCPin);
- clrPiece(pieceX*5,pieceY*2);
- if (buttonA == HIGH) {
- if (pieceX > 0 && pieceX < 8 && pieceY > 0 && pieceY < 46) {
- if (board[pieceX-1][pieceY] == 0 && board[pieceX][pieceY+1] == 0) {
- pieceX -= 1; // <------ Problem starts here. Comment out for working TV output.
- }
- }
- }
- if (buttonB == HIGH) {
- if (pieceX < 7 && pieceY < 46) {
- // if (board[pieceX+1][pieceY] == 0 && board[pieceX][pieceY+1] == 0) {
- //pieceX += 1;
- // }
- }
- }
- piece(0,0,pieceX*5,pieceY*2);
- counter += 1;
- /*
- if (counter == 5) {
- if (pieceY*2 < 91) {
- if (board[pieceX][pieceY+1] == 0) {
- pieceY += 1;
- } else {
- board[pieceX][pieceY-1] = 1;
- board[pieceX][pieceY] = 1;
- checkBoard(pieceX,pieceY);
- pieceY = 0;
- }
- } else {
- board[pieceX][pieceY-1] = 1;
- board[pieceX][pieceY] = 1;
- checkBoard(pieceX,pieceY);
- pieceY = 0;
- }
- counter = 0;
- }
- */
- delay(100); // Fix frame
- }
Advertisement
Add Comment
Please, Sign In to add comment