int flexPin = A0;
int flexReading = 0;
int ledPin = D2;
int ledBrightness = 0;
int switchPin = D3;
void setup() {
pinMode( switchPin , INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
Particle.variable("floopy", flexReading );
Particle.variable("brightness", ledBrightness );
}
void loop() {
int buttonState = digitalRead( switchPin );
if( buttonState == LOW ) {
digitalWrite( ledPin, HIGH);
flexReading = analogRead(flexPin);
ledBrightness = map(flexReading, 100, 1500, 0, 255);
analogWrite(ledPin, ledBrightness);
delay(500);
}else{
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. .