top of page
Writer's pictureTwinkle Desai

[Arduino Quiz] Sunflower



#include <Servo.h>


int sensorPin = A0;

int servoPin = 9;


int sensorValue = 0;

int servoGrad = 90;

int tolerance = 40;


Servo myservo;


void setup() {

pinMode( sensorPin, INPUT);

myservo.attach( servoPin );

myservo.write( servoGrad );

}


void loop() {

sensorValue = analogRead(sensorPin);

if ( sensorValue < (512-tolerance) )

{

if (servoGrad < 180) servoGrad++;

}


if ( sensorValue > (512+tolerance) )

{

if (servoGrad > 0) servoGrad--;

}


myservo.write( servoGrad );


delay(100);

}


14 views1 comment

Recent Posts

See All

1 komentář


Johnny
Johnny
07. 3. 2019

Great job! even though you don't include image file, it looks good! your grade is 90

To se mi líbí
bottom of page