Back to Parent

int tiltPin = D3;
int motorPin = D2;
void setup()
{
  pinMode( tiltPin , INPUT_PULLUP ); 
  
  pinMode(motorPin, OUTPUT);
  
}
void loop()
{
    
    int tiltState = digitalRead( tiltPin );
    int speed = 100;
    
    if( tiltState == HIGH ) {
        for( int i = 0; i < 20; i++ ){
          analogWrite(motorPin, speed);
          delay(1000);
        }
    
    } else {
        analogWrite(motorPin, 0);
        delay(1000);
    }
}
Click to Expand

Content Rating

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

0