This commit is contained in:
Lukas Bachschwell 2017-12-12 21:21:44 +01:00
parent 651025f826
commit f928b025f0
2 changed files with 106 additions and 45 deletions

View File

@ -1,9 +1,21 @@
// This examples shows the Hippie Library used toghether with ESPUI Library by Lukas Bachschwelll on the ESP32 // This examples shows the Hippie Library used toghether with ESPUI and the SimleExpressions Library by Lukas Bachschwelll on the ESP32
#include <SimpleExpressions.h>
#include <WiFi.h> #include <WiFi.h>
#include <ESPUI.h> #include <ESPUI.h>
#include <Hippie.h> #include <Hippie.h>
#include <Oscillator.h> #include <Oscillator.h>
#define ledDataPin 39
#define beeperPin 36
#define echoPin 34
#define triggerPin 35
#define checkTime 1000
#define warningDistance 20
long oldTime = 0;
bool warning = false;
const char* ssid = "Hippie"; const char* ssid = "Hippie";
@ -25,8 +37,9 @@ boolean moon_r = false;
boolean cruise = false; boolean cruise = false;
boolean test_pos = false; boolean test_pos = false;
void setup() void setup() {
{ pinMode(echoPin, INPUT );
pinMode(triggerPin, OUTPUT );
Serial.begin(115200); Serial.begin(115200);
WiFi.mode(WIFI_AP); WiFi.mode(WIFI_AP);
@ -37,6 +50,7 @@ void setup()
Serial.println(WiFi.softAPIP()); Serial.println(WiFi.softAPIP());
ESPUI.label("Distance", COLOR_CARROT, "0");
ESPUI.pad("Move", true, &buttonPad, COLOR_CARROT); ESPUI.pad("Move", true, &buttonPad, COLOR_CARROT);
ESPUI.button("TT Swing", &ttSwingButton, COLOR_PETERRIVER); ESPUI.button("TT Swing", &ttSwingButton, COLOR_PETERRIVER);
ESPUI.button("Swing", &swingButton, COLOR_PETERRIVER); ESPUI.button("Swing", &swingButton, COLOR_PETERRIVER);
@ -51,6 +65,13 @@ void setup()
ESPUI.begin("Hippie Control Demo"); ESPUI.begin("Hippie Control Demo");
SimpleExpressions.init(ledDataPin, beeperPin);
SimpleExpressions.clearMouth();
SimpleExpressions.writeMouth("happySmall", 0, 0, 80);
SimpleExpressions.playSound(S_SUPER_HAPPY);
SimpleExpressions.writeMouth("happyFull", 0, 60, 100);
/* /*
This function is used to config Hippie, it has the following parameters This function is used to config Hippie, it has the following parameters
- (int) pin of the upper left servo - (int) pin of the upper left servo
@ -59,15 +80,40 @@ void setup()
- (int) pin of the lower right servo - (int) pin of the lower right servo
*/ */
hippie.init(25, 13, 26, 16); hippie.init(25, 26, 16, 13);
} }
void loop() {
if (millis() - oldTime > checkTime) {
checkDistance();
oldTime = millis();
}
if (walk_forward) hippie.new_walk();
else if (walk_backward) hippie.new_walk(2, 4, 750);
else if (turn_left) hippie.new_turn();
else if (turn_right) hippie.new_turn(2);
else if (shake) hippie.shakeLeg();
else if (jump) hippie.jump();
else if (swing) hippie.swing();
else if (tt_swing) hippie.tiptoeSwing();
else if (jitter) hippie.jitter();
else if (bend) hippie.bend();
else if (flap) hippie.flapping();
else if (moon) hippie.moonwalker();
else if (moon_r) hippie.moonwalker(1, 900, 50, -1);
else if (cruise) hippie.crusaito();
else if (test_pos) hippie.test_pos();
else hippie.home();
}
// UI Callbacks
void ttSwingButton(Control c, int type) { void ttSwingButton(Control c, int type) {
if (type == B_DOWN) { if (type == B_DOWN) {
tt_swing = true; tt_swing = true;
} } else {
else {
tt_swing = false; tt_swing = false;
} }
} }
@ -75,8 +121,7 @@ void ttSwingButton(Control c, int type) {
void swingButton(Control c, int type) { void swingButton(Control c, int type) {
if (type == B_DOWN) { if (type == B_DOWN) {
swing = true; swing = true;
} } else {
else {
swing = false; swing = false;
} }
} }
@ -84,8 +129,7 @@ void swingButton(Control c, int type) {
void angryButton(Control c, int type) { void angryButton(Control c, int type) {
if (type == B_DOWN) { if (type == B_DOWN) {
jump = true; jump = true;
} } else {
else {
jump = false; jump = false;
} }
} }
@ -93,8 +137,7 @@ void angryButton(Control c, int type) {
void jitterButton(Control c, int type) { void jitterButton(Control c, int type) {
if (type == B_DOWN) { if (type == B_DOWN) {
jitter = true; jitter = true;
} } else {
else {
jitter = false; jitter = false;
} }
} }
@ -102,8 +145,7 @@ void jitterButton(Control c, int type) {
void shakeButton(Control c, int type) { void shakeButton(Control c, int type) {
if (type == B_DOWN) { if (type == B_DOWN) {
shake = true; shake = true;
} } else {
else {
shake = false; shake = false;
} }
} }
@ -111,8 +153,7 @@ void shakeButton(Control c, int type) {
void bendButton(Control c, int type) { void bendButton(Control c, int type) {
if (type == B_DOWN) { if (type == B_DOWN) {
bend = true; bend = true;
} } else {
else {
bend = false; bend = false;
} }
} }
@ -120,8 +161,7 @@ void bendButton(Control c, int type) {
void flapButton(Control c, int type) { void flapButton(Control c, int type) {
if (type == B_DOWN) { if (type == B_DOWN) {
flap = true; flap = true;
} } else {
else {
flap = false; flap = false;
} }
} }
@ -129,8 +169,7 @@ void flapButton(Control c, int type) {
void moonLeftButton(Control c, int type) { void moonLeftButton(Control c, int type) {
if (type == B_DOWN) { if (type == B_DOWN) {
moon = true; moon = true;
} } else {
else {
moon = false; moon = false;
} }
} }
@ -138,8 +177,7 @@ void moonLeftButton(Control c, int type) {
void cruisatoButton(Control c, int type) { void cruisatoButton(Control c, int type) {
if (type == B_DOWN) { if (type == B_DOWN) {
cruise = true; cruise = true;
} } else {
else {
cruise = false; cruise = false;
} }
} }
@ -147,13 +185,11 @@ void cruisatoButton(Control c, int type) {
void moonRightButton(Control c, int type) { void moonRightButton(Control c, int type) {
if (type == B_DOWN) { if (type == B_DOWN) {
moon_r = true; moon_r = true;
} } else {
else {
moon_r = false; moon_r = false;
} }
} }
void buttonPad (Control c, int value) { void buttonPad (Control c, int value) {
switch (value) { switch (value) {
case P_LEFT_DOWN: case P_LEFT_DOWN:
@ -189,24 +225,49 @@ void buttonPad (Control c, int value) {
} }
} }
// Ultrasonic Sensor
void checkDistance() {
void loop() int d = distance(triggerPin, echoPin);
{ ESPUI.print("Distance", String(d));
if (walk_forward) hippie.new_walk(); if (d < warningDistance) {
else if (walk_backward) hippie.new_walk(2, 4, 750); delay(100);
else if (turn_left) hippie.new_turn(); d = distance(triggerPin, echoPin);
else if (turn_right) hippie.new_turn(2); if (d < warningDistance) {
else if (shake) hippie.shakeLeg(); if(!warning) {
else if (jump) hippie.jump(); SimpleExpressions.writeMouth("sadFull", 100, 0, 0);
else if (swing) hippie.swing(); SimpleExpressions.writeMouth("sadFull", 100, 0, 0); // only twice please
else if (tt_swing) hippie.tiptoeSwing(); }
else if (jitter) hippie.jitter(); SimpleExpressions.playSound(S_CONFUSED);
else if (bend) hippie.bend(); warning = true;
else if (flap) hippie.flapping(); }
else if (moon) hippie.moonwalker(); } else {
else if (moon_r) hippie.moonwalker(1, 900, 50, -1); if (warning) {
else if (cruise) hippie.crusaito(); SimpleExpressions.writeMouth("happyFull", 0, 60, 100);
else if (test_pos) hippie.test_pos(); SimpleExpressions.writeMouth("happyFull", 0, 60, 100); // only twice please
else hippie.home(); warning = false;
}
}
}
long US_init(int trigger_pin, int echo_pin)
{
digitalWrite(trigger_pin, LOW);
delayMicroseconds(2);
digitalWrite(trigger_pin, HIGH);
delayMicroseconds(10);
digitalWrite(trigger_pin, LOW);
return pulseIn(echo_pin, HIGH, 100000);
}
long distance(int trigger_pin, int echo_pin)
{
long microseconds = US_init(trigger_pin, echo_pin);
long distance;
distance = microseconds / 29 / 2;
if (distance == 0) {
distance = 999;
}
return distance;
} }

View File

@ -1,5 +1,5 @@
//-------------------------------------------------------------- //--------------------------------------------------------------
//-- Oscillator.pde //-- Oscillator
//-- Generate sinusoidal oscillations in the servos //-- Generate sinusoidal oscillations in the servos
//-------------------------------------------------------------- //--------------------------------------------------------------
//-- (c) Juan Gonzalez-Gomez (Obijuan), Dec 2011 //-- (c) Juan Gonzalez-Gomez (Obijuan), Dec 2011