Back to Parent

//writing the code to have button input and flex sensor input

// name and assign the pin

int led = D2;
int led2= D5;
int buttonPin = D3; 
int buttonState; //Store the reading from Button
int flexPin = A2; //store data from Flex sensor


void setup() {
    
    pinMode (led, OUTPUT);
    pinMode (led2,OUTPUT);
    pinMode (buttonPin, INPUT_PULLUP);
    pinMode (flexPin, INPUT);

}

void loop() {
 
 int flexValue = analogRead(flexPin);
 
   buttonState = digitalRead(buttonPin);

   if (buttonState == LOW) {
       if (flexValue >=150){
       digitalWrite (led,HIGH);
       digitalWrite(led2,LOW);
       }
       else {
           digitalWrite (led,LOW);
           digitalWrite (led2,HIGH);
       }
      
   }else{
       digitalWrite (led,LOW);
       digitalWrite(led2,LOW);
   }   
  
  delay(500);
}
Click to Expand

Content Rating

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

0