int potPin = A5;
int potReading = 0;
int ledPin = D2;
int ledBrightness = 0;
int buttonPin = D5;
void setup(){
pinMode(ledPin, OUTPUT);
pinMode( buttonPin , INPUT_PULLUP);
Spark.variable("pot", potReading );
}
void loop() {
int buttonState = digitalRead( buttonPin );
if( buttonState == LOW )
{
// digitalWrite( ledPin, HIGH);
potReading = analogRead(potPin);
ledBrightness = map(potReading, 0, 4095, 0, 255);
analogWrite(ledPin, ledBrightness);
delay(100);
}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. .