int potPin = A5;
int potRead = 0;
int ledPin = D2;
int ledBright = 0;
int switchPin = D3;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(switchPin, INPUT_PULLUP);
Particle.variable("pot", potRead);
Particle.variable("led", ledBright);
}
void loop() {
int switchStatus = digitalRead(switchPin);
if (switchStatus == LOW){ // if turning on the switch
potRead = analogRead(potPin);
// change the range of potRead
ledBright = map(potRead, 0, 4095, 0, 255);
analogWrite(ledPin, ledBright);
}else{ // if turning off the switch
digitalWrite(ledPin, LOW);
}
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .