From d16566b824ea9a96928b27d1e749e55a20125d16 Mon Sep 17 00:00:00 2001 From: Lukas Bachschwell Date: Thu, 23 Nov 2017 12:28:47 +0100 Subject: [PATCH] Adding Shape instead of full color --- Shapes.h | 134 +++++++++++++++++++++++++++--------------- SimpleExpressions.cpp | 64 +++++++++++--------- SimpleExpressions.h | 11 ++-- examples/mouth.ino | 25 ++++---- 4 files changed, 142 insertions(+), 92 deletions(-) diff --git a/Shapes.h b/Shapes.h index 71a85ef..9cf044e 100755 --- a/Shapes.h +++ b/Shapes.h @@ -4,75 +4,117 @@ struct Frame { char name[20]; - int data[7][3]; + bool data[7]; } typedef Frame; + +struct MulticolorFrame +{ + char name[20]; + int data[7][3]; +} +typedef MulticolorFrame; + //*********************************************************************************** //*********************************MOUTHS DEFINES************************************ //*********************************************************************************** -#define shapeNumber 5 // add the current shape count here -// and don't make names longer than 20! +#define frameCount 18 +#define colorFrameCount 1 + +// TODO: calculate me + const Frame shapes[] = { { "zeros", - { - {0,0,0}, - {0,0,0}, - {0,0,0}, - {0,0,0}, - {0,0,0}, - {0,0,0}, - {0,0,0} - } + {0, 0, 0, 0, 0, 0, 0} }, { "happySmall", - { - {0,0,0}, - {0,0,0}, - {0,150,0}, - {0,150,0}, - {0,0,0}, - {0,0,0}, - {0,0,0} - } + {0, 0, 1, 1, 0, 0, 0} }, { "happyFull", - { - {0,0,0}, - {0,150,0}, - {0,150,0}, - {0,150,0}, - {0,150,0}, - {0,0,0}, - {0,0,0} - } + {0, 1, 1, 1, 1, 0, 0} }, { "sadSmall", - { - {0, 0, 0}, - {0, 0, 0}, - {0, 0, 0}, - {0, 0, 0}, - {0, 0, 0}, - {0, 150,0}, - {0, 150,0} - } + {0, 0, 0, 0, 0, 1, 1} }, { "sadFull", + {0, 1, 0, 0, 1, 1, 1} + }, + { + "neutral", + {1, 1, 0, 0, 1, 0, 0} + }, + { + "circle", + {0, 1, 1, 1, 1, 1, 1} + }, + { + "center", + {1, 0, 0, 0, 0, 0, 0} + }, + { + "hook", + {1, 0, 0, 1, 1, 0, 1} + }, + { + "upsidedownhook", + {1, 0, 1, 0, 1, 1, 0} + }, + { + "kooh", + {1, 1, 1, 0, 0, 1, 0} + }, + { + "upsidedownkooh", + {1, 1, 0, 1, 0, 0, 1} + }, + { + "cross", + {1, 0, 1, 1, 0, 1, 1} + }, + { + "rect", + {0, 0, 1, 1, 0, 1, 1} + }, + { + "leftarrow", + {1, 1, 0, 1, 1, 1, 0} + }, + { + "rightarrow", + {1, 1, 1, 0, 1, 0, 1} + }, + { + "lefthalf", + {0, 0, 0, 1, 1, 1, 0} + }, + { + "righthalf", + {0, 1, 1, 0, 0, 0, 1} + }, +}; + + + + + +const MulticolorFrame colorShapes[] = { + { + "colorCircle", { - {0,0,0}, - {0,150,0}, - {0,0,0}, - {0,0,0}, - {0,150,0}, - {0,150,0}, - {0,150,0} + {50,0,0}, + {0,50,0}, + {0,0,50}, + {50,0,0}, + {0,50,0}, + {0,0,50}, + {50,0,0} } } }; diff --git a/SimpleExpressions.cpp b/SimpleExpressions.cpp index f3ae4de..d5833e7 100755 --- a/SimpleExpressions.cpp +++ b/SimpleExpressions.cpp @@ -20,63 +20,71 @@ void SimpleExpressionsClass::init(int mouthPin, int buzzerPin) { //-- MOUTHS ----------------------------------------// /////////////////////////////////////////////////////////////////// - -long int SimpleExpressionsClass::getAnimShape(int anim, int index){ - -} - - +/* void SimpleExpressionsClass::putAnimationMouth(int aniMouth, int index){ } - -/* -void SimpleExpressionsClass::writeMouth(unsigned int mouthId){ - if(mouthId > shapeNumber) { - if(debug) Serial.println("Error: mouth does not exist"); - return; - } - writeMouthGeneric(shapes[mouthId].data); -} */ -void SimpleExpressionsClass::writeMouth(char mouthName[] ){ +void SimpleExpressionsClass::writeMouth(char mouthName[], int r, int g, int b){ int number = -1; - for(int i = 0; i < shapeNumber; i++){ - // perform on first encounter - //Serial.print("aname: "); + for(int i = 0; i < frameCount; i++){ if(strncmp(shapes[i].name, mouthName, 20) == 0) { - //Serial.print("####################match "); - //Serial.println(shapes[i].name); number = i; break; } } if(number != -1){ - printMouthShape(number); + printMouth(number, r, g, b); } else { if(debug) Serial.println("Error: mouth name does not exist"); } } -void SimpleExpressionsClass::printMouthShape(int number) { +void SimpleExpressionsClass::printMouth(int number, int r, int g, int b) { for(uint16_t i = 0; i<7; i++) { - mouth.setPixelColor(i, mouth.Color(shapes[number].data[i][0], shapes[number].data[i][1], shapes[number].data[i][2])); + if(shapes[number].data[i]) mouth.setPixelColor(i, mouth.Color(r, g, b)); + else mouth.setPixelColor(i, 0); + } + mouth.show(); +} + +void SimpleExpressionsClass::writeMouth(char mouthName[] ){ + int number = -1; + for(int i = 0; i < colorFrameCount; i++){ + if(strncmp(shapes[i].name, mouthName, 20) == 0) { + number = i; + break; + } + } + if(number != -1){ + printMouth(number); + } else { + if(debug) Serial.println("Error: mouth name does not exist"); + } +} + +void SimpleExpressionsClass::printMouth(int number) { + for(uint16_t i = 0; i<7; i++) { + mouth.setPixelColor(i, mouth.Color(colorShapes[number].data[i][0], colorShapes[number].data[i][1], colorShapes[number].data[i][2])); } mouth.show(); } +void SimpleExpressionsClass::writeMouthGeneric(const bool mouthArray[7], int r, int g, int b) { + for(uint16_t i=0; i<7; i++) { + if(mouthArray[i]) mouth.setPixelColor(i, mouth.Color(r, g, b)); + else mouth.setPixelColor(i, 0); + } + mouth.show(); +} void SimpleExpressionsClass::writeMouthGeneric(const int mouthArray[7][3]) { for(uint16_t i=0; i<7; i++) { mouth.setPixelColor(i, mouth.Color(mouthArray[i][0], mouthArray[i][1], mouthArray[i][2])); } - for(uint16_t i = 0; i<7; i++) { - Serial.println(mouth.getPixelColor(i)); - } - Serial.println("#############"); mouth.show(); } diff --git a/SimpleExpressions.h b/SimpleExpressions.h index f2de401..eff1ec8 100755 --- a/SimpleExpressions.h +++ b/SimpleExpressions.h @@ -16,15 +16,18 @@ class SimpleExpressionsClass void init(int mouthPin, int buzzerPin); + void writeMouth(char mouthName[], int r, int g, int b); + void printMouth(int number, int r, int g, int b); + void writeMouth(char mouthName[]); - void printMouthShape(int number); + void printMouth(int number); void clearMouth(); - void writeMouthRecolored(int mouth, uint32_t color); + void writeMouthGeneric(const bool mouthArray[7], int r, int g, int b); void writeMouthGeneric(const int mouthArray[7][3]); - void putAnimationMouth(int anim, int index); + //void putAnimationMouth(int anim, int index); //-- Sounds void _tone (float noteFrequency, long noteDuration, int silentDuration); @@ -32,7 +35,7 @@ class SimpleExpressionsClass void sing(int songName); //-- Gestures - void playGesture(int gesture); + //void playGesture(int gesture); private: diff --git a/examples/mouth.ino b/examples/mouth.ino index 4a38eb6..7d13c70 100644 --- a/examples/mouth.ino +++ b/examples/mouth.ino @@ -9,18 +9,15 @@ void setup() { } void loop() { - - SimpleExpressions.writeMouth("zeros"); - delay(500); - SimpleExpressions.printMouthShape(1); - delay(500); - SimpleExpressions.writeMouth("happyFull"); - delay(500); - SimpleExpressions.writeMouth("zeros"); - delay(500); - SimpleExpressions.writeMouth("sadFull"); - delay(500); - SimpleExpressions.writeMouth("sadSmall"); - delay(500); - + // for (int i = 0; i < 18; i++) { + SimpleExpressions.writeMouth("cross", 30, 0, 0); + //Serial.println(i); + delay(1000); + SimpleExpressions.writeMouth("hook", 0, 30, 0); + delay(1000); + SimpleExpressions.writeMouth("leftarrow", 0, 15, 30); + delay(1000); + SimpleExpressions.writeMouth("rightarrow", 0, 15, 30); + delay(1000); + //} }