Int Int Float Float Void Setup Pinmode Serial Begin
Int Int Float Float Void Setup Pinmode Serial Begin
* AnalogInput
* by DojoDave <http://www.0j0.org>
*
* Modified for Graduate Student Workshop
* by David Rogerson - Physics Electronics Resource Center, University of Toro
nto
*
* Turns on and off a light emitting diode(LED) connected to digital
* pin 10. The amount of time the LED will be on and off depends on
* the value obtained by analogRead(). In this instance we are using a LM35
* temperature sensor
*
*/
int tempPin = 0;
int ledPin = 10;
float val = 0;
float temp = 0;
//
//
//
//
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
val = analogRead(tempPin);
digitalWrite(ledPin, HIGH);
delay(val);
digitalWrite(ledPin, LOW);
delay(val);
turn
stop
turn
stop
the
the
the
the
led pin
program
led pin
program
on
for some time
off
for some time
/*
* Full scale temp (1023) is 40 degrees and bottom scale (0) is 10 degrees
* Celsius value is then the temp range (30) times the a/d value divided
* by the full scale a/d value plus 10 degrees (a/d zero value)
*/
temp = 30 * val / 1023 + 10; // Convert the reading to Celsius value
Serial.println( "A/D val & Temp in C");
Celsius value
Serial.println( val, 0 );
Serial.println( temp, 1 );
decimal pt
Serial.println("");
}