//FAILURE:
// THE CODE TO CONTROL BRIGHTNESS THAT DID NOT WORK
// Definitions
int TOUCH_PIN_IN = A1; // Pin connected to SIG at Touch-Sensor
int LED_PIN = D2; // LED pin GREEN
int LED_PIN2 = D5; // LED pin BLUE
int photoCellPin = A0;
int photoCellReading = 0;
int TOUCH_PIN_INReading = 0;
// Create variable to store the LED brightness
int ledBrightness = 25;
int moistPin = A2;
int moistVal = 0; // Create variable to read soil moisture
unsigned long lastmillis = 0; // time for interation the loop
void setup()
{
pinMode(TOUCH_PIN_IN, INPUT);
pinMode(LED_PIN, OUTPUT);
pinMode(LED_PIN2, OUTPUT);
Serial.begin(9600);
// take readings of variables
Particle.variable("pressure", &TOUCH_PIN_INReading, INT);
Particle.variable("daylight", &photoCellReading, INT);
Particle.variable("waterlevel", &moistVal, INT);
Particle.function("LED Brightness",brightnessControl);
}
int brightnessControl(String command)
{
ledBrightness=command.toInt(); // convert toiint val
if( bright > 255 ) return -1; // take values only from 25-255
if( bright < 25 ) return -1;
return 1;
}
void readData() {
int proximity = digitalRead(TOUCH_PIN_IN); // Read the state of the sensor
if (proximity == HIGH) // when leaf is touched
{
for (int i=25 ; i<255 ; i=i+20) // glow or increase in brightness should be gradual
{
if(i<200){
analogWrite(LED_PIN, i); // Turn the leaf on full glow
delay(100);}
else{
analogWrite(LED_PIN, i);
delay(2500); // stay on glow for some time
}
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. .