element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Help with Digital Pins and TFT Display
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 2 replies
  • Answers 1 answer
  • Subscribers 392 subscribers
  • Views 884 views
  • Users 0 members are here
  • digital_pins
  • programming
  • tft-lcd
  • digital-to-analog
  • arduino
  • newbie
Related

Help with Digital Pins and TFT Display

Former Member
Former Member over 10 years ago

Is it "syntaxly" correct if I plug in "digitalRead" wherever I see "analogRead" in a code meant to read from an analog pin? I'm trying to make my TFT LCD read from a digital pin, but I could find was a code that helped it read from an analog pin (http://arduino.cc/en/Tutorial/TFTDisplayText).

 

I'm using the analog version of that code to print information from a temperature sensor to the TFT LCD, but I'd also like to print values from ultrasonic range finder (URF) -- that uses a digital pin. At first, the URF and TFT LCD needed the same digital pin (pin 7) according to the code I used. I figured I couldn't get the digital value to print because the two used the same pin--since the URF didn't work when using any other pin, I switched the "cs" pin of the TFT to digital pin 4. It still displays fine, other than the absence of the URF's value.

 

Context:

- Board: Arduino Leonardo

- TFT Display/LCD Module with SD Card Reader (http://arduino.cc/en/Main/GTFT)

- Serial Port: /dev/tty.usbmodem1421

- Arduino version 1.0.6

- Goal: get TFT LCD to read from ultrasonic range finder.

 

Thanks for any replies in advance!

 

My Code: (I deleted the serial print parts and all others I deemed not relevant)

//create an instance of the library

TFT myScreen = TFT(cs, dc, rst);

 

// char array to print to the screen

char tempPrintout[6]; //[4] gives xx._, [5] gives xx.x

 

char soundPrintout[6]; //****For the URF!

 

void setup() {

....

Serial.begin(9600);

 

}

 

void loop() {

 

  // Read the value of the sensor on A1 (Temp sensor)

  String tempVal = String(analogRead(A1)* 0.48828125);

 

  // convert the reading to a char array

  tempVal.toCharArray(tempPrintout, 6); //changes decimal places

 

    // Read the value of the sensor on.....pin 7???

  String soundVal = String(digitalRead(pingPin)); //this doesn't work

 

  //convert the reading to a char array

  soundVal.toCharArray(soundPrintout, 6); //not sure if this should work

 

... //coding to format text

 

  // establish variables for duration of the ping,

  // and the distance result in inches and centimeters:

  long duration, cm; //inches

 

  // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.

  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:

  pinMode(pingPin, OUTPUT);

  digitalWrite(pingPin, LOW);

  delayMicroseconds(2);

  digitalWrite(pingPin, HIGH);

  delayMicroseconds(5);

  digitalWrite(pingPin, LOW);

 

  // The same pin is used to read the signal from the PING))): a HIGH pulse whose duration is the time (in microseconds) from the sending of the ping to the reception of its echo off of an object.

  pinMode(pingPin, INPUT);

  duration = pulseIn(pingPin, HIGH );

 

  myScreen.text(soundPrintout, 10, 40); //???

  • Sign in to reply
  • Cancel

Top Replies

  • clem57
    clem57 over 10 years ago +1 suggested
    A digitalRead on a pin determines is it on or off. Just two values. Do you have only two values for Temp? Looking at analogRead , the values returned are a range from say 0 to 1023. They convert analog…
  • clem57
    0 clem57 over 10 years ago

    A digitalRead on a pin determines is it on or off. Just two values. Do you have only two values for Temp? Looking at analogRead , the values returned are a range from say 0 to 1023. They convert analog to digital (ADC) and approximate as close as possible. On the arduino only pins labeled as PWM are analog capable. Look at datasheet for ultrasonic range finder (URF) to determine should it be digital or analog and pick the correct type. The variable pingPin should be set to that pin you physical set.

    Cheers,

    Clem

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to clem57

    Temp has a range of values, I actually use it to tell the temperature, after multiplying the value by 0.41.... The URF datasheet says that it should be connected to pin 7, so I declared that in the beginning. I tried plugging it into an analog pin, but it didn't work. Apparently, pin 7 on the arduino leonardo is labeled as PWM. In that case, I'll try converting the digital pin to an analog one: but should I be trying to change the nature of the pin or the data the pin returns (if that makes sense)?

     

    Thanks!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube