Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #if 1
- //week 5, assignment 1 by Juuso
- void zmain(void)
- {
- //start real time clock and set time
- RTC_Start();
- RTC_TIME_DATE now;
- now.Hour = 23;
- now.Min = 59;
- now.Sec = 00;
- RTC_WriteTime(&now);
- printf("\nBoot\n");
- send_mqtt("Zumo11/time", "Boot");
- while(true)
- {
- //print current time when user button is pressed
- if (SW1_Read() == 0) {
- print_mqtt("Zumo11/time", "%2d:%02d.%02d\n", now.Hour, now.Min, now.Sec, SW1_Read());
- }
- vTaskDelay(1000);
- //function for clock
- now.Sec++;
- if(now.Sec==60)
- {
- now.Min+=1;
- now.Sec=0;
- }
- if(now.Min==60)
- {
- now.Hour+=1;
- now.Min=0;
- }
- if(now.Hour==24)
- {
- now.Hour=0;
- now.Min=0;
- now.Sec=0;
- }
- }
- }
- #endif
- #if 0 //Assignment 2
- void zmain(void)
- {
- while(true)
- {
- Ultra_Start();
- printf("\nBoot\n");
- send_mqtt("Zumo01/debug", "Boot");
- while(SW1_Read()) vTaskDelay(200);
- motor_start();
- motor_forward(100,0);
- while(true)
- {
- int dist = Ultra_GetDistance(); //Starts detecting distance
- printf("Distance = %d\r\n", dist);
- vTaskDelay(200); //Delay between distance scans
- if(dist <= 5)
- {
- randomturn();
- motor_forward(100,0);
- }
- }
- }
- }
- #endif
- int randomturn()
- {
- int randomdir1, randomdir2, randomdir;
- int turn = 262; //Value for a 90 degree turn
- randomdir = rand() % 2; //Calculates random direction for turning
- if(randomdir == 1) { //Ensures the tracks go in different directions
- randomdir1 = 1;
- randomdir2= 0;
- char direction[] ="left";
- print_mqtt("Zumo11/debug", "%s", direction); //Sends MQTT message
- printf("%s", direction);
- }
- else {
- randomdir1 = 0;
- randomdir2 = 1;
- char direction[] ="right";
- print_mqtt("Zumo11/debug", "%s", direction);
- printf("%s", direction);
- }
- SetMotors(randomdir1,randomdir2, 100, 100, turn); //calls SetMotors to perform the turn
- printf("randomturn = %d\rms\n", turn);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement