Even if the Resistive touchscreens are way out of Cellphones today, they still are available in any electronics store and are very resourceful for the hobbyists.
The resistive touchscreen we will be using is a 4 wire touchscreen. why 4 wire? because it has 4 outputs.
Lets see how this works:
A resistive touchscreen is like a resistive bridge throughout the surface. I won’t be going deep inside its composition but how it works is, whenever we press anywhere it gives certain x axis resistance, and certain y axis resistance. and the resistance at every other point is very much unique. So what we have here is pretty much enough to use this magical tool to create something new.
How to poll the output:
It has 4 inputs. x, X’, y, Y’
to get the x axis value, we must put x as Vcc and X’ as Gnd. Then take input from y. And similarly to get Y axis value we must give y as VCC and Y’ as Gnd. So the touchscreen will act as a voltage divider. And we get an analog reading that we have to give to ADC and thats all it is.
How to make it use:
We can not touch a touchscreen at exact point so we will divide the touchscreen into some huge blocks like right now we will divide into 4 bigger blocks. and like you do the patterns on your cellphones the same way we will make swiping to operate a robot.
You will not get the exact value 0–>255 but it will be close, use it to form the blocks.
here is how you should poll: you will get values in x and y.
void poll_touch() { ADCSRA |= (1<<ADSC); while(!(ADCSRA & (1<<ADIF))) { ; } x=ADCH; ADMUX++; DDRA|=(1<<PA2) | (1<<PA0); DDRA&=~(1<<PA3); DDRA&=~(1<<PA1); PORTA=0x00; PORTA=0b00000100; _delay_ms(20); ADCSRA |= (1<<ADSC); while(!(ADCSRA & (1<<ADIF))) { ; } y=ADCH; ADMUX--; DDRA|=(1<<PA3) | (1<<PA1); DDRA&=~(1<<PA2); DDRA&=~(1<<PA0); PORTA=0x00; PORTA=0b00001000; _delay_ms(20); }
and like this i have divided the touchscreen into 4 blocks.
void decide_cell() { if(y<85) { celly=1; if(x<100) { cellx=1; } else { cellx=2; } } else { celly=2; if(x<100) { cellx=1; } else { cellx=2; } } if(celly==1) { if(cellx==1) cell=11; if(cellx==2) cell=12; } if(celly==2) { if(cellx==1) cell=21; if(cellx==2) cell=22; } }
By using threshold values i have made 4 blocks. SImilarly using more thresholds you can convert it into 9,16 or more than that block. What next? Its upto you. Make it to play piano sounds, swipe it to operate a bot. Infinite possibilities right? 😀
Have fun.