![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
turns internal LEDs on and off
Dependencies: DmTouch_UniGraphic UniGraphic mbed
Diff: main.cpp
- Revision:
- 1:699abdc72e3c
- Parent:
- 0:448f8ee9d3f1
--- a/main.cpp Fri Jan 22 19:21:11 2016 +0000 +++ b/main.cpp Fri Jan 22 19:27:23 2016 +0000 @@ -42,14 +42,14 @@ PinName dataBus[]= {p30, p29, p28, p27, p26, p25, p24, p23}; ILI932x myLCD(BUS_8, dataBus, p15, p17, p16, p14, p20, "myLCD", 240, 320); // Bus 8 bit, bus pin array, CS, RST, DC, WR, RD, name, xpixels, ypixels DmTouch touch(DmTouch::DM_TFT24_104, p5, p6, p7, p8, p9); -char orient=3; -bool down, lastDown; +char orient=3; // orient horizontal is long axis +bool down, lastDown; // keeps track of whether or not the screen is/was pressed Timer t; DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); -uint16_t tx,ty; +uint16_t tx,ty; // coordinates for touch screen int main(){ @@ -75,36 +75,36 @@ // Touch screen demo - touch.setOrientation(orient); + touch.setOrientation(orient); // orient LCD screen down = false; bool justDown = false; - t.reset(); + t.reset(); // reset timer while (1) { - touch.readTouchData(tx, ty, down); + touch.readTouchData(tx, ty, down); // read if touch screen is pressed and where if (down){ - if(t.read_ms()>200){ - if ((110>tx) && (tx>50) && (90>ty) && (ty>30)) //toggle LED 1 - led1 = !led1; - if ((270>tx) && (tx>210) && (90>ty) && (ty>30)) //toggle LED 2 - led2 = !led2; - if ((110>tx) && (tx>50) && (210>ty) && (ty>150)) //toggle LED 3 - led3 = !led3; - if ((270>tx) && (tx>210) && (210>ty) && (ty>150)) //toggle LED 4 - led4 = !led4; + if(t.read_ms()>200){ // "debounce + if ((110>tx) && (tx>50) && (90>ty) && (ty>30)) // if touch screen is pressed in circle 1 + led1 = !led1; //toggle LED 1 + if ((270>tx) && (tx>210) && (90>ty) && (ty>30)) // if touch screen is pressed in circle 2 + led2 = !led2; //toggle LED 2 + if ((110>tx) && (tx>50) && (210>ty) && (ty>150)) // if touch screen is pressed in circle 3 + led3 = !led3; //toggle LED 3 + if ((270>tx) && (tx>210) && (210>ty) && (ty>150)) // if touch screen is pressed in circle 4 + led4 = !led4; //toggle LED 4 - t.reset(); + t.reset(); // reset timer wait(0.04); } - else if (justDown) { + else if (justDown) { // if it was just pressed but is no longer pressed - // no longer pressed, clean text + // necessary to prevent leds from blinking myLCD.locate(40, 20); myLCD.printf(" "); } - justDown = down; + justDown = down; } }