Hey all,
I’m not sure this is a hardware or “programmer” issue, but let me post it an see what the experts think.
First, I have no problem reading digital values on Pin 4 (Or any of the analog pins).
But, when I use readAnalog on a pot or voltage divided input, or even direct gnd, or direct +5, I only get the a constant value of 33x .
Here is my code:
Created by David Cuartielles
Modified 4 Sep 2010
By Tom Igoe
This example code is in the public domain.
*/
int sensorPin = 4; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
// pinMode(sensorPin,INPUT);
//digitalWrite(sensorPin,HIGH);
// digitalWrite(sensorPin, LOW);
Serial.begin(9600);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// sensorValue = 1020;
// sensorValue = digitalRead(sensorPin);
Serial.println(sensorValue, DEC);
// turn the ledPin on
digitalWrite(ledPin, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for for <sensorValue> milliseconds:
delay(sensorValue);
}
Output is: 336, 337,336,337,336 …
Notice the digital read setup/loop commands are commented out, but work fine when I switch to digital.
Using the same pin…
What am i doing wrong? or is my board a problem?
- Ken