From f8795b892e9e20e1ed4993b670d3def6e6d16c0e Mon Sep 17 00:00:00 2001 From: Lukas Bachschwell Date: Wed, 22 Nov 2017 00:30:35 +0100 Subject: [PATCH] Rebuilding mouth loading system --- Shapes.h | 69 ++++++++++++++++++--------------------- SimpleExpressions.cpp | 75 +++++++++++++++++++++++++++---------------- SimpleExpressions.h | 9 ++++-- examples/mouth.ino | 2 +- 4 files changed, 86 insertions(+), 69 deletions(-) diff --git a/Shapes.h b/Shapes.h index 0594e82..587c376 100755 --- a/Shapes.h +++ b/Shapes.h @@ -1,47 +1,42 @@ #ifndef Shapes_h #define Shapes_h +struct Frame +{ + String name; + unsigned int data[7][3]; +} +typedef Frame; + //*********************************************************************************** //*********************************MOUTHS DEFINES************************************ //*********************************************************************************** - -const int zeros[7][3] = { -{0,0,0}, -{0,0,0}, -{0,0,0}, -{0,0,0}, -{0,0,0}, -{0,0,0}, -{0,0,0}, +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}, + } + }, + { + "happySimple", + { + {0,0,0}, + {0,150,0}, + {0,150,0}, + {0,150,0}, + {0,150,0}, + {0,0,0}, + {0,0,0}, + } + } }; -const int happySimple[7][3] = { -{0,0,0}, -{0,150,0}, -{0,150,0}, -{0,150,0}, -{0,150,0}, -{0,0,0}, -{0,0,0}, -}; - -const int testing[7][3] = { -{0,0,0}, -{0,150,0}, -{0,150,0}, -{0,150,0}, -{0,150,0}, -{0,0,0}, -{0,0,0}, -}; - - -//giving all moths a unique ID - -#define M_ZERO 0 -#define M_HAPPY_SIMPLE 1 -#define M_TESTING 2 - - #endif diff --git a/SimpleExpressions.cpp b/SimpleExpressions.cpp index d29f8b5..8358ab4 100755 --- a/SimpleExpressions.cpp +++ b/SimpleExpressions.cpp @@ -1,29 +1,19 @@ #include "Arduino.h" #include "SimpleExpressions.h" - - void SimpleExpressionsClass::init(int mouthPin, int buzzerPin) { mouth = Adafruit_NeoPixel(7, mouthPin, NEO_GRB + NEO_KHZ800); pinBuzzer = buzzerPin; - + pinMode(buzzerPin, OUTPUT); mouth.begin(); mouth.show(); + } /////////////////////////////////////////////////////////////////// -//-- MOUTHS & ANIMATIONS ----------------------------------------// +//-- MOUTHS ----------------------------------------// /////////////////////////////////////////////////////////////////// -unsigned long int SimpleExpressionsClass::getMouthShape(int number){ - unsigned long int types []={zero_code,one_code,two_code,three_code,four_code,five_code,six_code,seven_code,eight_code, - nine_code,smile_code,happyOpen_code,happyClosed_code,heart_code,bigSurprise_code,smallSurprise_code,tongueOut_code, - vamp1_code,vamp2_code,lineMouth_code,confused_code,diagonal_code,sad_code,sadOpen_code,sadClosed_code, - okMouth_code, xMouth_code,interrogation_code,thunder_code,culito_code,angry_code}; - - return types[number]; -} - unsigned long int SimpleExpressionsClass::getAnimShape(int anim, int index){ @@ -32,26 +22,22 @@ unsigned long int SimpleExpressionsClass::getAnimShape(int anim, int index){ void SimpleExpressionsClass::putAnimationMouth(unsigned long int aniMouth, int index){ - //ledmatrix.writeFull(getAnimShape(aniMouth,index)); } -void SimpleExpressionsClass::writeMouth(){ +void SimpleExpressionsClass::writeMouth(unsigned int mouthId){ + if(mouthId > sizeof(shapes)/sizeof(Frame*)) { + if(debug) Serial.println('mouth does not exist'); + } + writeMouthGeneric(shapes[mouthId].data); +} + +void SimpleExpressionsClass::writeMouthGeneric(const unsigned int mouthArray[7][3]) { for(uint16_t i=0; i<7; i++) { - mouth.setPixelColor(i, mouth.Color(happySimple[i][0], happySimple[i][1], happySimple[i][2])); + mouth.setPixelColor(i, mouth.Color(mouthArray[i][0], mouthArray[i][1], mouthArray[i][2])); } mouth.show(); } -void SimpleExpressionsClass::putMouth(unsigned long int mouth, bool predefined){ - - if (predefined){ - //ledmatrix.writeFull(getMouthShape(mouth)); - } - else{ - //ledmatrix.writeFull(mouth); - } -} - void SimpleExpressionsClass::clearMouth(){ for(uint16_t i=0; i