![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
First Draft, serial print change based on distance
Diff: main.cpp
- Revision:
- 16:af15244242c2
- Parent:
- 15:d8ff594535fc
- Child:
- 17:02676e9bbc73
--- a/main.cpp Fri Feb 04 01:28:35 2022 +0000 +++ b/main.cpp Fri Feb 04 16:29:33 2022 +0000 @@ -11,9 +11,9 @@ * and back buttons it is sent to the specific start and back functions which sets * the flags which are then used in other functions. * -* the mu.startUpdates() is where the ultrasonic sensor is told to start measuring +* the Ultrasonic.startUpdates() is where the ultrasonic sensor is told to start measuring * the distances. -* the joystick and lcd are then initialised and the man menu function is then +* the joystick and lcd are then initialised and the main menu function is then * called. * *******************************************************************************/ @@ -28,7 +28,7 @@ Back.rise(Back_isr); // printf("set buttons"); - mu.startUpdates(); + Ultrasonic.startUpdates(); // printf ("Ultrasonic Updates started"); joystick.init(); @@ -297,7 +297,7 @@ while(1) { - mu.checkDistance(); + Ultrasonic.checkDistance(); if (Back_flag == 1) { Back_flag = 0; @@ -335,7 +335,7 @@ //sense = 1; - Distance1 = mu.getCurrentDistance(); + Distance1 = Ultrasonic.getCurrentDistance(); buzzer.beep(1000,2); wait(0.5); @@ -349,7 +349,7 @@ //sense = 2; - Distance2 = mu.getCurrentDistance(); + Distance2 = Ultrasonic.getCurrentDistance(); buzzer.beep(1000,2); wait(0.5); @@ -363,7 +363,7 @@ //sense = 3; - Distance3 = mu.getCurrentDistance(); + Distance3 = Ultrasonic.getCurrentDistance(); buzzer.beep(1000,2); wait(0.5); @@ -377,7 +377,7 @@ //sense = 4; - Distance4 = mu.getCurrentDistance(); + Distance4 = Ultrasonic.getCurrentDistance(); buzzer.beep(1000,2); wait(0.5); @@ -391,7 +391,7 @@ //sense = 5; - Distance5 = mu.getCurrentDistance(); + Distance5 = Ultrasonic.getCurrentDistance(); buzzer.beep(1000,2); wait(0.5); @@ -405,7 +405,7 @@ //sense = 6; - Distance6 = mu.getCurrentDistance(); + Distance6 = Ultrasonic.getCurrentDistance(); buzzer.beep(1000,2); wait(0.5); @@ -422,11 +422,23 @@ //printf("Distance 1 = %d\n", Distance1); //printf("glass[0] = %d\n", glass[0]); //printf("glass[6] = %d\n", glass[6]); - if (abs(Distance1 - glass[0]) <= 10 and abs(Distance2 - glass[1]) <= 10 and abs(Distance3 - glass[2]) <= 10 and abs(Distance4 - glass[3]) <= 10 and abs(Distance5 - glass[4]) <= 10 and abs(Distance6 - glass[5]) <= 10){ + if (abs(Distance1 - glass[0]) <= 5 and abs(Distance2 - glass[1]) <= 5 and abs(Distance3 - glass[2]) <= 5 and abs(Distance4 - glass[3]) <= 5 and abs(Distance5 - glass[4]) <= 5 and abs(Distance6 - glass[5]) <= 5){ printf("glass\n"); lcd.printString(" Object Found!",0,1); lcd.printString(" Pint Glass",0,3); lcd.refresh();} + + else if (abs(Distance1 - firestick_box[0]) <= 5 and abs(Distance2 - firestick_box[1]) <= 5 and abs(Distance3 - firestick_box[2]) <= 5 and abs(Distance4 - firestick_box[3]) <= 5 and abs(Distance5 - firestick_box[4]) <= 5 and abs(Distance6 - firestick_box[5]) <= 5){ + printf("Firestick Box\n"); + lcd.printString(" Object Found!",0,1); + lcd.printString(" Firestick Box",0,3); + lcd.refresh();} + + else if (abs(Distance1 - Disaronno_bottle[0]) <= 5 and abs(Distance2 - Disaronno_bottle[1]) <= 5 and abs(Distance3 - Disaronno_bottle[2]) <= 5 and abs(Distance4 - Disaronno_bottle[3]) <= 5 and abs(Distance5 - Disaronno_bottle[4]) <= 5 and abs(Distance6 - Disaronno_bottle[5]) <= 5){ + printf("Firestick Box\n"); + lcd.printString(" Object Found!",0,1); + lcd.printString(" Firestick Box",0,3); + lcd.refresh();} else{ printf("nothing\n");