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

Files at this revision

API Documentation at this revision

Comitter:
jprocter3
Date:
Mon Apr 22 18:55:43 2019 +0000
Parent:
14:7e45dbeb0acf
Commit message:
fixed i2c interrupt block

Changed in this revision

Servo.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 7e45dbeb0acf -r 02e772571d48 Servo.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Servo.lib	Mon Apr 22 18:55:43 2019 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/Servo/#36b69a7ced07
diff -r 7e45dbeb0acf -r 02e772571d48 main.cpp
--- a/main.cpp	Sat Apr 20 21:55:34 2019 +0000
+++ b/main.cpp	Mon Apr 22 18:55:43 2019 +0000
@@ -6,6 +6,7 @@
 #include "ultrasonic.h"
 #include "SDFileSystem.h"
 #include "wave_player.h"
+#include "Servo.h"
 uLCD_4DGL uLCD(p13,p14,p29); // serial tx, serial rx, reset pin;
 SDFileSystem sd(p5, p6, p7, p21, "sd"); //SD card
 AnalogOut DACout(p18);
@@ -15,6 +16,7 @@
 InterruptIn interrupt(p26);
 I2C i2c(p28, p27);
 Mpr121 mpr121(&i2c, Mpr121::ADD_VSS);
+Servo myservo(p22);
 
 DigitalOut led1(LED1);
 DigitalOut led2(LED2);
@@ -31,6 +33,8 @@
 
 void fallInterrupt() {
       touchpad = true;
+      mpr121.read(0x00);
+      mpr121.read(0x01);
 }
 
 void dist(int distance) {
@@ -40,9 +44,9 @@
             m1.stop(0);
             m2.stop(0);
             Thread::wait(100);
-            m1.speed(.75);
-            m2.speed(-.75);
-            Thread::wait(500);
+            m1.speed(.6);
+            m2.speed(-.6);
+            Thread::wait(400);
         } else {
             m1.speed(.5);
             m2.speed(.5);
@@ -150,6 +154,24 @@
     }
 }
 
+void tail(void const *argument) {
+    while(1) {
+        if (state == STOP && (touched || fed)) {
+            for(int i=0; i<100; i++) {
+                myservo = i/100.0;
+                Thread::wait(10);
+            }
+            for(int i=100; i>0; i--) {
+                myservo = i/100.0;
+                Thread::wait(10);
+            }
+        } else {
+            myservo = 0.5;   
+        }
+        Thread::wait(500);
+    }
+}
+
 int main() {
     uLCD.cls();
     uLCD.printf("Change baudrate.....");
@@ -171,6 +193,7 @@
     Thread thread2(touch);
     Thread thread3(screen);
     Thread thread4(sound);
+    Thread thread5(tail);
     
     while(1) {
         // Status LEDS