Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8621

SDK • Re: [PICO] 4 wires touch screen + RP2040 ADC = ghost touch ?

$
0
0
yep, that's what I've tried and it's far better with this code :

Code:

#include <stdio.h>#include "pico/stdlib.h"#include "hardware/gpio.h"#include "hardware/adc.h"// 4 wires touch panel#define XR 0#define YU 1#define XL 27#define YD 26int main(){    stdio_init_all();    adc_init();    while(true)    {        int x, y;        //        // Read X (YD=ADC, YU=Hi-Z, XR=0v, XL=3.3v)        adc_gpio_init(YD);        gpio_set_pulls(YD, false, true);        adc_select_input(YD-ADC_BASE_PIN);        //        gpio_init(YU);        gpio_set_dir(YU, GPIO_IN);        gpio_set_pulls(YU, false, true);        //        gpio_init(XR);        gpio_set_dir(XR, GPIO_OUT);        gpio_put(XR, true);        //        gpio_init(XL);        gpio_set_dir(XL, GPIO_OUT);        gpio_put(XL, false);        //        sleep_us(20);        //        x = 0;        for( int i=0 ; i<4 ; i++ )        {            sleep_us(10);            x += adc_read();        }        x >>= 2;        //        printf("(%d;", x);        //        // Read Y (XL=ADC, XR=Hi-Z, YU=0v, YD=3.3v)        adc_gpio_init(XL);        gpio_set_pulls(XL, false, true);        adc_select_input(XL-ADC_BASE_PIN);        //        gpio_init(XR);        gpio_set_dir(XR, GPIO_IN);        gpio_set_pulls(XR, false, true);        //        gpio_init(YU);        gpio_set_dir(YU, GPIO_OUT);        gpio_put(YU, false);        //        gpio_init(YD);        gpio_set_dir(YD, GPIO_OUT);        gpio_put(YD, true);        //        sleep_us(20);        //        y = 0;        for( int i=0 ; i<4 ; i++ )        {            sleep_us(10);            y += adc_read();        }        y >>= 2;        //        printf("%d)\r\n", y);        //        sleep_ms(1000);    }}
Thanks.

--- SOLVED ---

Statistics: Posted by Z3bc2G — Thu Feb 12, 2026 8:55 am



Viewing all articles
Browse latest Browse all 8621

Trending Articles