void main() { unsigned char x, y, xdir, ydir; unsigned int i; // === Initialize system ================================================ IFG1=0; /* clear interrupt flag1 */ WDTCTL=WDTPW+WDTHOLD; /* stop WD */ init(); initNokia(); clearDisplay(); x=4; y=4; ydir=1; xdir=1; drawBlock(y,x); while(1) { if (ydir ==1){ y++; if(y>=8) ydir=0; } if (ydir==0){ y--; if(y<=0) ydir=1; } if (xdir ==1){ x++; if (x>=11) xdir = 0; } if(xdir==0){ x--; if(x<=0) xdir =1; } clearDisplay(); drawBlock(y,x); for(i=0; i<10; i++){ moveDelay(); } } }
void main() { unsigned char x, y, color, button_press; // === Initialize system ================================================ IFG1=0; /* clear interrupt flag1 */ WDTCTL=WDTPW+WDTHOLD; /* stop WD */ button_press = FALSE; init(); initNokia(); clearDisplay(); color = WHITE; x=4; y=4; drawBlock(y,x,color); while(1) { if (UP_BUTTON == 0) { while(UP_BUTTON == 0); if (y>=1) y=y-1; button_press = TRUE; } else if (DOWN_BUTTON == 0) { while(DOWN_BUTTON == 0); if (y<=6) y=y+1; button_press = TRUE; } else if (LEFT_BUTTON == 0) { while(LEFT_BUTTON == 0); if (x>=1) x=x-1; button_press = TRUE; } else if (RIGHT_BUTTON == 0) { while(RIGHT_BUTTON == 0); if (x<=10) x=x+1; button_press = TRUE; } else if (AUX_BUTTON == 0) { while(AUX_BUTTON == 0); if (color == BLACK) color = WHITE; else if (color == WHITE) color = BLACK; button_press = TRUE; } if (button_press) { button_press = FALSE; //clearDisplay(); drawBlock(y,x,color); } } }
void main() { unsigned char x, y, button_press, color; // Define new variable color // === Initialize system ================================================ IFG1=0; /* clear interrupt flag1 */ WDTCTL=WDTPW+WDTHOLD; /* stop WD */ button_press = FALSE; init(); initNokia(); clearDisplay(); x=4; y=4; color=2; // Initialized new variable color to 2 (BLACK) drawBlock(y,x,color); // New call with color variable while(1) { if (UP_BUTTON == 0) { while(UP_BUTTON == 0); if (y>=1) y=y-1; button_press = TRUE; } else if (DOWN_BUTTON == 0) { while(DOWN_BUTTON == 0); if (y<=6) y=y+1; button_press = TRUE; } else if (LEFT_BUTTON == 0) { while(LEFT_BUTTON == 0); if (x>=1) x=x-1; button_press = TRUE; } else if (RIGHT_BUTTON == 0) { while(RIGHT_BUTTON == 0); if (x<=10) x=x+1; button_press = TRUE; } else if (AUX_BUTTON == 0) { // Syntax similar to other buttons while(AUX_BUTTON == 0); if (color == BLACK) color = WHITE; // If BLACK, change to WHITE else if (color == WHITE) color = BLACK; // Else if WHITE, change to BLACK button_press = TRUE; } if (button_press) { button_press = FALSE; //clearDisplay(); // Commented out to leave block drawings behind drawBlock(y,x,color); // New call again } } }
void main() { unsigned char x, y, xVel, yVel; // === Initialize system ================================================ IFG1=0; /* clear interrupt flag1 */ WDTCTL=WDTPW+WDTHOLD; /* stop WD */ init(); initNokia(); clearDisplay(); x=4; y=4; xVel=1; yVel=1; drawBlock(y,x); while(1) { // Vel = 1 going right/down // Vel = 0 going left/up if (xVel == 1) { x++; if (x>=11) xVel=0; } if (xVel == 0) { x--; if (x<=0) xVel=1; } if (yVel == 1) { y++; if (y>=7) yVel=0; } if (yVel == 0) { y--; if (y<=0) yVel=1; } clearDisplay(); drawBlock(y,x); delayDraw(); } }
void main() { byte pattern[GHOST_WD] = {GHOST}; // Initialize the happy face pattern in memory ballStruct ball; //Initalize all the ball parameters ball.position.x = 5; ball.position.y = 5; ball.velocity.x = -1; ball.velocity.y = -1; ball.pattern = pattern; ball.width = GHOST_WD; ballStruct *ballPtr = &ball; // === Initialize system ================================================ IFG1=0; /* clear interrupt flag1 */ WDTCTL=WDTPW+WDTHOLD; /* stop WD */ init(); initNokia(); initInterrupt(); clearDisplay(); drawBall(ballPtr); while(1) { if(!(TACTL & (BIT5|BIT4))) // The program uses the Memory Control register to check if there is an inturrupt, an inturrupt has occured with the clock has stopped { clearDisplay(); moveBall(ballPtr); drawBall(ballPtr); TACTL |= MC_1; // Reset the Memory Control register to count up mode and resume (this process is fairly nice as it slows down the refresh speed) } } }
// ----------------------------------------------------------------------- // Main: Initializes the MSP430 and checks input for a known code // ----------------------------------------------------------------------- void main(void) { init(); initNokia(); initMSP430(); // Setup MSP to process IR and buttons clearDisplay(); x=1; y=1; color= BLACK; drawBlock(y,x);//, color); while(1) { if (newIrPacket) { //Got a new packet! _disable_interrupt(); newIrPacket = FALSE; packetIndex = 0; if(IS_BUTTON_ONE){ P1OUT ^= BIT0; //Alternate the Red LED } else if(IS_BUTTON_TWO){ P1OUT ^= BIT6; //Alternate the Green LED } //Check if color is changed by middle button else if(packetBits == BIG_MIDDLE){ color = (color+1)%2; } //Check if up button is pressed else if (packetBits == BIG_UP) { if (y>=1) y=y-1; drawBlock(y,x,color); } //Check if down button is pressed else if (packetBits == BIG_DOWN) { if (y<=6) y=y+1; drawBlock(y,x,color); } //Check if left button is pressed else if (packetBits == BIG_LEFT) { if (x>=1) x=x-1; drawBlock(y,x,color); } //Check if right button is pressed else if (packetBits == BIG_RIGHT) { if (x<=10) x=x+1; drawBlock(y,x,color); } initMSP430(); _enable_interrupt(); } // end if new IR packet arrived } // end infinite loop } // end main
void main() { int ballColumn, ballRow, paddleColumn, paddleRow; ball_t myBall, paddle; myBall = createBall(1,5,1,-1,1); ballColumn = getX(myBall); ballRow = getY(myBall); paddle = createBall(1,5,0,0,1); paddleColumn = getX(paddle); paddleRow = getY(paddle); // === Initialize system ================================================ IFG1=0; /* clear interrupt flag1 */ WDTCTL=WDTPW+WDTHOLD; /* stop WD */ init(); initNokia(); clearDisplay(); drawBall(ballRow,ballColumn); while(1) { if (ballColumn == 0){ //Hit the left side clearDisplay(); while(AUX_BUTTON){ // Keeps the screen cleared until the aux button is pressed } myBall = createBall(1,5,1,-1,1); } if (UP_BUTTON == 0) { //while(UP_BUTTON == 0); paddleRow--; paddle.position.y = paddleRow; } else if (DOWN_BUTTON == 0) { //while(DOWN_BUTTON == 0); paddleRow++; paddle.position.y = paddleRow; } // } else if (LEFT_BUTTON == 0) { // while(LEFT_BUTTON == 0); // if (x>=1) x=x-1; // button_press = TRUE; // } else if (RIGHT_BUTTON == 0) { // while(RIGHT_BUTTON == 0); // if (x<=10) x=x+1; // button_press = TRUE; // } else if (AUX_BUTTON == 0) { // while(AUX_BUTTON == 0); // color ^= 1; // toggles the block color flag // } myBall = moveBall(myBall); ballColumn = getX(myBall); ballRow = getY(myBall); paddleColumn = getX(paddle); paddleRow = getY(paddle); drawBall(ballRow,ballColumn); drawBlock(paddleRow,paddleColumn,0); Sleep(100); clearDisplay(); Sleep(20); if(hitBall(myBall,paddle)){ myBall.velocity.x *= -1; } } }
void main() { unsigned char x, y, button_press; signed char xVel, yVel; unsigned long timeWaster,timeWaster2; unsigned char paddleRow; unsigned char playGame; // === Initialize system ================================================ IFG1=0; /* clear interrupt flag1 */ WDTCTL=WDTPW+WDTHOLD; /* stop WD */ button_press = FALSE; //sets up the screen init(); initNokia(); clearDisplay(); //initializes the position of the block x=1; y=1; //initializes the velocity of the block xVel = 1; yVel = 1; //wastes time to make the block move slower. timeWaster = 0; timeWaster2 = 0; //intializes the location of the paddle. paddleRow = 4; //sets the color to be black initialy :) to omoimasu drawBlock(y,x); //first we need to draw the paddle. drawPaddle(paddleRow,PADDLECOL); playGame = 1; while(playGame) { //delays the code to make the ball move slower. for(timeWaster = 0; timeWaster<350; timeWaster++){ for(timeWaster2 = 0; timeWaster2<350; timeWaster2++){ //want to give the user a chance to hit the button before the block is moved. //therefore, check this every time you run through the for loop!!!! //might have to alter how long the loop delays for after this. } } //check if the up or down buttons have been hit!! if (UP_BUTTON == 0) { for(timeWaster = 0; timeWaster<60;timeWaster++){ } if (paddleRow>=1) paddleRow = paddleRow-1; button_press = TRUE; } else if (DOWN_BUTTON == 0) { for(timeWaster = 0; timeWaster<60;timeWaster++){ } if (paddleRow<=6) paddleRow=paddleRow+1; button_press = TRUE; } //check if too far left if(y<=0||y>=HEIGHT){ yVel *= -1; } //check if in bounds in x direction if(x<=0){ xVel *= -1; } //did it hit the paddle? if(x>=LENGTH&&y==paddleRow){ xVel *= -1; }else if (x==LENGTH){ //if it hit the right wall instead. //make the game end!!! playGame = 0; } //moves it!!! x +=xVel; y +=yVel; //resets screen with new location of block clearDisplay(); drawBlock(y,x); drawPaddle(paddleRow,PADDLECOL); } while(1){ clearDisplay(); } }
void main() { unsigned short cnt, cnt2; int8 paddle, inputDelay, button_press; SignedInt8Pair position, velocity, temp; // === Initialize system ================================================ IFG1=0; /* clear interrupt flag1 */ WDTCTL=WDTPW+WDTHOLD; /* stop WD */ button_press = FALSE; init(); initNokia(); position.x=X_INIT; position.y=Y_INIT; velocity.x=DX_INIT; velocity.y=DY_INIT; paddle=PADDLE_INIT; inputDelay=0; while(TRUE) { clearDisplay(); drawCircle(position.y,position.x); //draw ball cnt = 0; for(;cnt<=PADDLE_SIZE;cnt++) drawBlock(paddle+cnt,0); //draw paddle //figure out the new position and velocity of x direction temp = move1d(position.x, velocity.x, X_UPPER_BOUND); position.x = temp.x; velocity.x = temp.y; ////figure out the new position and velocity of y direction temp = move1d(position.y, velocity.y, Y_UPPER_BOUND); position.y = temp.x; velocity.y = temp.y; //when ball hits left row, check collision if (position.x<=0) { if (position.y < paddle || position.y > paddle + PADDLE_SIZE){ //game over, taunt player clearDisplay(); drawBlock(1,4); drawBlock(2,4); drawBlock(3,4); drawBlock(4,4); drawBlock(4,5); drawBlock(4,6); while (TRUE); } else { //collision, rebound ball velocity.x = -velocity.x; } } cnt=0; for(;cnt<1000;cnt++){ cnt2=0; for(;cnt2<95;cnt2++); if (button_press==FALSE){ if (UP_BUTTON == 0 && paddle > 0){ paddle--; button_press=TRUE; } else if (DOWN_BUTTON == 0 && (paddle+PADDLE_SIZE) < Y_UPPER_BOUND){ paddle++; button_press=TRUE; } } } if (button_press==TRUE){ if (inputDelay >= 2 ){ inputDelay=0; button_press=FALSE; } else { inputDelay++; } } } }
/* * main.c */ void main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer unsigned char black, notBlack, button_press, y; // === Initialize system ================================================ IFG1=0; /* clear interrupt flag1 */ WDTCTL=WDTPW+WDTHOLD; /* stop WD */ button_press = FALSE; black = TRUE; notBlack = FALSE; init(); initNokia(); clearDisplay(0,0,notBlack); vector2d pos = {2,2}; vector2d vel = {1,1}; unsigned char rad = 2; y=1; ball myBall; myBall.position = pos; myBall.velocity = vel; myBall.radius = rad; while(1){ if (UP_BUTTON == 0) { while(UP_BUTTON == 0); if (y>=1) y=y-1; button_press = TRUE; } else if (DOWN_BUTTON == 0) { while(DOWN_BUTTON == 0); if (y<=6) y=y+1; button_press = TRUE; } else if(AUX_BUTTON == 0){ while(AUX_BUTTON == 0); black = !black; notBlack = !black; clearDisplay(0,0,notBlack); drawBlock(myBall.position.y, myBall.position.x, black); drawPaddle(y,0,black); } if (button_press) { button_press = FALSE; //clearDisplay(); drawBlock(myBall.position.y, myBall.position.x, black); drawPaddle(y,0,black); } moveBall(&myBall,y); clearDisplay(0,0,notBlack); drawBlock(myBall.position.y, myBall.position.x, black); drawPaddle(y,0,black); _delay_cycles(5333333); } }
void main(void) { //This sets up the block position unsigned char x, y, c; IFG1=0; // clear interrupt flag1 WDTCTL=WDTPW+WDTHOLD; // stop WD BCSCTL1 = CALBC1_8MHZ; //set up clock DCOCTL = CALDCO_8MHZ; init(); initNokia(); initMSP430(); clearDisplay(); drawBlock(y,x,c); x = 6; y = 4; c=0xFF; initMSP430(); while(1){ // Determine value of IrPacket if(packetIndex == 34){ // if one full signal is recieved, then the loop will iterate _disable_interrupt(); int32 IrPacket = 0; int32 setBit = 0xF0000000; char i; for(i = 2; i<34; i++){ int16 current = packetData[i]; // This is the current element if(current/10 < 100){ IrPacket &= ~setBit; } else { IrPacket |= setBit; } setBit >>= 1; } packetIndex++; // This just makes sure that the loop is not entered into again. initNokia(); // Handle the button presses if (IrPacket == ZERO) { //This is the process in which we pick the "color" of the block if(c == 0xFF){ c = 0; } else if (c == 0){ c = 0xFF; } } if (IrPacket == VOL_UP) { //These just check for button presses in a particular direction. if (y>=1) y=y-1; } else if (IrPacket == VOL_DW) { if (y<=6) y=y+1; } else if (IrPacket == ONE) { if (x>=1) x=x-1; } else if (IrPacket == TWO) { if (x<=10) x=x+1; } drawBlock(y, x, c); //draws the block initMSP430(); //Now we look for another IR input. } }