|
Intro to Physical Computing Syllabus Research & Learning Other Class pages
ITP Help Pages |
Second Week
Code from Class
//some constants for the pin that will never change
#define VarResistor 2
//make a variable to hold the values from the analog sensor (pot, photocell, thermisitor, etc)
//no need to initialize this particular one, but I do out of habit
int AnalogValue =0;
void setup(){
//start serial communication, this way we can see the values coming from the sensor
beginSerial(9600);
}
void loop(){
//read the value of the sensor or variable resistor
//and place it in our variable named AnalogValue
AnalogValue=analogRead(VarResistor);
//print the value of the resistor to the serial monitor
Serial.println(AnalogValue);
//take a moment to let the ADC "breathe"
delay(10);
}
//some constants for the pins that will never change
#define VarResistor 2
#define LEDPin 10
//make a variable to hold the values from the analog sensore (pot, photocell, thermisitor, etc)
//no need to initialize this particular one, but I do out of habit
int AnalogValue =0;
void setup(){
//declare the LEDPin to be an output
pinMode(LEDPin, OUTPUT);
//start serial communication, this way we can see the values coming from the sensor
beginSerial(9600);
}
void loop(){
//read the value of the sensor or variable resistor
//and place it n our variable named Analog Value
AnalogValue=analogRead(VarResistor);
//Dim or brighten up the LED based on the value from the sensor
//make sure to divide by 4 because the analog output only has 8 bits of information
//even though our input is 16 bits
analogWrite(LEDPin, AnalogValue/4);
//print the value of the resistor to the serial monitor
Serial.println(AnalogValue);
//take a moment to let the ADC "breathe"
delay(10);
}
|