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 <ESPUI.h>
#include <Hippie.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";
@ -25,8 +37,9 @@ boolean moon_r = false;
boolean cruise = false;
boolean test_pos = false;
void setup()
{
void setup() {
pinMode(echoPin, INPUT );
pinMode(triggerPin, OUTPUT );
Serial.begin(115200);
WiFi.mode(WIFI_AP);
@ -37,6 +50,7 @@ void setup()
Serial.println(WiFi.softAPIP());
ESPUI.label("Distance", COLOR_CARROT, "0");
ESPUI.pad("Move", true, &buttonPad, COLOR_CARROT);
ESPUI.button("TT Swing", &ttSwingButton, COLOR_PETERRIVER);
ESPUI.button("Swing", &swingButton, COLOR_PETERRIVER);
@ -51,6 +65,13 @@ void setup()
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
- (int) pin of the upper left servo
@ -59,15 +80,40 @@ void setup()
- (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) {
if (type == B_DOWN) {
tt_swing = true;
}
else {
} else {
tt_swing = false;
}
}
@ -75,8 +121,7 @@ void ttSwingButton(Control c, int type) {
void swingButton(Control c, int type) {
if (type == B_DOWN) {
swing = true;
}
else {
} else {
swing = false;
}
}
@ -84,8 +129,7 @@ void swingButton(Control c, int type) {
void angryButton(Control c, int type) {
if (type == B_DOWN) {
jump = true;
}
else {
} else {
jump = false;
}
}
@ -93,8 +137,7 @@ void angryButton(Control c, int type) {
void jitterButton(Control c, int type) {
if (type == B_DOWN) {
jitter = true;
}
else {
} else {
jitter = false;
}
}
@ -102,8 +145,7 @@ void jitterButton(Control c, int type) {
void shakeButton(Control c, int type) {
if (type == B_DOWN) {
shake = true;
}
else {
} else {
shake = false;
}
}
@ -111,8 +153,7 @@ void shakeButton(Control c, int type) {
void bendButton(Control c, int type) {
if (type == B_DOWN) {
bend = true;
}
else {
} else {
bend = false;
}
}
@ -120,8 +161,7 @@ void bendButton(Control c, int type) {
void flapButton(Control c, int type) {
if (type == B_DOWN) {
flap = true;
}
else {
} else {
flap = false;
}
}
@ -129,8 +169,7 @@ void flapButton(Control c, int type) {
void moonLeftButton(Control c, int type) {
if (type == B_DOWN) {
moon = true;
}
else {
} else {
moon = false;
}
}
@ -138,8 +177,7 @@ void moonLeftButton(Control c, int type) {
void cruisatoButton(Control c, int type) {
if (type == B_DOWN) {
cruise = true;
}
else {
} else {
cruise = false;
}
}
@ -147,13 +185,11 @@ void cruisatoButton(Control c, int type) {
void moonRightButton(Control c, int type) {
if (type == B_DOWN) {
moon_r = true;
}
else {
} else {
moon_r = false;
}
}
void buttonPad (Control c, int value) {
switch (value) {
case P_LEFT_DOWN:
@ -189,24 +225,49 @@ void buttonPad (Control c, int value) {
}
}
// Ultrasonic Sensor
void loop()
{
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();
void checkDistance() {
int d = distance(triggerPin, echoPin);
ESPUI.print("Distance", String(d));
if (d < warningDistance) {
delay(100);
d = distance(triggerPin, echoPin);
if (d < warningDistance) {
if(!warning) {
SimpleExpressions.writeMouth("sadFull", 100, 0, 0);
SimpleExpressions.writeMouth("sadFull", 100, 0, 0); // only twice please
}
SimpleExpressions.playSound(S_CONFUSED);
warning = true;
}
} else {
if (warning) {
SimpleExpressions.writeMouth("happyFull", 0, 60, 100);
SimpleExpressions.writeMouth("happyFull", 0, 60, 100); // only twice please
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
//--------------------------------------------------------------
//-- (c) Juan Gonzalez-Gomez (Obijuan), Dec 2011