int exampleMain() { WDTCTL = WDTPW|WDTHOLD; configureP1PinAsButton(BIT1|BIT2|BIT3); // configure pins 1, 2, and 3 as buttons P1DIR |= BIT0|BIT6; // set launchpad LEDs to output while (1) { char buttons[] = {BIT1, BIT2, BIT3}; char pressedButton = pollP1Buttons(buttons, 3); switch (pressedButton) { case BIT1: // do something in response break; case BIT2: // do something in response break; case BIT3: // toggle LEDs and wait for release P1OUT ^= BIT0|BIT6; waitForP1ButtonRelease(BIT3); break; } } return 0; }
int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer initSPI(); LCDinit(); LCDclear(); unsigned char player = initPlayer(); init_timer(); init_buttons(); __enable_interrupt(); printPlayer(player); while(1) { player = movementCheck(player); if(LOSE == 1){ LCDclear(); print("GAME"); secondLine(); print("OVER"); firstLine(); GAMEOVER = 1; waitForP1ButtonRelease(BIT1|BIT2|BIT3|BIT4); debounce(); } if(didPlayerWin(player)){ LCDclear(); print("YOU"); secondLine(); print("WON"); firstLine(); GAMEOVER = 1; waitForP1ButtonRelease(BIT1|BIT2|BIT3|BIT4); debounce(); } if(GAMEOVER){ char buttonsToPoll[4] = {BIT1, BIT2, BIT3, BIT4}; while(!pollP1Buttons(buttonsToPoll, 4)){ //poll until something is pressed } TAR = 0; LOSE = 0; TIMER = 0; GAMEOVER = 0; LCDclear(); player = initPlayer(); printPlayer(player); } } return 0; }
/*Author: Travis Schriner * Date 21 Oct 2013 * Description: This program interacts with the * LCD in the geekbox and allows me to write to it * */ int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer initSPI(); LCDinit(); LCDclear(); char *topMessage = "ECE382 is my Favorite Class!"; char *prompt = "Message?"; char *promptKey = "Press123"; char *message1 = "This is message 1 fool!"; char *message2 = "This is message 2 fool!"; char *message3 = "This is message 3 fool!"; cursorToLineOne(); writeString(prompt); cursorToLineTwo(); writeString(promptKey); configureP1PinAsButton(BIT1|BIT2|BIT3); // configure pins 1, 2, and 3 as buttons P1DIR |= BIT0|BIT6; // set launchpad LEDs to output char buttons[] = {BIT1, BIT2, BIT3}; char pressedButton = pollP1Buttons(buttons, 3); switch (pressedButton) { case BIT1: waitForP1ButtonRelease(BIT1); scrollString(topMessage, message1); break; case BIT2: waitForP1ButtonRelease(BIT2); scrollString(topMessage, message2); break; case BIT3: waitForP1ButtonRelease(BIT3); scrollString(topMessage, message3); break; } while(1){ } }
/*Author C2C Rasmussen * Date Oct 28 13 * * Implements the program * main.c */ int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer //stores strings in an arrays (idea from C2C Mordan) char string1[] = {'E','C','E',' ','3', '8', '2',' ','i','s',' ','m','y',' ','f','a','v','o','r','i','t','e',' ','c','l','a','s','s','!',' ',' '}; char message[] = {'P','R','E','S','S',' ','K','E','Y',' ',' '}; // 11 in length char message1[] = {'w','a','z','z','u','p'}; // 6 in length char message2[] = {'h','o','w',' ','d','o',' ','y','o','u', ' ','d','o','?',' ',' '}; // 16 in length char message3[] = {'f','a','l','c','o','n',' ','p','u','n','c','h',' ',' '}; // 14 in length initSPI(); LCDinit(); LCDclear(); while(1){ cursorToLineOne(); createString(message, 11); scrollLCD(message, 11); configureP1PinAsButton(BIT1|BIT2|BIT3); // configure pins 1, 2, and 3 as buttons P1DIR |= BIT0|BIT6; // set launchpad LEDs to output while (1) { char buttons[] = {BIT1, BIT2, BIT3}; char pressedButton = pollP1Buttons(buttons, 3); switch (pressedButton) { case BIT1: // detects if Bit1 is enabled P1OUT ^= BIT0|BIT6; waitForP1ButtonRelease(BIT1); while(1){ cursorToLineOne(); //passes new message createString(string1, 31); cursorToLineTwo(); createString(message1, 6 ); scrollLCD(string1, 31); scrollLCD(message1, 6); } // do something in response break; case BIT2: P1OUT ^= BIT0|BIT6; waitForP1ButtonRelease(BIT2); // do something in response while(1){ cursorToLineOne(); createString(string1, 31); cursorToLineTwo(); createString(message2, 16 ); scrollLCD(string1, 31); scrollLCD(message2, 16); } break; case BIT3: // toggle LEDs and wait for release P1OUT ^= BIT0|BIT6; waitForP1ButtonRelease(BIT3); while(1){ cursorToLineOne(); createString(string1, 31); cursorToLineTwo(); createString(message3, 14 ); scrollLCD(string1, 31); scrollLCD(message3, 14); } break; } } } }