예제 #1
0
파일: Lab1.c 프로젝트: KylePolansky/EE445L
int main(void){uint32_t i;
  PLL_Init(Bus80MHz);
  PortF_Init();
  ST7735_InitR(INITR_REDTAB);
  while(1){
    ST7735_FillScreen(0);  // set screen to black
    ST7735_SetCursor(0,0);
    printf("Lab 1\rST7735_sDecOut3\r");
    for(i=0; i<13; i++){
      ST7735_sDecOut3(outTests1[i].InNumber);  // your solution
      ST7735_OutString((char*)outTests1[i].OutBuffer); // expected solution
    }
    //Pause();
  
    ST7735_FillScreen(0);  // set screen to black
    ST7735_SetCursor(0,0);
    printf("ST7735_uBinOut8\r");
    for(i=0; i<14; i++){
      ST7735_uBinOut8(outTests2[i].InNumber);  // your solution
      ST7735_OutString((char*)outTests2[i].OutBuffer); // expected solution
    }
    //Pause();
    
    ST7735_XYplotInit("Circle",-2500, 2500, -2500, 2500);
    ST7735_XYplot(180,(int32_t *)CircleXbuf,(int32_t *)CircleYbuf);
    //Pause();
    
    ST7735_XYplotInit("Star- upper right",-450, 150, -400, 200);
    ST7735_XYplot(50,(int32_t *)StarXbuf,(int32_t *)StarYbuf);
    Pause(); 
  } 
} 
int main(void){
  TExaS_Init(SSI0_Real_Nokia5110_Scope);  // set system clock to 80 MHz
  Random_Init(1);

  Output_Init();
  ST7735_FillScreen(0x0000);            // set screen to black
  
  ST7735_DrawBitmap(52, 159, PlayerShip0, 18,8); // player ship middle bottom
  ST7735_DrawBitmap(53, 151, Bunker0, 18,5);

  ST7735_DrawBitmap(0, 9, SmallEnemy10pointA, 16,10);
  ST7735_DrawBitmap(20,9, SmallEnemy10pointB, 16,10);
  ST7735_DrawBitmap(40, 9, SmallEnemy20pointA, 16,10);
  ST7735_DrawBitmap(60, 9, SmallEnemy20pointB, 16,10);
  ST7735_DrawBitmap(80, 9, SmallEnemy30pointA, 16,10);
  ST7735_DrawBitmap(100, 9, SmallEnemy30pointB, 16,10);


  Delay100ms(50);              // delay 5 sec at 80 MHz


  ST7735_FillScreen(0x0000);            // set screen to black
  ST7735_SetCursor(1, 1);
  ST7735_OutString("GAME OVER");
  ST7735_SetCursor(1, 2);
  ST7735_OutString("Nice try,");
  ST7735_SetCursor(1, 3);
  ST7735_OutString("Earthling!");
  ST7735_SetCursor(2, 4);
  LCD_OutDec(1234);
  while(1){
  }

}
예제 #3
0
파일: Lab1.c 프로젝트: KylePolansky/EE445L
/**************ST7735_XYplotInit***************
 Specify the X and Y axes for an x-y scatter plot
 Draw the title and clear the plot area
 Inputs:  title  ASCII string to label the plot, null-termination
          minX   smallest X data value allowed, resolution= 0.001
          maxX   largest X data value allowed, resolution= 0.001
          minY   smallest Y data value allowed, resolution= 0.001
          maxY   largest Y data value allowed, resolution= 0.001
 Outputs: none
 assumes minX < maxX, and miny < maxY
*/
void ST7735_XYplotInit(char *title, int32_t minX, int32_t maxX, int32_t minY, int32_t maxY){
	ST7735_FillScreen(ST7735_BLACK);  // set screen to black
  ST7735_SetCursor(0,0);
	printf("%s\n", title);
	
	gi.xMax = maxX;
	gi.xMin = minX;
	gi.yMax = maxY;
	gi.yMin	= minY;
	gi.xRange = maxX - minX;
	gi.yRange = maxY - minY;
	
	if(ST7735_TFTWIDTH<=ST7735_TFTHEIGHT)
		gi.smallDem = ST7735_TFTWIDTH;
	else
		gi.smallDem = ST7735_TFTHEIGHT;
	
	ST7735_DrawFastVLine((ST7735_TFTWIDTH)/2, 0, ST7735_TFTHEIGHT, ST7735_WHITE);
	ST7735_DrawFastHLine(0, ST7735_TFTHEIGHT/2, ST7735_TFTWIDTH, ST7735_WHITE);
	
	ST7735_DrawChar((ST7735_TFTWIDTH)/2 + 1,  0, 'y', ST7735_WHITE, ST7735_BLACK, 1);
	ST7735_DrawChar(0, (ST7735_TFTHEIGHT)/2 + 1, 'x', ST7735_WHITE, ST7735_BLACK, 1);
	
	return;
}
예제 #4
0
int init() {
    // unselect all SPI devices first
    SDCARD_Unselect();
    ST7735_Unselect();

    // initialize SD-card as fast as possible, it glitches otherwise
    // (this is important only if SPI bus is shared by multiple devices)
    int code = SDCARD_Init();
    if(code < 0) {
        UART_Printf("SDCARD_Init() failed, code = %d\r\n", code);
        return -1;
    }

    ST7735_Init();
    ST7735_FillScreen(ST7735_BLACK);

    // mount the default drive
    FRESULT res = f_mount(&fs, "", 0);
    if(res != FR_OK) {
        UART_Printf("f_mount() failed, res = %d\r\n", res);
        return -2;
    }
    UART_Printf("f_mount() done!\r\n");

    return 0;
}
예제 #5
0
파일: ST7735.c 프로젝트: howlanjo/Project-2
//------------ST7735_InitR------------
// Initialization for ST7735R screens (green or red tabs).
// Input: option one of the enumerated options depending on tabs
// Output: none
void ST7735_InitR(enum initRFlags option) {
  commonInit(Rcmd1);
  if(option == INITR_GREENTAB) {
    commandList(Rcmd2green);
    ColStart = 2;
    RowStart = 1;
  } else {
    // colstart, rowstart left at default '0' values
    commandList(Rcmd2red);
  }
  commandList(Rcmd3);

  // if black, change MADCTL color filter
  if (option == INITR_BLACKTAB) {
    writecommand(ST7735_MADCTL);
    writedata(0xC0);
  }
  TabColor = option;
  ST7735_SetCursor(0,0);
  StTextColor = ST7735_YELLOW;
  ST7735_FillScreen(0);                 // set screen to black
}
예제 #6
0
int main(void){
  PLL_Init();                           // 25 MHz
	

	
  SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOF; // activate port F
   ADC0_InitSWTriggerSeq3(0);            // allow time to finish activating
 // ADC0_InitAllTriggerSeq3(0);           // allow time to finish activating
	Timer0A_Init10HzInt();                // set up Timer0A for 10 Hz interrupts
  Timer1_Init();												// Intitalize timer1 count down
	
  GPIO_PORTF_DIR_R |= 0x04;             // make PF2 out (built-in LED)
  GPIO_PORTF_AFSEL_R &= ~0x04;          // disable alt funct on PF2
  GPIO_PORTF_DEN_R |= 0x04;             // enable digital I/O on PF2
                                        // configure PF2 as GPIO
  GPIO_PORTF_PCTL_R = (GPIO_PORTF_PCTL_R&0xFFFFF0FF)+0x00000000;
  GPIO_PORTF_AMSEL_R = 0;               // disable analog functionality on PF
  GPIO_PORTF2 = 0;                      // turn off LED
	 EnableInterrupts();
   ST7735_InitR(INITR_REDTAB);
	ST7735_FillScreen(0);  // set screen to black
	ST7735_SetCursor(0,0);
  ST7735_XYplotInit("Lab 2 PMF Averaging \n", 0, 4096, 0, 50);
	ST7735_OutString("1 point \n");
  while(1){
     WaitForInterrupt();
		 
//    GPIO_PORTF2 = 0x04;                 // profile
//    ADCvalue = ADC0_InSeq3();
//    GPIO_PORTF2 = 0x00;
		
		
		if(Buffer_Counter == 1000){
		    break;
		}
  }
		uint32_t Jitter;
	//	DisableInterrupts();
		//	TIMER1_CTL_R = 0x00000000;    // 10) enable TIMER1A
			GPIO_PORTF2 = 0x04;                   // profile
			
			
			Jitter = Calc_Jitter();  
			 uint32_t n = ADCvalue;
 	  //	 ST7735_OutUDec(n);
			Calc_PMF();  // will populate the frequency table ADC_Data = x-axis ADC_Freq = y-axis
			// Next line is call to the plot point function we created in lab1
		  //	ST7735_XYplotInit("PMF", 0, 4096, 0, 50);
		  //  ST7735_XYplot(1000, ADC_Data, ADC_Freq);
			int j = 0;
			uint32_t x = 0;
			uint32_t y = 0;
	    int i = 0;
			//ST7735_PlotClear(32, 159);
		//	for(j = 0; j < 1000; j+=1){
				ST7735_XYplotInit("Lab 2 PMF", 0, 4095, 0, 1000);
				ST7735_XYplot(1000, ADC_Data, ADC_Freq);
			 	// ST7735_PlotBar(ADC_Freq[j]);
				// ST7735_PlotBar(ADC_Freq[j]);
				 //ST7735_PlotBar(30);
				//ST7735_PlotNext();
				
			//	  y = 32+(127*(400-ADC_Freq[j]))/400;
		  //		x = 127-(127*(4095 - ADC_Data[j])/4095);
			//	  if(x<0)x = 0;
			//		if(x>127)x=127;
			//		if(y<32) y = 32;
			//	ST7735_PlotBar(y);
			//	if(y>159) y = 159;
			 // 	if(x > i){
				//		ST7735_PlotNext();
				 //	  i += 1;
				 // }
				
				/*
				if(j < 14){
				ST7735_OutUDec(ADC_Data[j]);
				ST7735_OutString(" ");
				ST7735_OutUDec(ADC_Freq[j]);
					ST7735_OutString("\n");
				}
				*/
//			}
			GPIO_PORTF2 = 0x00;
		//	EnableInterrupts();
}
예제 #7
0
int main(void){  
	char* lab_greeting = "Smart \"Mirror\"!";
	
	
  DisableInterrupts();
  PLL_Init(Bus80MHz);
  Output_Init();       // UART0 only used for debugging
	ST7735_Output_Init(); 
	PortF_Init();
	PortE_Init();
  printf("\n\r-----------\n\rSystem starting...\n\r");
	
	
  ESP8266_Init(115200);      // connect to access point, set up as client
  ESP8266_GetVersionNumber();
	
  while(1){
		if(last_mode != mode){
			refresh =1;
			last_mode = mode;
			memset(ResponseJson, 0, SERVER_RESPONSE_SIZE * sizeof(ResponseJson[0]));
		}
		
		if(mode==0&&refresh){
			refresh = 0;
			ST7735_FillScreen(0);
			ST7735_DrawString(0,0, lab_greeting, ST7735_WHITE);
			ST7735_DrawString(0,1, "MODE: WEATHER", ST7735_GREEN);
			ESP8266_GetStatus();
			if(ESP8266_MakeTCPConnection("kylepolansky.dyndns.org")){ // open socket in server
				LED_GreenOn();
				ESP8266_SendTCP(Fetch_Kyle);
			}
			ESP8266_CloseTCPConnection(); 				
			ParseWeather(ResponseJson);
			printf("START RESPONSE\n");
			printf(ResponseJson);
			printf("STOP RESPONSE\n");
			
		}
		else if(mode==1&&refresh){
			refresh = 0;
			ST7735_FillScreen(0);
			ST7735_DrawString(0,0, lab_greeting, ST7735_WHITE);
			ST7735_DrawString(0,1, "MODE: TIME", ST7735_GREEN);
			ESP8266_GetStatus();
			if(ESP8266_MakeTCPConnection("kylepolansky.dyndns.org")){ // open socket in server
				LED_GreenOn();
				ESP8266_SendTCP(Fetch_Kyle);
			}
			ESP8266_CloseTCPConnection(); 				
			ParseTime(ResponseJson);
			printf("START RESPONSE\n");
			printf(ResponseJson);
			printf("STOP RESPONSE\n");
			
		}
		else if(mode==2&&refresh){
			refresh = 0;
		ST7735_FillScreen(0);
			ST7735_DrawString(0,0, lab_greeting, ST7735_WHITE);
			ST7735_DrawString(0,1, "MODE: REMINDERS", ST7735_GREEN);
		ESP8266_GetStatus();
			if(ESP8266_MakeTCPConnection("kylepolansky.dyndns.org")){ // open socket in server
				LED_GreenOn();
				ESP8266_SendTCP(Fetch_Kyle);
			}
			ESP8266_CloseTCPConnection(); 				
			ParseReminders(ResponseJson);
			printf("START RESPONSE\n");
			printf(ResponseJson);
			printf("STOP RESPONSE\n");
		}	
		else if(mode==3&&refresh){
			refresh = 0;
		ST7735_FillScreen(0);
			ST7735_DrawString(0,0, lab_greeting, ST7735_WHITE);
			ST7735_DrawString(0,1, "MODE: NEWS", ST7735_GREEN);
		ESP8266_GetStatus();
			if(ESP8266_MakeTCPConnection("kylepolansky.dyndns.org")){ // open socket in server
				LED_GreenOn();
				ESP8266_SendTCP(Fetch_Kyle);
			}
			ESP8266_CloseTCPConnection(); 				
			ParseHeadline(ResponseJson);
			printf("START RESPONSE\n");
			printf(ResponseJson);
			printf("STOP RESPONSE\n");
		}
		else if(mode==4&&refresh){
			refresh = 0;
		ST7735_FillScreen(0);
			ST7735_DrawString(0,0, lab_greeting, ST7735_WHITE);
			ST7735_DrawString(0,1, "MODE: STOCK", ST7735_GREEN);
		ESP8266_GetStatus();
			if(ESP8266_MakeTCPConnection("kylepolansky.dyndns.org")){ // open socket in server
				LED_GreenOn();
				ESP8266_SendTCP(Fetch_Kyle);
			}
			ESP8266_CloseTCPConnection(); 				
			ParseStock(ResponseJson);
			printf("START RESPONSE\n");
			printf(ResponseJson);
			printf("STOP RESPONSE\n");
		}
		

  }
}
예제 #8
0
파일: ST7735.c 프로젝트: howlanjo/Project-2
//------------ST7735_InitB------------
// Initialization for ST7735B screens.
// Input: none
// Output: none
void ST7735_InitB(void) {
  commonInit(Bcmd);
  ST7735_SetCursor(0,0);
  StTextColor = ST7735_YELLOW;
  ST7735_FillScreen(0);                 // set screen to black
}
예제 #9
0
//-----------------------------------------------------------------------
//
//		THIS CODE HAS THE MANUAL CHIP SELECT FOR THE DISPLAY
//
int main (void)
{
	//============== Local Variables =====================
	int encoderValue = 0;
	int16_t temp0, temp2, temp3;
	unsigned int temp1;
	int refreshValues = YES, i, t = 0, h = 0;
	double temptemp1, temptemp2;
	screen = 2;
	tempFormat = CEL;
	tempCharacter[0] = 'C';

	// Turning off watch dog timer
	MAP_WDT_A_holdTimer();

	//Configuring pins for peripheral/crystal usage.
	CS_setExternalClockSourceFrequency(32768,48000000);
	MAP_PCM_setCoreVoltageLevel(PCM_VCORE1);
	MAP_FlashCtl_setWaitState(FLASH_BANK0, 2);
	MAP_FlashCtl_setWaitState(FLASH_BANK1, 2);
	CS_startHFXT(false);
	//Setting other clocks to speeds needed throughout the project
	MAP_CS_initClockSignal(CS_MCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_1);
	MAP_CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_4);
	MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_PJ, GPIO_PIN3 | GPIO_PIN4, GPIO_PRIMARY_MODULE_FUNCTION);

	//Initialization functions for variable peripherals
	InitFunction();
	err = DisplayInit();
	err |= InitOneWire();
	err |= RF_Init();
	if(err)
	{
		printf("ERROR occured in initialization functions.\n");
	}

	//Setting variables to initial values
	temperatureOUT[0] = 250;	temperatureOUT[1] = 251;
	temperatureIN[0] = 220;		temperatureIN[1] = 221;
	humidityOUT[0] = 440;		humidityOUT[1] = 441;
	humidityIN[0] = 330;		humidityIN[1] = 331;
	pressure[0] = 60;			pressure[1] = 61;
	lux[0] = 9000;				lux[1] = 9001;
	lightIndex[0] = 1;			lightIndex[1] = 2;

	//Enable interupts and set the interupt for the One-Wire to have highest priority
	MAP_Interrupt_enableMaster();
	MAP_Interrupt_setPriority(INT_TA0_0, 0x00);

	//Keep process in infinite loop
	while(1)
	{
		while(!Setup) //'Setup' controls whether or not the user is view the data from
					  //the remote system, or is editing the time for the RTC
		{
	        if (status) //'status' is set high when the IQR pin is set high -- meaning there is a packet
	        			//available to be read in from the RF chip
	        {
	        	status = 0;
	        	r_rx_payload((uint8_t)PACKET_SIZE, &data);	//retrieve data
	        	sscanf(data, "<T%dP%dH%dL%d>", &temp0, &temp1, &temp2, &temp3);  //parse data
	        	temperatureOUT[0] = temp0;
	        	pressure[0] = temp1;
	        	humidityOUT[0] = temp2;
	        	lux[0] = temp3;
	        	calculateLighting(lux[0], lightIndexString[0], &lightIndex[0]); 	//Figure out the lighting condition

	        	//Convert to F if 'tempFormat' is set high when tempFormat is set high, indicating that there needs to be a
	        	//C to F convserion. The data is C from the sensors.
				if(tempFormat == FAR)
				{
					//C to F convserion
					temptemp2 =  ((float)temperatureOUT[0]);
					temperatureOUT[0] = (int)((temptemp2 * 1.8));
					temperatureOUT[0] += 320;
				}
	        }

	        //Tick is set high every second from the RTC interupt
			if(tick)
			{
				i = 0;
				MAP_SysTick_disableModule(); // disable the systick interupt during while getting the
											 // temperature and humidity data from sensor
				//Getting the temp and humidity data
				__delay_cycles(100);
				dht_start_read();
				t = dht_get_temp();
				h = dht_get_rh();
				MAP_SysTick_enableModule(); //Enable the systick interupt again
				__delay_cycles(100);

				//put the humidity and temperature values in the needed variables
				humidityIN[0] = h;
				temperatureIN[0] = t;

				//Convert to F if 'tempFormat' is set high when tempFormat is set high, indicating that there needs to be a
				//C to F convserion. The data is C from the sensors.
				if(tempFormat == FAR)
				{
					//C to F conversion
					temptemp1 =  ((float)temperatureIN[0]);
					temperatureIN[0] = (int)((temptemp1 * 1.8));
					temperatureIN[0] += 320;
				}
			}

			//'screen' is either set to the value of 1 or 2.
			// screen == 1 is the main screen with only the temperatures and lighting condition displayed
			if(screen == 1)
			{
				//If the time has been updated or the screen has been switched, update the string
				if(tick || refreshValues)
				{
					tick = 0;
					//Create the time and date strings
					sprintf(dateString, "%s %02X, %X", months[newTime.month], newTime.dayOfmonth, newTime.year);
					sprintf(timeString, "%02X:%02X:%02X", newTime.hours, newTime.minutes, newTime.seconds);

					//Write "IN:" in the lower part of the screen to indicate to the user which temperature is the
					//inside tempterature
					if(refreshValues == YES)
					{
						ST7735_DrawStringHorizontal(50, 140, "IN:", ST7735_Color565(255, 255, 255), 1);
					}

					//Printing the time
					for(i = 0; i < strlen(timeString); i++)
					{
						ST7735_DrawChar(22+(11*i), 10, timeString[i], timeStringColor[i], 0x0000, 2);
					}

					//Printing the date
					for(i = 0; i < strlen(dateString); i++)
					{
						ST7735_DrawChar(30+(6*i), 30, dateString[i], dateStringColor[i], 0x0000, 1);
					}
				}

				//If the new data value is different than the previous value, or the screen has been changes, update display
				if((temperatureOUT[0] != temperatureOUT[1]) || refreshValues == YES)
				{
					//Re-write the last string in black (the same color as the backgruond) to cover it up so that the
					// new value is not written overtop.
					sprintf(tempString, "%02d.%.1d", temperatureOUT[1]/10, temperatureOUT[1]%10);
					ST7735_DrawStringHorizontal(20, 80, tempString, ST7735_Color565(0, 0, 0), 4);
					ST7735_DrawCharS((20 + strlen(tempString)*4*6), 80, tempCharacter[1], ST7735_Color565(0, 0, 0), ST7735_Color565(0, 0, 0), 1);

					//Write the new string
					sprintf(tempString, "%02d.%.1d", temperatureOUT[0]/10, temperatureOUT[0]%10);
					ST7735_DrawStringHorizontal(20, 80, tempString, ST7735_Color565(255, 0, 0), 4);
					ST7735_DrawCharS((20 + strlen(tempString)*4*6), 80, tempCharacter[0], ST7735_Color565(255, 0, 0), ST7735_Color565(255, 0, 0), 1);
					temperatureOUT[1] = temperatureOUT[0];
					tempCharacter[1] = tempCharacter[0];
				}

				//If the new data value is different than the previous value, or the screen has been changes, update display
				if((temperatureIN[0] != temperatureIN[1]) || refreshValues == YES)
				{
					//Re-write the last string in black (the same color as the backgruond) to cover it up so that the
					// new value is not written overtop.
					sprintf(tempString, "%02d.%.1d", temperatureIN[1]/10, temperatureIN[1]%10);
					ST7735_DrawStringHorizontal(70, 130, tempString, ST7735_Color565(0, 0, 0), 2);
					ST7735_DrawCharS((70 + strlen(tempString)*2*6), 130, tempCharacter, ST7735_Color565(0, 0, 0), ST7735_Color565(0, 0, 0), 1);

					//Write the new string
					sprintf(tempString, "%02d.%.1d", temperatureIN[0]/10, temperatureIN[0]%10);
					ST7735_DrawStringHorizontal(70, 130, tempString, ST7735_Color565(255, 0, 0), 2);
					ST7735_DrawCharS((70 + strlen(tempString)*2*6), 130, tempCharacter, ST7735_Color565(255, 0, 0), ST7735_Color565(255, 0, 0), 1);
					temperatureIN[1] = temperatureIN[0];
					tempCharacter[1] = tempCharacter[0];
				}

				//If the new data value is different than the previous value, or the screen has been changes, update display
				if((lightIndex[0] != lightIndex[1]) || refreshValues == YES)
				{
					//Re-write the last string in black (the same color as the backgruond) to cover it up so that the
					// new value is not written overtop.
					sprintf(tempString, "%s", lightIndexString[1]);
					ST7735_DrawStringVertical(0, 60, tempString, ST7735_Color565(0, 0, 0), 2);

					//Write the new string
					sprintf(tempString, "%s", lightIndexString[0]);
					ST7735_DrawStringVertical(0, 60, tempString, ST7735_Color565(0, 255, 0), 2);
					memcpy(lightIndexString[1], lightIndexString[0], sizeof(lightIndexString[0]));
					lightIndex[1] = lightIndex[0];
				}
				//Reset the refreshValues variable. This variable will be set high when the user swithces screen by turning the knob
				refreshValues = NO;
			}
			//'screen' equalling 2 is the screen that displays all the data to the user
			if(screen == 2)
			{
				//If the time has been updated or the screen has been switched, update the string
				if(time || refreshValues)
				{
					tick = 0;
					//Create the time string that will be written
					sprintf(timeString, "%02X:%02X:%02X", newTime.hours, newTime.minutes, newTime.seconds);

					//Write the new time string
					for(i = 0; i < strlen(timeString); i++)
					{
						ST7735_DrawChar(35+(6*i), 5, timeString[i], ST7735_Color565(0, 0, 0), ST7735_Color565(255, 255, 255), 1);
					}
				}

				//When update the items on the screen that will remain constant when the screen is changed.
				if(refreshValues == YES)
				{
					sprintf(tempString, "Inside");
					ST7735_DrawStringVertical(0, 10, tempString, ST7735_Color565(0, 255, 0), 1);

					sprintf(tempString, "Outside");
					ST7735_DrawStringVertical(120, 90, tempString, ST7735_Color565(0, 255, 0), 1);

					sprintf(tempString, "_______________________");
					ST7735_DrawStringHorizontal(0, 55, tempString, ST7735_Color565(255, 255, 255), 1);
				}

				//If the new data value is different than the previous value, or the screen has been changes, update display
				if((temperatureIN[0] != temperatureIN[1]) || refreshValues == YES)
				{
					//Re-write the last string in black (the same color as the backgruond) to cover it up so that the
					// new value is not written overtop.
					sprintf(tempString, "%02d.%.1d", temperatureIN[1]/10, temperatureIN[1]%10);
					ST7735_DrawStringHorizontal(12, 30, tempString, ST7735_Color565(0, 0, 0), 2);
					ST7735_DrawCharS((12 + strlen(tempString)*2*6), 25, tempCharacter, ST7735_Color565(0, 0, 0), ST7735_Color565(0, 0, 0), 1);

					//Write the new string
					sprintf(tempString, "%02d.%.1d", temperatureIN[0]/10, temperatureIN[0]%10);
					ST7735_DrawStringHorizontal(12, 30, tempString, ST7735_Color565(255, 0, 0), 2);
					ST7735_DrawCharS((12 + strlen(tempString)*2*6), 25, tempCharacter, ST7735_Color565(255, 0, 0), ST7735_Color565(255, 0, 0), 1);
					temperatureIN[1] = temperatureIN[0];
					tempCharacter[1] = tempCharacter[0];
				}

				//If the new data value is different than the previous value, or the screen has been changes, update display
				if((humidityIN[0] != humidityIN[1]) || refreshValues == YES)
				{
					//Re-write the last string in black (the same color as the backgruond) to cover it up so that the
					// new value is not written overtop.
					sprintf(tempString, "%02d.%.1d", humidityIN[1]/10, humidityIN[1]%10);
					ST7735_DrawStringHorizontal(74, 30, tempString, ST7735_Color565(0, 0, 0), 2);
					ST7735_DrawCharS((74 + strlen(tempString)*2*6), 27, '%', ST7735_Color565(0, 0, 0), ST7735_Color565(0, 0, 0), 1);

					//Write the new string
					sprintf(tempString, "%02d.%.1d", humidityIN[0]/10, humidityIN[0]%10);
					ST7735_DrawStringHorizontal(74, 30, tempString, ST7735_Color565(255, 0, 0), 2);
					ST7735_DrawCharS((74 + strlen(tempString)*2*6), 27, '%', ST7735_Color565(255, 0, 0), ST7735_Color565(255, 0, 0), 1);
					humidityIN[1] = humidityIN[0];
				}

				//==========================================================================================================================


				//If the new data value is different than the previous value, or the screen has been changes, update display
				if((temperatureOUT[0] != temperatureOUT[1]) || refreshValues == YES)
				{
					//Re-write the last string in black (the same color as the backgruond) to cover it up so that the
					// new value is not written overtop.
					sprintf(tempString, "%02d.%.1d", temperatureOUT[1]/10, temperatureOUT[1]%10);
					ST7735_DrawStringHorizontal(0, 70, tempString, ST7735_Color565(0, 0, 0), 2);
					ST7735_DrawCharS((0 + strlen(tempString)*2*6), 68, tempCharacter, ST7735_Color565(0, 0, 0), ST7735_Color565(0, 0, 0), 1);

					//Write the new string
					sprintf(tempString, "%02d.%.1d", temperatureOUT[0]/10, temperatureOUT[0]%10);
					ST7735_DrawStringHorizontal(0, 70, tempString, ST7735_Color565(255, 0, 0), 2);
					ST7735_DrawCharS((0 + strlen(tempString)*2*6), 68, tempCharacter, ST7735_Color565(255, 0, 0), ST7735_Color565(255, 0, 0), 1);
					temperatureOUT[1] = temperatureOUT[0];
					tempCharacter[1] = tempCharacter[0];
				}

				//If the new data value is different than the previous value, or the screen has been changes, update display
				if((humidityOUT[0] != humidityOUT[1]) || refreshValues == YES)
				{
					//Re-write the last string in black (the same color as the backgruond) to cover it up so that the
					// new value is not written overtop.
					sprintf(tempString, "%02d.%.1d", humidityOUT[1]/10, humidityOUT[1]%10);
					ST7735_DrawStringHorizontal(0, 90, tempString, ST7735_Color565(0, 0, 0), 2);
					ST7735_DrawCharS((0 + strlen(tempString)*2*6), 87, '%', ST7735_Color565(0, 0, 0), ST7735_Color565(0, 0, 0), 1);

					//Write the new string
					sprintf(tempString, "%02d.%.1d", humidityOUT[0]/10, humidityOUT[0]%10);
					ST7735_DrawStringHorizontal(0, 90, tempString, ST7735_Color565(255, 0, 0), 2);
					ST7735_DrawCharS((0 + strlen(tempString)*2*6), 87, '%', ST7735_Color565(255, 0, 0), ST7735_Color565(255, 0, 0), 1);
					humidityOUT[1] = humidityOUT[0];
				}

				if((lux[0] != lux[1]) || refreshValues == YES)
				{
					//Re-write the last string in black (the same color as the backgruond) to cover it up so that the
					// new value is not written overtop.
					sprintf(tempString, "%d", lux[1]);
					ST7735_DrawStringHorizontal(0, 112, tempString, ST7735_Color565(0, 0, 0), 2);
					ST7735_DrawCharS((0 + strlen(tempString)*2*6), 112, 'L', ST7735_Color565(0, 0, 0), ST7735_Color565(0, 0, 0), 1);

					//Write the new string
					sprintf(tempString, "%d", lux[0]);
					ST7735_DrawStringHorizontal(0, 112, tempString, ST7735_Color565(255, 0, 0), 2);
					ST7735_DrawCharS((0 + strlen(tempString)*2*6), 112, 'L', ST7735_Color565(255, 0, 0), ST7735_Color565(255, 0, 0), 1);
					lux[1] = lux[0];
				}

				//If the new data value is different than the previous value, or the screen has been changes, update display
				if((pressure[0] != pressure[1]) || refreshValues == YES)
				{
					//Re-write the last string in black (the same color as the backgruond) to cover it up so that the
					// new value is not written overtop.
					sprintf(tempString, "%d", pressure[1]);
					ST7735_DrawStringHorizontal(0, 135, tempString, ST7735_Color565(0, 0, 0), 2);
					ST7735_DrawStringHorizontal((0 + strlen(tempString)*2*6), 135, "Pa", ST7735_Color565(0, 0, 0), 1);

					//Write the new string
					sprintf(tempString, "%d", pressure[0]);
					ST7735_DrawStringHorizontal(0, 135, tempString, ST7735_Color565(255, 0, 0), 2);
					ST7735_DrawStringHorizontal((0 + strlen(tempString)*2*6), 135, "Pa", ST7735_Color565(255, 0, 0), 1);
					pressure[1] = pressure[0];
				}

				//If the new data value is different than the previous value, or the screen has been changes, update display
				if((lightIndex[0] != lightIndex[1]) || refreshValues == YES)
				{
					//Re-write the last string in black (the same color as the backgruond) to cover it up so that the
					// new value is not written overtop.
					sprintf(tempString, "%s", lightIndexString[1]);
					ST7735_DrawStringVertical(105, 70, tempString, ST7735_Color565(0, 0, 0), 2);

					//Write the new string
					sprintf(tempString, "%s", lightIndexString[0]);
					ST7735_DrawStringVertical(105, 70, tempString, ST7735_Color565(0, 0, 255), 2);
					memcpy(lightIndexString[1], lightIndexString[0], sizeof(lightIndexString[0]));
					lightIndex[1] = lightIndex[0];
				}

				refreshValues = NO;
			}

			//Check to see in the knob has been changed at all
			encoderValue = EncoderDecipher(&Encoder1, &Encoder2, &PushButton);

			//If encoder has been held, this indicates enting the setting of the RTC time
			if(encoderValue == HOLD)
			{
				Setup = YES;	//Now that is this set high, the process will exit the while loop above

				//Set all varaibles to what is needed for editing the time and date
				memset(dateStringColor, 0xFFFF, sizeof(dateStringColor));
				memset(timeStringColor, 0xFFFF, sizeof(timeStringColor));
				dateStringColor[0] = ST7735_Color565(255, 0, 0);
				dateStringColor[1] = ST7735_Color565(255, 0, 0);
				dateStringColor[2] = ST7735_Color565(255, 0, 0);

				//Getting the current RTC values and put them into variables that will then used to manipulate
				sprintf(temp, "%x, %x, %x, %x, %x, %x", newTime.month, newTime.dayOfmonth, newTime.year, newTime.hours, newTime.minutes, newTime.seconds);
				sscanf(temp, "%d, %d, %d, %d, %d, %d", &date[0], &date[1], &date[2], &time[0], &time[1], &time[2]);

				//Fill the screen in all black
				ST7735_FillScreen(0);
				//Variable controlling the whether editing the time or date
				Top = YES;
			}
			//If the user turns the knob, change the screen variable and set the refreshValues high so that the screen will change for the user
			else if (encoderValue == RIGHT || encoderValue == LEFT)
			{
				if(screen == 1)
				{
					screen = 2;
					ST7735_FillScreen(0);	//Clear screen
					refreshValues = YES;
				}
				else if(screen == 2)
				{
					screen = 1;
					ST7735_FillScreen(0); 	//Clear screen
					refreshValues = YES;
				}
			}
			//If the user just pressed the encoder (not holds it) change the temperature to be displayed in the opposite type
			else if(encoderValue == PRESS)
			{
				if(tempFormat == CEL)
				{
					tempFormat = FAR;
					tempCharacter[0] = 'F';
				}
				else
				{
					tempFormat = CEL;
					tempCharacter[0] = 'C';
				}
			}
		}

		//Keep process inside this loop while the encoder is not being touched
		while(!movement)
		{
			if(encoderRefresh)
			{
				//Getting the movement of the encoder
				movement = EncoderDecipher(Encoder1, Encoder2, PushButton);
				encoderRefresh = 0;
			}
			if(flag)
			{
				flag = 0;
				//Write the date and time strings
				for(i = 0; i < strlen(dateString); i++)
				{
					ST7735_DrawChar((11*i), 10, dateString[i], dateStringColor[i], 0x0000, 2);
				}
				for(i = 0; i < strlen(timeString); i++)
				{
					ST7735_DrawChar(22+(11*i), 40, timeString[i], timeStringColor[i], 0x0000, 2);
				}
			}
		}

		//Is user turned the knob right, increment withever value the user is editing
		if(movement == RIGHT)
		{
			flag = 1;
			if(Top)		// Up
			{
				if(dateStringColor[1] == 31)
				{
					if(++date[0] > 11)
						date[0] = 0;
				}
				else if(dateStringColor[4] == 31)
				{
					if(++date[1] > 31)
						date[1] = 0;
				}
				else
				{
					if(++date[2] > 2050)
						date[2] = 1950;
				}
			}
			else
			{
				if(timeStringColor[1] == 31)
				{
					if(++time[0] > 24)
						time[0] = 0;
				}
				else if(timeStringColor[4] == 31)
				{
					if(++time[1] > 59)
						time[1] = 0;
				}
				else
				{
					if(++time[2] > 59)
						time[2] = 0;
				}
			}
		}

		//Is user turned the knob left, decrement withever value the user is editing
		if(movement == LEFT)
		{
			flag = 1;
			if(Top)		// Up
			{
				if(dateStringColor[1] == 31)
				{
					if(--date[0] < 0)
						date[0] = 11;
				}
				else if(dateStringColor[4] == 31)
				{
					if(--date[1] < 0)
						date[1] = 31;
				}
				else
				{
					if(--date[2] < 1950)
						date[2] = 2050;
				}
			}
			else
			{
				if(timeStringColor[1] == 31)
				{
					if(--time[0] < 0)
						time[0] = 23;
				}
				else if(timeStringColor[4] == 31)
				{
					if(--time[1] < 0)
						time[1] = 59;
				}
				else
				{
					if(--time[2] < 0)
						time[2] = 59;
				}
			}
		}

		//Is user presses the right, swith which what is highlighted, to indicate to the user
		//what is being edited
		if(movement == PRESS)
		{
			flag = 1;

			if(Top)		// XXX XX XXXX
			{
				if(dateStringColor[1] == 31)
				{
					memset(dateStringColor, 0xFFFF, sizeof(dateStringColor));
					dateStringColor[4] = ST7735_Color565(255, 0, 0);
					dateStringColor[5] = ST7735_Color565(255, 0, 0);
				}
				else if(dateStringColor[4] == 31)
				{
					memset(dateStringColor, 0xFFFF, sizeof(dateStringColor));
					dateStringColor[7] = ST7735_Color565(255, 0, 0);
					dateStringColor[8] = ST7735_Color565(255, 0, 0);
					dateStringColor[9] = ST7735_Color565(255, 0, 0);
					dateStringColor[10] = ST7735_Color565(255, 0, 0);
				}
				else if(dateStringColor[8] == 31)
				{
					memset(dateStringColor, 0xFFFF, sizeof(dateStringColor));
					memset(timeStringColor, 0xFFFF, sizeof(timeStringColor));
					timeStringColor[0] = ST7735_Color565(255, 0, 0);
					timeStringColor[1] = ST7735_Color565(255, 0, 0);
					Top = NO;
				}
			}
			else				//XX XX XX
			{
				if(timeStringColor[1] == 31)
				{
					memset(timeStringColor, 0xFFFF, sizeof(timeStringColor));
					timeStringColor[3] = ST7735_Color565(255, 0, 0);
					timeStringColor[4] = ST7735_Color565(255, 0, 0);
				}
				else if(timeStringColor[4] == 31)
				{
					memset(timeStringColor, 0xFFFF, sizeof(timeStringColor));
					timeStringColor[6] = ST7735_Color565(255, 0, 0);
					timeStringColor[7] = ST7735_Color565(255, 0, 0);
				}
				else if(timeStringColor[7] == 31)
				{
					memset(timeStringColor, 0xFFFF, sizeof(timeStringColor));
					dateStringColor[0] = ST7735_Color565(255, 0, 0);
					dateStringColor[1] = ST7735_Color565(255, 0, 0);
					dateStringColor[2] = ST7735_Color565(255, 0, 0);
					Top = YES;
				}
			}
		}
		//Update the new time and date strings
		sprintf(dateString, "%s %02d,%d", months[date[0]], date[1], date[2]);
		sprintf(timeString, "%02d:%02d:%02d", time[0], time[1], time[2]);

		//If used holds the encoder down, the time and date will be written to the RTC and the process will return
		//to the top where the temp, humid... data is diplayed. Editing the time/date is exited.
		if(movement == HOLD)
		{
			if(!Setup)
			{	//Setting new time
				Setup = 1;
				flag = 1;
				if(dateStringColor[0] == 31 || dateStringColor[4] == 31 || dateStringColor[8] == 31 || timeStringColor[0] == 31 || timeStringColor[4] == 31 || timeStringColor[7] == 31)
				{
					memset(timeStringColor, 0xFFFF, sizeof(timeStringColor));
					memset(dateStringColor, 0xFFFF, sizeof(dateStringColor));
				}
				else
				{
					memset(dateStringColor, 0xFFFF, sizeof(dateStringColor));
					memset(timeStringColor, 0xFFFF, sizeof(timeStringColor));
					dateStringColor[0] = ST7735_Color565(255, 0, 0);
					dateStringColor[1] = ST7735_Color565(255, 0, 0);
					dateStringColor[2] = ST7735_Color565(255, 0, 0);
					Top = YES;
				}
			}
			else //Exiting setup
			{
				//Setup new time into system. Exiting setup
				Setup = 0;
				tick = 1;
				memset(dateStringColor, 0xFFFF, sizeof(dateStringColor));
				memset(timeStringColor, 0xFFFF, sizeof(timeStringColor));

				//Set the values (in the correct type) back into the RTC structure so that it can be updated.
				sprintf(temp, "%d, %d, %d, %d, %d, %d", date[0], date[1], date[2], time[0], time[1], time[2]);
				sscanf(temp, "%x, %x, %x, %x, %x, %x", &setTime.month, &setTime.dayOfmonth, &setTime.year, &setTime.hours, &setTime.minutes, &setTime.seconds);

				//Set the RTC with the values the uset chose
				MAP_RTC_C_initCalendar(&setTime, RTC_C_FORMAT_BCD);
				MAP_RTC_C_startClock();

				//Clear screen
				ST7735_FillScreen(0);
			}
		}
		movement = NONE;
	}
}