// main time constants #define NumberOfPhotos 3 #define PhotoSavingTime 200 #define InitialWait 700 // shutter release time constants #define ConfirmShutter 30 #define PressedShutter 40 #define UnpressShutter 50 // motors & sensors #define RotationMotor OUT_A #define ShutterMotor OUT_C #define ShutterSense SENSOR_1 #define RotationSense SENSOR_2 #define CalibrateTime 15 #define Hyster 10 #define CountPerTurn 80 // Threshold for the light sensor encoder int Threshold; // Position of the panoramic head int RotAngle; int count=0; task main() { SetSensor(ShutterSense,SENSOR_TOUCH); SetSensorType(RotationSense,SENSOR_TYPE_LIGHT); SetSensorMode(RotationSense,SENSOR_MODE_RAW); SetPower(RotationMotor,2); Wait(InitialWait); Calibrate(); RotAngle=0; start CountRotation; while (count < NumberOfPhotos) { count++; PlaySound(1); ShutterRelease(); Wait(PhotoSavingTime); OnRev(RotationMotor); until (RotAngle >= (count * CountPerTurn)/NumberOfPhotos); Off(RotationMotor); } Float(RotationMotor+ShutterMotor); StopAllTasks(); } // As name implies, press the shutter release button... sub ShutterRelease() { OnRev(ShutterMotor); until (ShutterSense == 1); Wait(ConfirmShutter); Off(ShutterMotor); Wait(PressedShutter); OnFwd(ShutterMotor); Wait(UnpressShutter); Off(ShutterMotor); } // Measures the light in white and black zones of the encoder // and place the threshold in-between // As an added bonus, finish by rotating the head in forward direction, // thus compensating looseness of gears sub Calibrate() { int low = 1000; int high = 0; int temp; Wait(50); OnFwd(RotationMotor); repeat (CalibrateTime) { temp = RotationSense; if (temp < low) { low = temp; } if (temp > high) { high = temp; } Wait(1); } Off(RotationMotor); Wait(50); OnRev(RotationMotor); repeat (CalibrateTime) { temp = RotationSense; if (temp < low) { low = temp; } if (temp > high) { high = temp; } Wait(1); } Off(RotationMotor); Wait(50); Threshold = (high+low)/2; } //Counts the number of transitions between black and white task CountRotation() { while (true) { until (RotationSense < Threshold - Hyster); RotAngle++; until (RotationSense > Threshold + Hyster); RotAngle++; } }