int main(void) { static uint8_t i = 20; initializeSystem(); while(1) { //illuminate(true); if(i == 200) { getRGBIrradiance(&spectrum); printSpectrumIrradiance(spectrum); taos_irr = getTaosIrradiance(); printTaosIrradiance(taos_irr); illuminateLEDIfThresholdMet(spectrum, taos_irr); // printTaosFrequency(); i = 0; } else { i++; } checkPB(); //illuminate(false); LoopTime(); } return 0; }
int main(void) { //Local Variables bool displayMode = true;//True if display mode, false if in data entry mode //Push buttons bool upPB = false; bool rightPB = false; bool downPB = false; bool leftPB = false; bool modePB = false; //Push buttons shift registers uint16_t shiftRegSW2 = 0xFFFF; uint16_t shiftRegSW3 = 0xFFFF; uint16_t shiftRegSW4 = 0xFFFF; uint16_t shiftRegSW5 = 0xFFFF; uint16_t shiftRegSW6 = 0xFFFF; //Initial display message uint8_t displayArray [SAVED_MSG_LEN_MAX] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; uint8_t inputArray [17] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; //Mark the indexcies of the array uint8_t endIndex = 19; uint8_t currIndex = 0; uint8_t inputIndex = 0; uint8_t tempIndex = 0; //Flag for overflwoing max char array length bool overflow = false; //Init color uint8_t color; //ADCval1 uint32_t ADCval1 = 0; uint32_t ADCval2 = 0; //Current string char myString[21] = "hello world"; char myChar; int8_t stringIndex=-1; // Initialize the PLLs so the the main CPU frequency is 80MHz PLL_Init(); //Configure Port C initPortC(); //Configure the SYSTICK timer 12.5uS ticks SYSTICKConfig(1000, true); //Configure Timer0 1mS ticks TIMER0Config(80000); //Configure watchdog with 1s reset WatchdogTIMERConfig(); // Initialize the GPIO Ports initializeGPIOPort(PORTA, &portA_config); initializeGPIOPort(PORTB, &portB_config); initializeGPIOPort(PORTC, &portC_config); initializeGPIOPort(PORTD, &portD_config); initializeGPIOPort(PORTE, &portE_config); initializeGPIOPort(PORTF, &portF_config); // Initialize SPI0 interface initializeSPI(SSI0, PHASE, POLARITY); //Init ADC ADCInit(); initializeDisplay(); // Set up the UARTS for 115200 8N1 InitializeUART(UART0); InitializeUART(UART2); InitializeUART(UART5); // Since PD7 is shared with the NMI, we need to clear the lock register and // set the commit register so that all the pins alternate functions can // be used. GPIO_PORTD_LOCK_R = 0x4C4F434B; GPIO_PORTD_CR_R = 0xFF; initializeGPIOPort(PORTD, &portD_config); EnableInterrupts(); //Get initial ADC values pwm = GetADCval(POT_RIGHT) / 40; ADCval2 = GetADCval(POT_LEFT) / 575; // Print out the current string uartTxPoll(UART0,"Hello World\n\r"); while(1) { if(checkADC){ pwm = GetADCval(POT_RIGHT) / 40; ADCval2 = GetADCval(POT_LEFT) / 600; checkADC = false; } //On systick interrupt display the current character and poll the buttons if (refreshLED){ if (displayMode){ displayLEDChar(displayArray[currIndex], ADCval2); } else{ displayLEDChar(inputArray[inputIndex], ADCval2); } refreshLED = false; } if (buttonPoll){ //Check if any buttons have been pushed //If so debounce them buttonPoll = false; //SW2 shiftRegSW2 = debounce(PORTA, SW2, shiftRegSW2); upPB = checkPB(shiftRegSW2); //SW3 shiftRegSW3 = debounce(PORTA, SW3, shiftRegSW3); rightPB = checkPB(shiftRegSW3); //SW4 shiftRegSW4 = debounce(PORTD, SW4, shiftRegSW4); downPB = checkPB(shiftRegSW4); //SW5 shiftRegSW5 = debounce(PORTD, SW5, shiftRegSW5); leftPB = checkPB(shiftRegSW5); //SW6 shiftRegSW6 = debounce(PORTF, SW6, shiftRegSW6); modePB = checkPB(shiftRegSW6); }//End polling //Display Mode if (displayMode){ //Check if right button is pressed if(rightPB){ //Clear the button press rightPB = false; //Display the next character in order in green color = GREEN_EN; if(currIndex == endIndex) currIndex = 0; else currIndex++; } //Check if left button is pressed else if(leftPB){ //Clear the button press leftPB = false; //Display the next character in reverse order in red color = RED_EN; if(currIndex == 0) currIndex = endIndex; else currIndex--; } //Check if mode button is pushed if(modePB){ //Clear the button press modePB = false; //change mode and reset parameters displayMode = false; inputIndex = 0; currIndex = 0; endIndex = 0; overflow = false; tempIndex = 0; displayArray[0] = 0; } } //Input Mode else{ //Check if right button is pressed if(rightPB || leftPB){ //Clear the button press rightPB = false; leftPB = false; //Save the current input character in the display array if //there is enough space if (tempIndex >= SAVED_MSG_LEN_MAX){ tempIndex= 0; overflow = true; } displayArray[tempIndex] = inputArray[inputIndex]; tempIndex++; } //Check if up button is pressed else if(upPB){ //Clear the button press upPB = false; //Display the next character in order in input array if(inputIndex == 15) inputIndex = 0; else inputIndex++; } //Check if down button is pressed else if(downPB){ //Clear the button press downPB = false; //Display the next character in reverse order input array if(inputIndex == 0) inputIndex = 15; else inputIndex--; } if(modePB){ //Clear the button press modePB = false; //change mode to display and reset parameters displayMode = true; color = GREEN_EN; if(overflow){ endIndex = SAVED_MSG_LEN_MAX - 1; } else if (tempIndex != 0) endIndex = tempIndex - 1; } } } }