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); //???