Back to Parent

//Set Up Variable 
int ledPin = D2;
//bool status = LOW;                                                     //control with phone 
int buttonPin = D3;

int buttonState; //store the reading from the button

int potPin = A5;
int potReading = 0;

void setup() {

    pinMode( ledPin, OUTPUT );
    
    pinMode( buttonPin, INPUT_PULLUP );
    
    Particle.variable("dial", potReading);
    
//    pinMode( potPin, INPUT );
    
  //  Particle.function( "controllight", handleControllight );
  // analog pins are by default inputs (no need to configure them.)
    
}

void loop() {
    
    buttonState = digitalRead( buttonPin );
//    int buttonReading = digitalRead( buttonPin );
    
    potReading = analogRead( potReading );
    
    //AnalogRead = value from 0-4095
//    potReading = analogRead( potPin );
    
//    int ledBrightness = map( potReading, 0, 4095, 0, 255 );
    
//    analogWrite( ledPin, ledBrightness );
    
//    buttonState = digitalRead( buttonPin );
    
    if( buttonReading == LOW )
    {
        
//        int ledBrightness = map( potReading, 0, 4095, 0, 255 );
        
  //      analogWrite( ledPin, ledBrightness );
        
  //     digitalWrite( ledPin, HIGH );
 //   }else{
//         digitalWrite( ledPin, HIGH );
//    }else{
  // delay( 2000 );
    
         digitalWrite( ledPin, LOW );
    }else{
        
        int ledBrightness = map(potReading,0, 4095, 0, 255);
        
        analogWrite(ledPin, ledBrightness);
    }
  // delay( 2000 );
//    }
  //  digitalWrite( led, status );
       delay( 500 );
    
    // repeat and repeat ..etc
}

//   int handleControllight( String command ){

//    if( command.equals( "on" ) ){
//        status = HIGH;
  //      digitalWrite( led, HIGH );
    //     delay( 200 );
     //     digitalWrite( led, LOW );
      //    delay( 200 );
    //       digitalWrite( led, HIGH );
     //    delay( 200 );
      //    digitalWrite( led, LOW );
    //      delay( 200 );
     //      digitalWrite( led, HIGH );
    //     delay( 200 );
    //      digitalWrite( led, LOW );
    //      delay( 200 );
    //    return 1;
//    }
 
//    if( command.equals( "off" ) ){
 //       status = LOW;
 //       return 0;
//    }
 //   return -1;
//}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0