I had previously used the Adafruit TFT display using my library (ported from the Adafruit Arduino library). I decided to optimize the library to improve drawing speed. The same display I use comes with a 4-wire resistive touch-screen as well. I decided to write a simple library for the touch-screen and give Protothreads a try. To incorporate all this, I thought it would be cool if I used these to make a simple game. Tic-tac-toe came to mind as a fun little demo.
I'm sure everyone's familiar with the game so I won't explain the rules there. The touch-screen is simply two resistive sheets placed on top of each other on top of the TFT screen. When it is pressed down at a given place, the two sheets make contact and a voltage divider is formed. Using the IO's and the ADC, this voltage is read in the X and Y directions to register a touch.
Here is a very good pictorial depiction of the resistive touch screen (taken from the Atmel AVR341 document):
So in order to read the touch, the X+ and X- points are applied power, and one of Y+ or Y- is read to read the x-coordinate. Then Y+ and Y- are applied power and one of X+ or X- is read to read the y-coordinate. X+, X-, Y+ and Y- are connected to four GPIO pins on the PIC32 that are configured to outputs when driving the touch-screen and analog inputs when reading. Every time the IO pin switches state, a long delay is provided to allow the outputs to stabilize. Alternately, the ADC is significantly slowed down to negate effects of capacitive charging by high source impedance. The library is written in the form of a simple state machine cycling through its states every few milliseconds, decided by the application calling the library functions. In my application, I use 5 milliseconds.
To organize the game, I've made use of the Protothreads threading library. Protothreads is a very light-weight, stackless, threading library written entirely as C macros by Adam Dunkels. Bruce Land has ported Protothreads over for the PIC32. You can find more details on his excellent site: http://people.ece.cornell.edu/land/courses/ece4760//PIC32/index_Protothreads.html
There are two main executing threads, one is the main game thread and the other is a clock thread that keeps track of, and displays, time since the program was started. There is a third thread used to retrieve touch information. It is spawned by the main game thread when touch input is required. The main Protothreads functions (macros) I've made use of are:
PT_setup()
PT_INIT()
PT_SCHEDULE()
PT_SPAWN()
PT_WAIT_UNTIL()
PT_YIELD_TIME_msec()
PT_GET_TIME()
Pin connections:
BL (backlight): I left it unconnected, but you can connect it to 3.3V for backlight.
SCK: connected to RB14 on the PIC
MISO: left unconnected, since I'm not reading anything from the screen
MOSI: connected to RB11 on the PIC
CS: connected to RB1 on the PIC
SDCS: left unconnected as I'm not using the microSD card for this
RST: connected to RB2 on the PIC
D/C: connected to RB0 on the PIC
X+: connected to RA4 on the PIC
X-: connected to RB13 on the PIC
Y+: connected to RB5 on the PIC
Y-: connected to RB15 on the PIC
VIN: connected to 3.3V supply
GND: connected to gnd
Here is a demo of the game:
Besides the game itself, you can see the running clock on the bottom left right above the players' scores. To the bottom right you can see a flickering circle that is either green or red, depending on if it's player 1 or 2's turn, respectively. Once the game is over, you have the option of playing another game while score is being tracked.
Here is a link to the MPLABX project with all required header and source files:
https://drive.google.com/file/d/0B4SoPFPRNziHbURwVWVSN1c3VVE/view?usp=sharing
I have commented the code to make it fairly self-explanatory. If you have doubts or questions about anything, let me know and I'll add more detail. Let me know what you think!
nice work syed g.
ReplyDeleteHow do I calculate how many mosfet needed for a 1500w fullbridge inverter with very good efficiency.
ReplyDeleteI use 24vdc input.
I use irfp260n.
Thanks
I use either hip4081A or ir2110
ReplyDeleteHi Tahmid , Glad to see your work here. I have a question that is related to IR 2110. I want to understand the groud connection of high side driver with ac grid as a load in case of flyback inverter configuration.
ReplyDeleteThanks
Good work Tahmid, What optimizations have you made to the graphics library?
ReplyDeleteThis blog is about using of touch-screen.Cartincoupon.com
ReplyDeleteHello!
ReplyDeleteI think that Keep posting more informative articles like these one.
These are very good articles to visit...
gclub casino
goldenslot casino
goldenslot
What a nice Information are there in it.MyFirstSaving
ReplyDeleteGeorgia Football
ReplyDeleteGeorgia Football Game
Georgia College Football
Watch Georgia Football
Georgia Football Live
Georgia Football Live Stream
Clemson Football
Clemson Football Game
Clemson College Football
Watch Clemson Football
Clemson Football Live
Clemson Football Live Stream
Alabama Football
Alabama Football Game
Alabama College Football
Watch Alabama Football
Alabama Football Live
Alabama Football Live Stream
Michigan Football
Michigan Football Game
Michigan College Football
Watch Michigan Football
Michigan Football Live
Michigan Football Live Stream
Ohio State Football
Ohio State Football Game
Ohio State College Football
Watch Ohio State Football
Ohio State Football Live
Ohio State Football Live Stream
Nebraska Football
Nebraska Football Game
Nebraska College Football
Watch Nebraska Football
Nebraska Football Live
Nebraska Football Live Stream
Totally agree with your insights. In today's internet generation, the only way to get an edge in the market out there is to be visible using any other techniques know to men to be able to get the connection in the online community
ReplyDeletePDO Threads
thread lift
thread face lift
face thread lift
thread lift face
thread lift treatment
thread lift for face
thread lift procedure
non surgical thread face lift
skin threading face lift
neck thread lift
facelift with thread
thread neck lift
threading for face lift
fine thread lifting
thread lift neck
thread nose lift
non surgical facelift threading
thread lift surgery
polydioxanone thread lift
face lifting with threads
facelift by threading
non surgical thread lift
golden thread face lift
face lift thread facelift
nova lift face lift
I am quite interesting in this topic hope you will elaborate more on it in future posts. Keep it up the good work!
ReplyDeleteStanley Cup Playoffs
ReplyDeleteStanley Cup Playoffs 2018
NHL Playoffs
NHL Playoffs 2018
Stanley Cup Playoffs Live
Stanley Cup Playoffs Live Stream
Stanley Cup Playoffs 2018 Live
Stanley Cup Playoffs 2018 Live Stream
Watch Stanley Cup Playoffs Live
Watch Stanley Cup Playoffs Live Stream
How to watch Stanley Cup Playoffs 2018
NHL Playoff Games
NHL Playoff Games 2018
Interesting blog and great knowledge to share me thanks for sharing nice post.
ReplyDeleteprogrammable logic controller
tension controller
Kentucky Derby
ReplyDeleteKentucky Derby 2018
Kentucky Derby Live
Kentucky Derby 2018 Live
2018 Kentucky Derby
Kentucky Derby
Kentucky Derby 2018
Kentucky Derby Live
Kentucky Derby 2018 Live
2018 Kentucky Derby
GGG vs Martirosyan
GGG vs Martirosyan Live
Golovkin vs Martirosyan
Martirosyan vs GGG
dear sir,
ReplyDeletemy name is Than Toe Aung from mandaly.I am beginner of Arduino and PIC.I want to start my first project "arduino powered ac voltage stablizer" for my home.I have some difficulties on coding for unstable voltage like as wave,eg 121.5,119.8,120.3 and so on in 1minute. So I tried to search on google, than I get one.That is your voltage stabilizer project. I fairly read your code.But something else your project working on PIC, I need to use arduino. Please explain me for this code. "void StabilizeVoltage(void){
unsigned int ADS;
unsigned char V_LOW_CUT;
if (flgAC){
ADS = ADC_Get_Sample(Vin_CHANNEL);
Voltage_FLOAT = (float)((float)ADS * 5.0 * 101.0 * Kc) / (1.3836 * 1023.0); "
How i can use in arduino.
Thank you sir,
I am waiting for your reply.
It's great that you are telling us about these things.
ReplyDelete