Example #1
0
void TOUCH_init(){
	//Initialize Touch
	    if (TM_STMPE811_Init() != TM_STMPE811_State_Ok) {
	    	if (TM_STMPE811_Init() != TM_STMPE811_State_Ok) {
	    		TM_ILI9341_Puts(20, 20, "STMPE811 Error", &TM_Font_11x18, ILI9341_COLOR_ORANGE, ILI9341_COLOR_BLACK);

	    		while (1);
	    	}
	    }
}
Example #2
0
int main(void) {
	char str[30];
	/* Create TouchData struct */
	TM_STMPE811_TouchData touchData;
	
	/* Initialize system */
	SystemInit();
	
	/* Initialize LCD */
	TM_ILI9341_Init();
	/* Fill with orange color */
	TM_ILI9341_Fill(ILI9341_COLOR_ORANGE);
	/* Rotate LCD */
	TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_2);
	
	/* Initialize Touch */
	if (TM_STMPE811_Init() != TM_STMPE811_State_Ok) {
		TM_ILI9341_Puts(20, 20, "STMPE811 Error", &TM_Font_11x18, ILI9341_COLOR_ORANGE, ILI9341_COLOR_BLACK);
		
		while (1);
	}
	
	/* Select touch screen orientation */
	touchData.orientation = TM_STMPE811_Orientation_Portrait_2;
	
	/* Print some text */
	TM_ILI9341_Puts(20, 20, "Press on LCD", &TM_Font_11x18, ILI9341_COLOR_ORANGE, ILI9341_COLOR_BLACK);
	TM_ILI9341_Puts(93, 310, "stm32f4-discovery.com", &TM_Font_7x10, ILI9341_COLOR_GREEN, ILI9341_COLOR_BLACK);
	
	while (1) {
		if (TM_STMPE811_ReadTouch(&touchData) == TM_STMPE811_State_Pressed) {
			/* Touch valid */
			sprintf(str, "Pressed    \n\nX: %03d\nY: %03d", touchData.x, touchData.y);
			TM_ILI9341_Puts(20, 80, str, &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE);
		
			/* Draw pixel on touch location */
			TM_ILI9341_DrawPixel(touchData.x, touchData.y, 0x0000);
		} else {
			sprintf(str, "Not Pressed\n\n       \n      ");
			TM_ILI9341_Puts(20, 80, str, &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE);
		}
	}
}
Example #3
0
int main(void) {
	char str[30];
	//Create TouchData struct
	TM_STMPE811_TouchData touchData;
	
	//Initialize system
	SystemInit();
	
	//Initialize LCD
	TM_ILI9341_Init();
	//Fill with orange color
	TM_ILI9341_Fill(ILI9341_COLOR_ORANGE);
	//Rotate LCD
	TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_2);
	
	//Initialize Touch
	TM_STMPE811_Init();
	
	//Select touch screen orientation
	touchData.orientation = TM_STMPE811_Orientation_Portrait_2;
	
	//Print some text
	TM_ILI9341_Puts(20, 20, "Press on LCD", &TM_Font_11x18, ILI9341_COLOR_ORANGE, ILI9341_COLOR_BLACK);
	TM_ILI9341_Puts(168, 308, "majerle.eu", &TM_Font_7x10, ILI9341_COLOR_GREEN, ILI9341_COLOR_BLACK);
	
	while (1) {
		if (TM_STMPE811_ReadTouch(&touchData) == TM_STMPE811_State_Pressed) {
			//Touch valid
			sprintf(str, "Pressed    \n\nX: %03d\nY: %03d", touchData.x, touchData.y);
			TM_ILI9341_Puts(20, 80, str, &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE);

			
			TM_ILI9341_DrawPixel(touchData.x, touchData.y, 0x0000);
		} else {
			sprintf(str, "Not Pressed\n\n       \n      ");
			TM_ILI9341_Puts(20, 80, str, &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE);
		}
	}
}
Example #4
0
int main(void) {
	//TM_STMPE811_TouchData instance
	TM_STMPE811_TouchData touchData;
	//TM_ILI9341_Button_t instance
	TM_ILI9341_Button_t button;
	int8_t buttonPressed, button1, button2, button3;
	char str[30];
	//Initialize system
	SystemInit();
	
	//Initialize onboard leds
	TM_DISCO_LedInit();
	
	//Initialize LCD
	TM_ILI9341_Init();
	//Fill LCD with gray color
	TM_ILI9341_Fill(ILI9341_COLOR_GRAY);
	//Select orientation
	TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_2);
	
	//Select touch screen orientation
	touchData.orientation = TM_STMPE811_Orientation_Portrait_2;
	
	//Initialize Touch
	TM_STMPE811_Init();
	
	//Button 1, default configuration
	//Red with black border and black font 11x18
	button.x = 10;
	button.y = 30;
	button.width = 219;
	button.height = 50;
	button.background = ILI9341_COLOR_RED;
	button.borderColor = ILI9341_COLOR_BLACK;
	button.label = "Button 1";
	button.color = ILI9341_COLOR_BLACK;
	button.font = &TM_Font_11x18;
	//Add button
	button1 = TM_ILI9341_Button_Add(&button);
	
	//Button with custom background and without label
	button.x = 10;
	button.y = 260;
	button.width = 105;
	button.height = 50;
	button.background = ILI9341_COLOR_GREEN;
	button.borderColor = ILI9341_COLOR_BLACK;
	button.label = "Button 2";
	//Use background image and no label
	button.flags = TM_BUTTON_FLAG_NOLABEL | TM_BUTTON_FLAG_IMAGE;
	button.color = ILI9341_COLOR_BLACK;
	button.font = &TM_Font_11x18;
	button.image = buttonBackground; //Variable stored in 
	//Add button
	button2 = TM_ILI9341_Button_Add(&button);
	
	//Button with custom background and with label and without border and 7x10 fontsize
	button.x = 125;
	button.y = 260;
	button.background = ILI9341_COLOR_BLUE2;
	button.borderColor = ILI9341_COLOR_BLACK;
	button.label = "Button 3";
	button.color = ILI9341_COLOR_BLACK;
	button.font = &TM_Font_7x10;
	button.flags = TM_BUTTON_FLAG_IMAGE | TM_BUTTON_FLAG_NOBORDER;	//Use background image, without border
	//Add button
	button3 = TM_ILI9341_Button_Add(&button);
	
	if (!TM_DISCO_LedIsOn(LED_RED)) {
		//If led res is turned off, disable buttons 2 and 3
		TM_ILI9341_Button_Disable(button2);
		TM_ILI9341_Button_Disable(button3);
		TM_ILI9341_Puts(25, 220, "Buttons disabled!", &TM_Font_11x18, ILI9341_COLOR_RED, ILI9341_COLOR_GRAY);
	}
	
	//Draw buttons
	TM_ILI9341_Button_DrawAll();
	
	//Draw some strings
	TM_ILI9341_Puts(45, 245, "LED on         LED off", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_GRAY);
	TM_ILI9341_Puts(10, 100, "Bottom buttons work\nonly if red led is turned on.\nYou can toggle red\nled with Button 1.", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_GRAY);

	while (1) {
		if (TM_STMPE811_ReadTouch(&touchData) == TM_STMPE811_State_Pressed) {
			buttonPressed = TM_ILI9341_Button_Touch(&touchData);
			if (buttonPressed >= 0) {
				//Any button pressed
				sprintf(str, "Pressed: Button %d", (buttonPressed + 1));
			} else {
				sprintf(str, "Press the button ");
			}
			if (buttonPressed == button1) {
				//Red button 1 is pressed, toggle led
				TM_DISCO_LedToggle(LED_RED);
				
				if (TM_DISCO_LedIsOn(LED_RED)) {
					//If led is turned on, enable button 2 and button 3
					TM_ILI9341_Button_Enable(button2);
					TM_ILI9341_Button_Enable(button3);
					TM_ILI9341_Puts(25, 220, "Buttons enabled! ", &TM_Font_11x18, ILI9341_COLOR_GREEN, ILI9341_COLOR_GRAY);
				} else {
					//otherwise disable both
					TM_ILI9341_Button_Disable(button2);
					TM_ILI9341_Button_Disable(button3);
					TM_ILI9341_Puts(25, 220, "Buttons disabled!", &TM_Font_11x18, ILI9341_COLOR_RED, ILI9341_COLOR_GRAY);
				}
			} else if (buttonPressed == button2) {
				//If button 2 is pressed, turn green led on
				TM_DISCO_LedOn(LED_GREEN);
			} else if (buttonPressed == button3) {
				//if button 3 is pressed, turn green led off
				TM_DISCO_LedOff(LED_GREEN);
			}
		}
		TM_ILI9341_Puts(10, 5, str, &TM_Font_11x18, ILI9341_COLOR_GREEN, ILI9341_COLOR_GRAY);
	}
}