Advertisements

Adafruit Touch-screen TFT LCD Rotation

The alert reader will have noted that the Kenmore 158 UI twisted around to a new orientation atop its fancy holder, with the USB port now poking out from the right side:

Kenmore 158 UI - PCB holder

Kenmore 158 UI – PCB holder

That lets me position the whole affair to the right of the sewing machine, in what seems to be its natural position, without having the cable form a loop that would push it off the platform. It’s not entirely clear how we’ll keep a straight cable from pulling it off, but that’s in the nature of fine tuning.

Anyhow, rotating the LCD isn’t a big deal, because the Adafruit library does all the heavy lifting:

// LCD orientation: always landscape, 1=USB upper left / 3=USB lower right
#define LCDROTATION 3

... snippage ...
tft.begin();
tft.setRotation(LCDROTATION);	// landscape, 1=USB upper left / 3=USB lower right

Flipping the touch screen coordinates required just interchanging the “to” bounds of the map() functions, with a conditional serving as institutional memory in the not-so-unlikely event I must undo this:

#if LCDROTATION == 1
	p->x = map(t.y, TS_Min.y, TS_Max.y, 0, tft.width());	// rotate & scale to TFT boundaries
	p->y = map(t.x, TS_Min.x, TS_Max.x, tft.height(), 0);	//   ... USB port at upper left
#elif LCDROTATION == 3
	p->x = map(t.y, TS_Min.y, TS_Max.y, tft.width(), 0);	// rotate & scale to TFT boundaries
	p->y = map(t.x, TS_Min.x, TS_Max.x, 0, tft.height());	//   ... USB port at lower right
#endif

And then It Just Worked.

Advertisements

, , ,