Slide 17
Slide 17 text
Code
const int ledPin = 9; // the pin that the LED is attached to
const int switchAPin = 2; // the pin that the reed switch A is attached to
const int switchBPin = 3; // the pin that the reed switch B is attached to
const byte partialBrightness = 77; // 30% of brightness based in a 0 to 255 scale
const byte fullBrightness = 255; // 100% of brightness based in a 0 to 255 scale
const float distance = 0.10; // distance between reed switches (10 cm)
int switchAReading;
int switchBReading;
unsigned long switchATime;
unsigned long switchBTime;
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
analogWrite(ledPin, partialBrightness); // set LED brightness to 30%
// initialize the reed switches pins as inputs:
pinMode(switchAPin, INPUT);
pinMode(switchBPin, INPUT);
}