This is another iteration of the previous assignment. The robots come into action during the day, and sleep during the night. So, shining some light on to a photo sensor makes them more active! When the amount of light is reduced, they go to sleep!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | #include <Servo.h> ; // The wiring assignment. #define SERVO_PIN 9 #define SENSORPIN 0 Servo servoSmall; Servo servoBig; Servo servoMed; void setup() { // Initialize the serial UART at 9600 bits per second. Serial.begin( 9600 ); // Initialize the Servo object to use the given pin for output. servoSmall.attach(SERVO_PIN); servoBig.attach( 7 ); servoMed.attach( 5 ); } void loop() { int sensorPhoto = analogRead(SENSORPIN); Serial.println(sensorPhoto); int timeDelay = 100 ; int smooth = 30 ; int sweepA = map(sensorPhoto, 400 , 950 , 20 , 130 ); int startA = 90 - sweepA / 2 ; int endA = 90 + sweepA / 2 ; for ( int i = startA; i <= endA; i=i + smooth) { servoSmall.write(i/ 4 ); servoBig.write(i); servoMed.write(i/ 2 ); delay(timeDelay); } for ( int i = endA; i <= startA; i=i + smooth) { servoSmall.write(i/ 4 ); servoBig.write(i); servoMed.write(i/ 2 ); delay(timeDelay); } } |
Leave a Reply
You must be logged in to post a comment.