Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #if 1
- //ultrasonic sensor//
- void motor_tankturn(int turn_speed, int delay);
- void motor_tankturn_random(void);
- void zmain(void)
- {
- bool OnOff = false;
- Ultra_Start(); // Ultra Sonic Start function
- motor_stop();
- while(true) { // Waits for users button press to start
- if(SW1_Read() == 0) {
- printf("\nStarting...\n");
- motor_start();
- motor_forward(0,0);
- OnOff = true;
- break;
- }
- }
- while(OnOff) {
- int d = Ultra_GetDistance();
- if ( d <= 10 )
- {
- printf("WARNING! Distance to obstacle: %dcm\r\n", d);
- motor_forward(0,0);
- motor_backward(100,400);
- motor_backward(0,0);
- motor_tankturn_random();
- /*motor_tankturn(53,990);*/
- vTaskDelay(500);
- } else {
- // Print the detected distance (centimeters)
- printf("distance = %d\r\n", d);
- motor_forward(50,200);
- motor_forward(0,0);
- }
- }
- }
- void motor_tankturn(int turn_speed, int delay)
- {
- SetMotors(0,0,turn_speed, 0,delay);
- motor_forward(0,0);
- }
- void motor_tankturn_random(void)
- {
- int delay = (rand() % (2965 +1 - 990) + 990);
- int leftright = (rand() % (1 + 1));
- printf("\n%d ", leftright);
- printf("- %d\n", delay);
- if (leftright == 1) {
- SetMotors(0,0,53, 0,delay);
- } else {
- SetMotors(0,0,0,53,delay);
- }
- motor_forward(0,0);
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement