int pwmPin = 11; // The Arduino can turn on and off pwn fast.
// This can make LED appear dimmer, and motors turn slower.
// This depends how much they are 'on' and 'off.'
// Only pins 3,5,6,9,10,11 can do this. They are shown with a '~' on the Arduino.
int potPin = 19; // Pin A5 is the same as pin 19. This matches the ThinkerShield location.
// A Potentiometer or LDR can be used for analog inputs.
// The LDR on the ThinkerShield is at A4.
int ldrPin = A4;
void setup() {
Serial.begin(9600);
pinMode(pwmPin, OUTPUT);
pinMode(potPin, INPUT);
pinMode(ldrPin, INPUT);
}//EOS
// This loop reads the 2 values, calculated the difference, coverts to 8bit, and dims the LED.
void loop() {
// The analog value 0-1023 is saved to this variable.
int potentiometerValue = analogRead(potPin);
int ldrValue = analogRead(ldrPin);
int pot_Minus_ldr = abs(potentiometerValue - ldrValue);
// The analog value is 'mapped' to the 8bit values (0-255).
// 0 is LOW. 255 is HIGH. 128 is 50%.
int pwmValue = map (pot_Minus_ldr, 0, 1023, 0, 255);
//The values are sent to the Serial Monitor.
Serial.println((String)"Potentiometer Value:" + potentiometerValue + " LDR Value: " + ldrValue + " Difference: " + pot_Minus_ldr + " PWM Value: " + pwmValue );
// analogWrite is used instead of digitalWrite.
analogWrite(pwmPin, pwmValue);
// the delay command stops the Arduino working ridiculously fast.
// Your loop should always contain at least one delay.
delay (500);
} //EOL