Touch panel module

    This page is to Setup and Config Touch panel module
 

Hardware and Software

Hardware 
    
Touch panel module

Software 
    Arduino IDE


Sanki Notes


Examples

          This example is ..........
  1. /*
    * Created By: Ankush Verma & Cory Malantonio
     * Kushy04@gmail.com
     * cgmalantonio@gmail.com
     *
     * Y- to analog 0
     * X+ to analog 1
     * Y+ to analog 2
     * X- to analog 3
     *
     */

    int xVal = 0;
    int yVal = 0;
    int touchX;
    int touchY;
    int xPos;
    int yPos;

    int redPin = 11;
    int greenPin = 9;
    int bluePin = 10;

    int rL = 0;
    int bL = 0;
    int gL = 0;


    void setup()
    {
      pinMode(redPin, OUTPUT);
      pinMode(bluePin, OUTPUT);
      pinMode(greenPin, OUTPUT);
      Serial.begin(38400);
    }


    void loop()
    {
      // Set up the analog pins in preparation for reading the Y value
      pinMode( A1, INPUT ); // Analog pin 1
      pinMode( A3, INPUT ); // Analog pin 3
      pinMode( A0, OUTPUT ); // Analog pin 0
      digitalWrite( A0, LOW ); //  Analog pin 0 as  GND connection
      pinMode( A2, OUTPUT ); // Analog pin 2
      digitalWrite( A2, HIGH ); //  Analog pin 2 as  +5V connection
      yVal = analogRead( 1 ); // Read the Y value

      // Set up the analog pins in preparation for reading the Y value
      // from the touchscreen
      pinMode( A0, INPUT ); // Analog pin 0
      pinMode( A2, INPUT ); // Analog pin 2
      pinMode( A1, OUTPUT ); // Analog pin 1
      digitalWrite( A1, LOW ); //  Analog pin 1 as  GND connection
      pinMode( A3, OUTPUT ); // Analog pin 3
      digitalWrite( A3, HIGH ); //  Analog pin 3 as  +5V connection
      xVal = analogRead( 0 ); // Read the x value


      //when touchscreen is not pressed it rests at certain coordinates
      //this makes sure the coordinates at rest don't get calculated
      touchX = xVal;
      if( touchX > 20 && touchX < 900 ) {

        ////   Here is where you need your minimum X value and Range of X
        ////  (touchX, minimum x, range of x, converts to 0-1024)
        xPos = map(touchX, 108.0, 899.0, 0, 1024); 


        xPos = constrain(xPos, 0, 1024);
      }
      touchY = yVal;
      if( touchY > 20 && touchY < 900 ) {

        ////   Here is where you need your minimum Y value and Range of Y
        ////  (touchY, minimum y, range of y, converts to 0-1024)
        yPos = map(touchY, 145.0, 892.0, 0, 1024);


        yPos = constrain(yPos, 0, 1024);
      }


      float brightness;
      brightness = int (yPos)/1024.0;
      //this lovely bit converts 0-1024, into three 255 values
      int value = int (xPos);
      float RGBslider = (float)value/1024.0;
      float redLevel   = 128.0 * ( 2 * cos( 2 * PI * (RGBslider + 0.125)));
      float greenLevel = 128.0 * ( 2 * cos( 2 * PI * (RGBslider + 0.375)));
      float blueLevel  = 128.0 * ( 2 * cos( PI * RGBslider));


      //allows values of color to be affected by value of brightness
      redLevel = redLevel * (brightness);
      greenLevel = greenLevel * (brightness);
      blueLevel = blueLevel * (brightness);

      /*
      if (redLevel > 255) redLevel = 255;
       if (redLevel < 0) redLevel = 0;
       if (greenLevel > 255) greenLevel = 255;
       if (greenLevel < 0) greenLevel = 0;
       if (blueLevel > 255) blueLevel = 255;
       if (blueLevel < 0) blueLevel = 0; 
       */
      //does same thing as section commented out above
      redLevel = constrain(redLevel, 0, 255);
      greenLevel = constrain(greenLevel, 0, 255);
      blueLevel = constrain(blueLevel, 0, 255);


      //rgb led's being used work backwards
      //0 = on || 255 = off
      //this reverses normal values
      rL = 255 - int(redLevel);
      bL = 255 - int(blueLevel);
      gL = 255 - int(greenLevel);


      analogWrite(redPin, rL);
      analogWrite(greenPin, gL);
      analogWrite(bluePin, bL);

      Serial.print(brightness);
      Serial.print(":");
      Serial.print(rL);
      Serial.print(".");
      Serial.print(gL);
      Serial.print(".");
      Serial.print(bL);
      Serial.print("-----");
      Serial.print(xPos);
      Serial.print(" / ");
      Serial.println(yPos); 

     //Serial.print(xPos);
     //Serial.println(yPos);

      delay(100);
    }