int ledPin = D2;
int ledBrightness = 0;
int ledBrightnessB = 0;
int ledBrightness1 = 0; // variable from photoCell sensor
int ledBrightness2 = 0; // variable from bending sensor
int ledState = LOW;
int photoCellPin = A0;
int photoCellReading = 0;
int bendPin = A5;
int bendReading = 0;
void setup() {
//set the LED to output
pinMode(ledPin, OUTPUT);
Particle.variable( "photolight", &photoCellReading, INT );
Particle.variable( "bent", &bendReading, INT );
Particle.variable( "light", ledBrightness ); // console variables connecting.
}
void loop() {
// Use analogRead to read the photo cell reading
// This gives us a value from 0 to 4095
photoCellReading = analogRead( photoCellPin );
bendReading = analogRead( bendPin );
ledBrightness1 = map( photoCellReading, 3000, 1700, 0, 255); //LED brightness 0-255(adjust the value range)
ledBrightness2 = map( bendReading, 1000, 1250, 0, 255);
ledBrightness = (ledBrightness1 + ledBrightness2) / 2;
analogWrite( ledPin, ledBrightness );
delay( 100 );
}
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. .