int flexSens =A0;
int YellowPin=D2;
int GreenPin=D3;
int ledBrightness;
int flexSensReading;
void setup() {
pinMode(YellowPin, OUTPUT);
pinMode(GreenPin, OUTPUT);
pinMode(flexSens, INPUT);
Particle.variable("power",&flexSensReading, INT);
}
void loop() {
//analogRead reads the sensor, and gives a value from 0 to 4095
flexSensReading =analogRead (flexSens);
//We want to map this value into the PWM range of 0-255
ledBrightness = map(flexSensReading, 0, 4095, 0, 255);
if(flexSensReading<=1000){
analogWrite(YellowPin, ledBrightness);
}
//fade the LED to the desired brightness, sets the value
else if (flexSensReading >2000){
analogWrite(YellowPin, ledBrightness);
analogWrite(GreenPin, ledBrightness);
}
//waits and then loops
delay(100);
digitalWrite(YellowPin, LOW);
digitalWrite(GreenPin, 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. .