Code for a robotic pet to interact with.
Dependencies: mbed wave_player Servo Motordriver mbed-rtos 4DGL-uLCD-SE SDFileSystem_OldbutworkswithRTOS HC_SR04_Ultrasonic_Library
Diff: main.cpp
- Revision:
- 14:7e45dbeb0acf
- Parent:
- 12:492f2a122e39
- Child:
- 15:02e772571d48
--- a/main.cpp Sat Apr 20 20:57:48 2019 +0000 +++ b/main.cpp Sat Apr 20 21:55:34 2019 +0000 @@ -87,16 +87,21 @@ uLCD.filled_rectangle(0, 0, 127, 127, BLACK); // clear screen switch(state) { case ROAM: { - uLCD.circle(64, 64, 50, BLUE); // blue circle in the center + uLCD.circle(64, 64, 30, BLUE); // blue circle in the center + uLCD.filled_circle(64, 64, 5, BLUE); // blue circle in the center } break; case STOP: { uLCD.locate(0,0); - if (energy < 30) { // tired + uLCD.text_width(12); + uLCD.text_height(12); + if (fed || touched) { // touched or fed + uLCD.text_width(9); + uLCD.text_height(9); + uLCD.color(RED); + uLCD.printf("<3"); + } else if (energy < 30) { // tired uLCD.color(RED+GREEN); uLCD.printf("0"); // yellow 0's - } else if (fed || touched) { // touched or fed - uLCD.color(RED); - uLCD.printf("<3"); } else { // wondering uLCD.color(BLUE); uLCD.printf("?"); // blue ?'s @@ -104,6 +109,8 @@ } break; case SLEEP: { uLCD.locate(0,0); + uLCD.text_width(12); + uLCD.text_height(12); uLCD.color(BLUE); uLCD.printf("Z"); // blue Z's } @@ -118,14 +125,16 @@ while(1) { switch(state) { case STOP: { - if (energy < 30) { // tired - wave_file=fopen("/sd/bark.wav","r"); // < 1 second - } else if (fed) { // fed + if (fed) { // fed wave_file=fopen("/sd/eat.wav","r"); // 2 seconds } else if (touched) { // touched wave_file=fopen("/sd/purr.wav","r"); // 3 seconds + } else if (energy < 30) { // tired + wave_file=fopen("/sd/bark.wav","r"); // < 1 second + Thread::wait(500); } else { // wondering wave_file=fopen("/sd/curious.wav","r"); // 1 second + Thread::wait(1000); } waver.play(wave_file); fclose(wave_file); @@ -146,11 +155,9 @@ uLCD.printf("Change baudrate....."); uLCD.baudrate(3000000); //jack up baud rate to max uLCD.background_color(BLACK); + uLCD.cls(); uLCD.text_bold(ON); uLCD.text_mode(OPAQUE); - uLCD.text_width(5); - uLCD.text_height(5); - uLCD.cls(); mu.startUpdates(); @@ -181,6 +188,9 @@ state = STOP; led1 = 0; led2 = 1; + } else if (state == STOP) { + Thread::wait(6000); // wait wondering for 5 seconds after touched or fed + state = ROAM; } else { state = ROAM; led1 = 1;