#include <msp430.h>
#include <stdlib.h>
#include "SSD1306.h"
#include "i2c.h"
#include <stdbool.h>
#define BUTTON 0x1F
#define BUTTON0 BIT0
#define BUTTON1 BIT1
#define BUTTON2 BIT2
#define BUTTON3 BIT3
#define BUTTON4 BIT4
#define BUTTON_CONFIRM BIT4
#define LED BIT5
volatile unsigned int indexRow0 = 0;
volatile unsigned int indexRow1 = 0;
volatile unsigned int indexRow2 = 0;
volatile unsigned int indexRow3 = 0;
volatile unsigned int indexRow4 = 0;
volatile bool switch0 = 0;
volatile bool switch1 = 0;
volatile bool switch2 = 0;
volatile bool switch3 = 0;
volatile bool switch4 = 0;
volatile bool keyFlag0 = 0;
volatile bool keyFlag1 = 0;
volatile bool keyFlag3 = 0;
volatile bool keyDefuse = 0;
volatile unsigned int seconds_elapsed = 0;
const char totalArray[35][6][5] = {
{{'A', 'J', 'G', 'P', 'A'}, {'U', 'B', 'X', 'A', 'I'}, {'G', 'I', 'O', 'W', 'T'}, {'M', 'N', 'Q', 'U', 'H'}, {'P', 'R', 'W', 'H', 'T'}, {'V', 'U', 'O', 'H', 'B'}},
{{'A', 'J', 'G', 'P', 'A'}, {'U', 'F', 'X', 'A', 'I'}, {'G', 'I', 'T', 'W', 'T'}, {'M', 'N', 'Q', 'E', 'H'}, {'P', 'R', 'W', 'H', 'R'}, {'V', 'U', 'O', 'H', 'B'}},
{{'A', 'J', 'G', 'P', 'A'}, {'U', 'G', 'X', 'A', 'I'}, {'G', 'I', 'A', 'W', 'T'}, {'M', 'N', 'Q', 'I', 'H'}, {'P', 'R', 'W', 'H', 'N'}, {'V', 'U', 'O', 'H', 'B'}},
{{'B', 'J', 'G', 'P', 'A'}, {'U', 'E', 'X', 'A', 'I'}, {'G', 'I', 'L', 'W', 'T'}, {'M', 'N', 'Q', 'O', 'H'}, {'P', 'R', 'W', 'W', 'U'}, {'V', 'U', 'O', 'H', 'B'}},
{{'C', 'J', 'G', 'P', 'A'}, {'U', 'O', 'X', 'A', 'I'}, {'G', 'I', 'U', 'W', 'T'}, {'M', 'N', 'Q', 'L', 'H'}, {'P', 'R', 'W', 'H', 'D'}, {'V', 'U', 'O', 'H', 'B'}},
{{'R', 'J', 'G', 'P', 'Y'}, {'U', 'W', 'X', 'R', 'I'}, {'G', 'I', 'E', 'W', 'T'}, {'M', 'V', 'Q', 'X', 'H'}, {'E', 'R', 'W', 'H', 'U'}, {'V', 'U', 'O', 'H', 'B'}},
{{'R', 'J', 'G', 'P', 'T'}, {'U', 'W', 'X', 'S', 'I'}, {'G', 'I', 'R', 'W', 'T'}, {'M', 'I', 'Q', 'X', 'H'}, {'F', 'R', 'W', 'H', 'U'}, {'V', 'U', 'O', 'H', 'B'}},
{{'R', 'J', 'G', 'P', 'D'}, {'U', 'W', 'X', 'N', 'I'}, {'G', 'I', 'U', 'W', 'T'}, {'M', 'O', 'Q', 'X', 'H'}, {'F', 'R', 'W', 'H', 'U'}, {'V', 'U', 'O', 'H', 'B'}},
{{'R', 'J', 'G', 'P', 'T'}, {'U', 'W', 'X', 'A', 'I'}, {'G', 'I', 'E', 'W', 'T'}, {'M', 'R', 'Q', 'X', 'H'}, {'G', 'R', 'W', 'H', 'U'}, {'V', 'U', 'O', 'H', 'B'}},
{{'R', 'J', 'G', 'P', 'E'}, {'U', 'W', 'X', 'S', 'I'}, {'G', 'I', 'U', 'W', 'T'}, {'M', 'O', 'Q', 'X', 'H'}, {'H', 'R', 'W', 'H', 'U'}, {'V', 'U', 'O', 'H', 'B'}},
{{'R', 'J', 'G', 'P', 'A'}, {'U', 'W', 'X', 'A', 'E'}, {'G', 'I', 'R', 'G', 'T'}, {'M', 'N', 'R', 'X', 'H'}, {'P', 'A', 'W', 'H', 'U'}, {'L', 'U', 'O', 'H', 'B'}},
{{'R', 'J', 'G', 'P', 'A'}, {'U', 'W', 'X', 'A', 'N'}, {'G', 'I', 'R', 'R', 'T'}, {'M', 'N', 'A', 'X', 'H'}, {'P', 'E', 'W', 'H', 'U'}, {'L', 'U', 'O', 'H', 'B'}},
{{'R', 'J', 'G', 'P', 'A'}, {'U', 'W', 'X', 'A', 'R'}, {'G', 'I', 'R', 'E', 'T'}, {'M', 'N', 'V', 'X', 'H'}, {'P', 'E', 'W', 'H', 'U'}, {'N', 'U', 'O', 'H', 'B'}},
{{'R', 'J', 'G', 'P', 'A'}, {'U', 'W', 'X', 'A', 'R'}, {'G', 'I', 'R', 'E', 'T'}, {'M', 'N', 'H', 'X', 'H'}, {'P', 'T', 'W', 'H', 'U'}, {'O', 'U', 'O', 'H', 'B'}},
{{'R', 'J', 'G', 'P', 'A'}, {'U', 'W', 'X', 'A', 'E'}, {'G', 'I', 'R', 'C', 'T'}, {'M', 'N', 'A', 'X', 'H'}, {'F', 'L', 'W', 'H', 'U'}, {'P', 'U', 'O', 'H', 'B'}},
{{'P', 'J', 'G', 'P', 'A'}, {'U', 'L', 'X', 'A', 'I'}, {'G', 'I', 'A', 'W', 'T'}, {'M', 'N', 'Q', 'N', 'H'}, {'P', 'R', 'W', 'H', 'T'}, {'V', 'U', 'O', 'H', 'B'}},
{{'P', 'J', 'G', 'P', 'A'}, {'U', 'O', 'X', 'A', 'I'}, {'G', 'I', 'I', 'W', 'T'}, {'M', 'N', 'Q', 'N', 'H'}, {'P', 'R', 'W', 'H', 'T'}, {'V', 'U', 'O', 'H', 'B'}},
{{'R', 'J', 'G', 'P', 'A'}, {'U', 'W', 'X', 'A', 'I'}, {'G', 'I', 'R', 'W', 'T'}, {'M', 'N', 'Q', 'X', 'H'}, {'P', 'R', 'W', 'H', 'U'}, {'V', 'U', 'O', 'H', 'B'}},
{{'S', 'J', 'G', 'P', 'A'}, {'U', 'M', 'X', 'A', 'I'}, {'G', 'I', 'A', 'W', 'T'}, {'M', 'N', 'Q', 'L', 'H'}, {'P', 'R', 'W', 'H', 'L'}, {'V', 'U', 'O', 'H', 'B'}},
{{'S', 'J', 'G', 'P', 'A'}, {'U', 'O', 'X', 'A', 'I'}, {'G', 'I', 'U', 'W', 'T'}, {'M', 'N', 'Q', 'N', 'H'}, {'P', 'R', 'W', 'H', 'D'}, {'V', 'U', 'O', 'H', 'B'}},
{{'R', 'J', 'G', 'P', 'L'}, {'U', 'W', 'X', 'L', 'I'}, {'G', 'I', 'E', 'W', 'T'}, {'M', 'P', 'Q', 'X', 'H'}, {'S', 'R', 'W', 'H', 'U'}, {'V', 'U', 'O', 'H', 'B'}},
{{'R', 'J', 'G', 'P', 'L'}, {'U', 'W', 'X', 'L', 'I'}, {'G', 'I', 'I', 'W', 'T'}, {'M', 'T', 'Q', 'X', 'H'}, {'S', 'R', 'W', 'H', 'U'}, {'V', 'U', 'O', 'H', 'B'}},
{{'R', 'J', 'G', 'P', 'Y'}, {'U', 'W', 'X', 'D', 'I'}, {'G', 'I', 'U', 'W', 'T'}, {'M', 'T', 'Q', 'X', 'H'}, {'S', 'R', 'W', 'H', 'U'}, {'V', 'U', 'O', 'H', 'B'}},
{{'R', 'J', 'G', 'P', 'R'}, {'U', 'W', 'X', 'I', 'I'}, {'G', 'I', 'E', 'W', 'T'}, {'M', 'H', 'Q', 'X', 'H'}, {'T', 'R', 'W', 'H', 'U'}, {'V', 'U', 'O', 'H', 'B'}},
{{'R', 'J', 'G', 'P', 'E'}, {'U', 'W', 'X', 'R', 'I'}, {'G', 'I', 'E', 'W', 'T'}, {'M', 'H', 'Q', 'X', 'H'}, {'T', 'R', 'W', 'H', 'U'}, {'V', 'U', 'O', 'H', 'B'}},
{{'R', 'J', 'G', 'P', 'A'}, {'U', 'W', 'X', 'A', 'E'}, {'G', 'I', 'R', 'S', 'T'}, {'M', 'N', 'E', 'X', 'H'}, {'P', 'H', 'W', 'H', 'U'}, {'T', 'U', 'O', 'H', 'B'}},
{{'R', 'J', 'G', 'P', 'A'}, {'U', 'W', 'X', 'A', 'G'}, {'G', 'I', 'R', 'N', 'T'}, {'M', 'N', 'I', 'X', 'H'}, {'P', 'H', 'W', 'H', 'U'}, {'T', 'U', 'O', 'H', 'B'}},
{{'R', 'J', 'G', 'P', 'A'}, {'U', 'W', 'X', 'A', 'K'}, {'G', 'I', 'R', 'N', 'T'}, {'M', 'N', 'I', 'X', 'H'}, {'P', 'H', 'W', 'H', 'U'}, {'T', 'U', 'O', 'H', 'B'}},
{{'R', 'J', 'G', 'P', 'A'}, {'U', 'W', 'X', 'A', 'E'}, {'G', 'I', 'R', 'E', 'T'}, {'M', 'N', 'R', 'X', 'H'}, {'P', 'H', 'W', 'H', 'U'}, {'T', 'U', 'O', 'H', 'B'}},
{{'R', 'J', 'G', 'P', 'A'}, {'U', 'W', 'X', 'R', 'I'}, {'G', 'I', 'R', 'E', 'T'}, {'M', 'N', 'T', 'X', 'H'}, {'P', 'A', 'W', 'H', 'U'}, {'W', 'U', 'O', 'H', 'B'}},
{{'W', 'J', 'G', 'P', 'A'}, {'U', 'H', 'X', 'A', 'I'}, {'G', 'I', 'E', 'W', 'T'}, {'M', 'N', 'Q', 'R', 'H'}, {'P', 'R', 'W', 'H', 'E'}, {'V', 'U', 'O', 'H', 'B'}},
{{'W', 'J', 'G', 'P', 'A'}, {'U', 'H', 'X', 'A', 'I'}, {'G', 'I', 'I', 'W', 'T'}, {'M', 'N', 'Q', 'C', 'Z'}, {'P', 'R', 'W', 'H', 'H'}, {'V', 'U', 'O', 'H', 'B'}},
{{'W', 'J', 'G', 'P', 'A'}, {'U', 'O', 'X', 'A', 'I'}, {'G', 'I', 'R', 'W', 'T'}, {'M', 'N', 'Q', 'L', 'H'}, {'P', 'R', 'W', 'H', 'D'}, {'V', 'U', 'O', 'H', 'B'}},
{{'W', 'J', 'G', 'P', 'A'}, {'U', 'O', 'X', 'A', 'I'}, {'G', 'I', 'U', 'W', 'T'}, {'M', 'N', 'Q', 'L', 'H'}, {'P', 'R', 'W', 'H', 'D'}, {'V', 'U', 'O', 'H', 'B'}},
{{'W', 'J', 'G', 'P', 'A'}, {'U', 'R', 'X', 'A', 'I'}, {'G', 'I', 'I', 'W', 'T'}, {'M', 'N', 'Q', 'T', 'H'}, {'P', 'R', 'W', 'H', 'E'}, {'V', 'U', 'O', 'H', 'B'}}
};
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
i2c_init(); // initialize I2C to use with OLED
ssd1306_init(); // Initialize SSD1306 OLED
ssd1306_clearDisplay(); // Clear OLED display
P2DIR |= LED;
P1REN |= BUTTON;
P1OUT |= BUTTON; // enable P1.3 pull-UP resistor
P1IE |= BUTTON; // P1.3 interrupt enabled
P1IES |= BUTTON; // P1.3 interrupt triggered on high-to-low transition
P1IFG &= ~BUTTON; // P1.3 IFG cleared
P2REN |= BUTTON;
P2OUT |= BUTTON; // enable P1.3 pull-UP resistor
P2IE |= BUTTON; // P1.3 interrupt enabled
P2IES |= BUTTON; // P1.3 interrupt triggered on high-to-low transition
P2IFG &= ~BUTTON; // P1.3 IFG cleared
TACCR0 = 30000; // Set the TimerA0 CC0 delay
TACTL = TASSEL_2 + MC_2; // Set the timer A to SMCLCK, Continuous
__enable_interrupt(); // enable all interrupts
bool passwordSolved = 1;
char tempCString[2];
srand(time(0));
unsigned int randPass = rand() % 34;
while (passwordSolved)
{
tempCString[0] = totalArray[randPass][indexRow0][0];
tempCString[1] = '\0';
ssd1306_printText(35, 3, tempCString); // print message
tempCString[0] = totalArray[randPass][indexRow1][1];
ssd1306_printText(45, 3, tempCString); // print message
tempCString[0] = totalArray[randPass][indexRow2][2];
ssd1306_printText(55, 3, tempCString); // print message
tempCString[0] = totalArray[randPass][indexRow3][3];
ssd1306_printText(65, 3, tempCString); // print message
tempCString[0] = totalArray[randPass][indexRow4][4];
ssd1306_printText(75, 3, tempCString); // print message
if (((totalArray[randPass][indexRow0][0] == 'A')
&& (totalArray[randPass][indexRow1][1] == 'B')
&& (totalArray[randPass][indexRow2][2] == 'O')
&& (totalArray[randPass][indexRow3][3] == 'U')
&& (totalArray[randPass][indexRow4][4] == 'T'))
|| ((totalArray[randPass][indexRow0][0] == 'A')
&& (totalArray[randPass][indexRow1][1] == 'F')
&& (totalArray[randPass][indexRow2][2] == 'T')
&& (totalArray[randPass][indexRow3][3] == 'E')
&& (totalArray[randPass][indexRow4][4] == 'R'))
|| ((totalArray[randPass][indexRow0][0] == 'A')
&& (totalArray[randPass][indexRow1][1] == 'G')
&& (totalArray[randPass][indexRow2][2] == 'A')
&& (totalArray[randPass][indexRow3][3] == 'I')
&& (totalArray[randPass][indexRow4][4] == 'N'))
|| ((totalArray[randPass][indexRow0][0] == 'B')
&& (totalArray[randPass][indexRow1][1] == 'E')
&& (totalArray[randPass][indexRow2][2] == 'L')
&& (totalArray[randPass][indexRow3][3] == 'O')
&& (totalArray[randPass][indexRow4][4] == 'W'))
|| ((totalArray[randPass][indexRow0][0] == 'C')
&& (totalArray[randPass][indexRow1][1] == 'O')
&& (totalArray[randPass][indexRow2][2] == 'U')
&& (totalArray[randPass][indexRow3][3] == 'L')
&& (totalArray[randPass][indexRow4][4] == 'D'))
|| ((totalArray[randPass][indexRow0][0] == 'E')
&& (totalArray[randPass][indexRow1][1] == 'V')
&& (totalArray[randPass][indexRow2][2] == 'E')
&& (totalArray[randPass][indexRow3][3] == 'R')
&& (totalArray[randPass][indexRow4][4] == 'Y'))
|| ((totalArray[randPass][indexRow0][0] == 'F')
&& (totalArray[randPass][indexRow1][1] == 'I')
&& (totalArray[randPass][indexRow2][2] == 'R')
&& (totalArray[randPass][indexRow3][3] == 'S')
&& (totalArray[randPass][indexRow4][4] == 'T'))
|| ((totalArray[randPass][indexRow0][0] == 'F')
&& (totalArray[randPass][indexRow1][1] == 'O')
&& (totalArray[randPass][indexRow2][2] == 'U')
&& (totalArray[randPass][indexRow3][3] == 'N')
&& (totalArray[randPass][indexRow4][4] == 'D'))
|| ((totalArray[randPass][indexRow0][0] == 'G')
&& (totalArray[randPass][indexRow1][1] == 'R')
&& (totalArray[randPass][indexRow2][2] == 'E')
&& (totalArray[randPass][indexRow3][3] == 'A')
&& (totalArray[randPass][indexRow4][4] == 'T'))
|| ((totalArray[randPass][indexRow0][0] == 'H')
&& (totalArray[randPass][indexRow1][1] == 'O')
&& (totalArray[randPass][indexRow2][2] == 'U')
&& (totalArray[randPass][indexRow3][3] == 'S')
&& (totalArray[randPass][indexRow4][4] == 'E'))
|| ((totalArray[randPass][indexRow0][0] == 'L')
&& (totalArray[randPass][indexRow1][1] == 'A')
&& (totalArray[randPass][indexRow2][2] == 'R')
&& (totalArray[randPass][indexRow3][3] == 'G')
&& (totalArray[randPass][indexRow4][4] == 'E'))
|| ((totalArray[randPass][indexRow0][0] == 'L')
&& (totalArray[randPass][indexRow1][1] == 'E')
&& (totalArray[randPass][indexRow2][2] == 'A')
&& (totalArray[randPass][indexRow3][3] == 'R')
&& (totalArray[randPass][indexRow4][4] == 'N'))
|| ((totalArray[randPass][indexRow0][0] == 'N')
&& (totalArray[randPass][indexRow1][1] == 'E')
&& (totalArray[randPass][indexRow2][2] == 'V')
&& (totalArray[randPass][indexRow3][3] == 'E')
&& (totalArray[randPass][indexRow4][4] == 'R'))
|| ((totalArray[randPass][indexRow0][0] == 'O')
&& (totalArray[randPass][indexRow1][1] == 'T')
&& (totalArray[randPass][indexRow2][2] == 'H')
&& (totalArray[randPass][indexRow3][3] == 'E')
&& (totalArray[randPass][indexRow4][4] == 'R'))
|| ((totalArray[randPass][indexRow0][0] == 'P')
&& (totalArray[randPass][indexRow1][1] == 'L')
&& (totalArray[randPass][indexRow2][2] == 'A')
&& (totalArray[randPass][indexRow3][3] == 'C')
&& (totalArray[randPass][indexRow4][4] == 'E'))
|| ((totalArray[randPass][indexRow0][0] == 'P')
&& (totalArray[randPass][indexRow1][1] == 'L')
&& (totalArray[randPass][indexRow2][2] == 'A')
&& (totalArray[randPass][indexRow3][3] == 'N')
&& (totalArray[randPass][indexRow4][4] == 'T'))
|| ((totalArray[randPass][indexRow0][0] == 'P')
&& (totalArray[randPass][indexRow1][1] == 'O')
&& (totalArray[randPass][indexRow2][2] == 'I')
&& (totalArray[randPass][indexRow3][3] == 'N')
&& (totalArray[randPass][indexRow4][4] == 'T'))
|| ((totalArray[randPass][indexRow0][0] == 'R')
&& (totalArray[randPass][indexRow1][1] == 'I')
&& (totalArray[randPass][indexRow2][2] == 'G')
&& (totalArray[randPass][indexRow3][3] == 'H')
&& (totalArray[randPass][indexRow4][4] == 'T'))
|| ((totalArray[randPass][indexRow0][0] == 'S')
&& (totalArray[randPass][indexRow1][1] == 'M')
&& (totalArray[randPass][indexRow2][2] == 'A')
&& (totalArray[randPass][indexRow3][3] == 'L')
&& (totalArray[randPass][indexRow4][4] == 'L'))
|| ((totalArray[randPass][indexRow0][0] == 'S')
&& (totalArray[randPass][indexRow1][1] == 'O')
&& (totalArray[randPass][indexRow2][2] == 'U')
&& (totalArray[randPass][indexRow3][3] == 'N')
&& (totalArray[randPass][indexRow4][4] == 'D'))
|| ((totalArray[randPass][indexRow0][0] == 'S')
&& (totalArray[randPass][indexRow1][1] == 'P')
&& (totalArray[randPass][indexRow2][2] == 'E')
&& (totalArray[randPass][indexRow3][3] == 'L')
&& (totalArray[randPass][indexRow4][4] == 'L'))
|| ((totalArray[randPass][indexRow0][0] == 'S')
&& (totalArray[randPass][indexRow1][1] == 'T')
&& (totalArray[randPass][indexRow2][2] == 'I')
&& (totalArray[randPass][indexRow3][3] == 'L')
&& (totalArray[randPass][indexRow4][4] == 'L'))
|| ((totalArray[randPass][indexRow0][0] == 'S')
&& (totalArray[randPass][indexRow1][1] == 'T')
&& (totalArray[randPass][indexRow2][2] == 'U')
&& (totalArray[randPass][indexRow3][3] == 'D')
&& (totalArray[randPass][indexRow4][4] == 'Y'))
|| ((totalArray[randPass][indexRow0][0] == 'T')
&& (totalArray[randPass][indexRow1][1] == 'H')
&& (totalArray[randPass][indexRow2][2] == 'E')
&& (totalArray[randPass][indexRow3][3] == 'I')
&& (totalArray[randPass][indexRow4][4] == 'R'))
|| ((totalArray[randPass][indexRow0][0] == 'T')
&& (totalArray[randPass][indexRow1][1] == 'H')
&& (totalArray[randPass][indexRow2][2] == 'E')
&& (totalArray[randPass][indexRow3][3] == 'R')
&& (totalArray[randPass][indexRow4][4] == 'E'))
|| ((totalArray[randPass][indexRow0][0] == 'T')
&& (totalArray[randPass][indexRow1][1] == 'H')
&& (totalArray[randPass][indexRow2][2] == 'E')
&& (totalArray[randPass][indexRow3][3] == 'S')
&& (totalArray[randPass][indexRow4][4] == 'E'))
|| ((totalArray[randPass][indexRow0][0] == 'T')
&& (totalArray[randPass][indexRow1][1] == 'H')
&& (totalArray[randPass][indexRow2][2] == 'I')
&& (totalArray[randPass][indexRow3][3] == 'N')
&& (totalArray[randPass][indexRow4][4] == 'G'))
|| ((totalArray[randPass][indexRow0][0] == 'T')
&& (totalArray[randPass][indexRow1][1] == 'H')
&& (totalArray[randPass][indexRow2][2] == 'I')
&& (totalArray[randPass][indexRow3][3] == 'N')
&& (totalArray[randPass][indexRow4][4] == 'K'))
|| ((totalArray[randPass][indexRow0][0] == 'T')
&& (totalArray[randPass][indexRow1][1] == 'H')
&& (totalArray[randPass][indexRow2][2] == 'R')
&& (totalArray[randPass][indexRow3][3] == 'E')
&& (totalArray[randPass][indexRow4][4] == 'E'))
|| ((totalArray[randPass][indexRow0][0] == 'W')
&& (totalArray[randPass][indexRow1][1] == 'A')
&& (totalArray[randPass][indexRow2][2] == 'T')
&& (totalArray[randPass][indexRow3][3] == 'E')
&& (totalArray[randPass][indexRow4][4] == 'R'))
|| ((totalArray[randPass][indexRow0][0] == 'W')
&& (totalArray[randPass][indexRow1][1] == 'H')
&& (totalArray[randPass][indexRow2][2] == 'E')
&& (totalArray[randPass][indexRow3][3] == 'R')
&& (totalArray[randPass][indexRow4][4] == 'E'))
|| ((totalArray[randPass][indexRow0][0] == 'W')
&& (totalArray[randPass][indexRow1][1] == 'H')
&& (totalArray[randPass][indexRow2][2] == 'I')
&& (totalArray[randPass][indexRow3][3] == 'C')
&& (totalArray[randPass][indexRow4][4] == 'H'))
|| ((totalArray[randPass][indexRow0][0] == 'W')
&& (totalArray[randPass][indexRow1][1] == 'O')
&& (totalArray[randPass][indexRow2][2] == 'R')
&& (totalArray[randPass][indexRow3][3] == 'L')
&& (totalArray[randPass][indexRow4][4] == 'D'))
|| ((totalArray[randPass][indexRow0][0] == 'W')
&& (totalArray[randPass][indexRow1][1] == 'O')
&& (totalArray[randPass][indexRow2][2] == 'U')
&& (totalArray[randPass][indexRow3][3] == 'L')
&& (totalArray[randPass][indexRow4][4] == 'D'))
|| ((totalArray[randPass][indexRow0][0] == 'W')
&& (totalArray[randPass][indexRow1][1] == 'R')
&& (totalArray[randPass][indexRow2][2] == 'I')
&& (totalArray[randPass][indexRow3][3] == 'T')
&& (totalArray[randPass][indexRow4][4] == 'E')))
{
tempCString[0] = totalArray[randPass][indexRow0][0];
ssd1306_printText(35, 3, tempCString); // print message
tempCString[0] = totalArray[randPass][indexRow1][1];
ssd1306_printText(45, 3, tempCString); // print message
tempCString[0] = totalArray[randPass][indexRow2][2];
ssd1306_printText(55, 3, tempCString); // print message
tempCString[0] = totalArray[randPass][indexRow3][3];
ssd1306_printText(65, 3, tempCString); // print message
tempCString[0] = totalArray[randPass][indexRow4][4];
ssd1306_printText(75, 3, tempCString); // print message
ssd1306_printText(20, 5, "Module Defused"); // print message
P2OUT |= LED;
passwordSolved = 0;
}
switch0 = 0;
switch1 = 0;
switch2 = 0;
switch3 = 0;
switch4 = 0;
}
}
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void) // Port 1 interrupt service routine, without any debouncing
{
if (TAIFG == 0) // if timer has been started, go to main
{
;
}
else // if timer has not been started, start timer
{
TA0CCTL0 = CCIE; // enable the interrupts from TimerA0 CC0
}
P1IFG &= ~BUTTON; // P1.3 IFG cleared
}
#pragma vector=PORT2_VECTOR
__interrupt void Port_2(void) // Port 2 interrupt service routine, without any debouncing
{
if (TAIFG == 0) // if timer has been started, go to main
{
;
}
else // if timer has not been started, start timer
{
TA0CCTL0 = CCIE; // enable the interrupts from TimerA0 CC0
}
P2IFG &= ~BUTTON; // P1.3 IFG cleared
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A(void) // Timer A0 interrupt service routine
{
if ((!(BUTTON0 & P1IN)) && (switch0 == 0)) // if button0 is still pressed, change index
{
indexRow0++;
if (indexRow0 > 4)
indexRow0 = 0;
switch0 = 1;
}
if ((!(BUTTON1 & P1IN)) && (switch1 == 0)) // if button1 is still pressed, change index
{
indexRow1++;
if (indexRow1 > 4)
indexRow1 = 0;
switch1 = 1;
}
if ((!(BUTTON2 & P1IN)) && (switch2 == 0)) // if button2 is still pressed, change index
{
indexRow2++;
if (indexRow2 > 4)
indexRow2 = 0;
switch2 = 1;
}
if ((!(BUTTON3 & P1IN)) && (switch3 == 0)) // if button3 is still pressed, change index
{
indexRow3++;
if (indexRow3 > 4)
indexRow3 = 0;
switch3 = 1;
}
if ((!(BUTTON4 & P1IN)) && (switch4 == 0)) // if button4 is still pressed, change index
{
indexRow4++;
if (indexRow4 > 4)
indexRow4 = 0;
switch4 = 1;
}
if (!(BUTTON3 & P2IN))
{ // if button3 is pressed
keyFlag3 = 1; // raise flag3
}
if ((!(BUTTON0 & P2IN)) && (keyFlag3))
{ //if button0 is pressed after button3
keyFlag0 = 1;
}
if ((!(BUTTON1 & P2IN)) && (keyFlag3) && (keyFlag0))
{ //if button1 is pressed after button3 AND button0
keyFlag1 = 1;
}
if ((!(BUTTON2 & P2IN)) && (keyFlag3) && (keyFlag0) && (keyFlag1))
{ //if button2 is pressed after button3 AND button0 AND button1
keyDefuse = 1;
P1OUT |= LED;
}
}
Comments