From e3d6ae422b1fc3c8dbfd8f5c6aa801760dd4d943 Mon Sep 17 00:00:00 2001 From: Lukas Bachschwell Date: Wed, 22 Nov 2017 13:50:16 +0100 Subject: [PATCH] Still memory issues --- Shapes.h | 49 +++++++++++++++++++++++++++++++++++++------ SimpleExpressions.cpp | 40 ++++++++++++++++++++++++++++++----- SimpleExpressions.h | 12 ++++++----- examples/mouth.ino | 20 +++++++++++++++++- 4 files changed, 104 insertions(+), 17 deletions(-) diff --git a/Shapes.h b/Shapes.h index 587c376..69bbd5f 100755 --- a/Shapes.h +++ b/Shapes.h @@ -3,8 +3,8 @@ struct Frame { - String name; - unsigned int data[7][3]; + char name[20]; + int data[7][3]; } typedef Frame; @@ -12,7 +12,9 @@ typedef Frame; //*********************************MOUTHS DEFINES************************************ //*********************************************************************************** -const Frame shapes[] = { +#define shapeNumber 5 // add the current shape count here +// and don't make names longer than 20! +const PROGMEM Frame shapes[] = { { "zeros", { @@ -26,7 +28,19 @@ const Frame shapes[] = { } }, { - "happySimple", + "happySmall", + { + {0,0,0}, + {0,0,0}, + {0,150,0}, + {0,150,0}, + {0,0,0}, + {0,0,0}, + {0,0,0}, + } + }, + { + "happyFull", { {0,0,0}, {0,150,0}, @@ -36,7 +50,30 @@ const Frame shapes[] = { {0,0,0}, {0,0,0}, } - } + }, + { + "sadSmall", + { + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}, + {0, 150,0}, + {0, 150,0}, + } + }, + { + "sadFull", + { + {0,0,0}, + {0,150,0}, + {0,0,0}, + {0,0,0}, + {0,150,0}, + {0,150,0}, + {0,150,0}, + } + }, }; - #endif diff --git a/SimpleExpressions.cpp b/SimpleExpressions.cpp index 8358ab4..432ab26 100755 --- a/SimpleExpressions.cpp +++ b/SimpleExpressions.cpp @@ -15,23 +15,53 @@ void SimpleExpressionsClass::init(int mouthPin, int buzzerPin) { /////////////////////////////////////////////////////////////////// -unsigned long int SimpleExpressionsClass::getAnimShape(int anim, int index){ +long int SimpleExpressionsClass::getAnimShape(int anim, int index){ } -void SimpleExpressionsClass::putAnimationMouth(unsigned long int aniMouth, int index){ +void SimpleExpressionsClass::putAnimationMouth(int aniMouth, int index){ } +/* void SimpleExpressionsClass::writeMouth(unsigned int mouthId){ - if(mouthId > sizeof(shapes)/sizeof(Frame*)) { - if(debug) Serial.println('mouth does not exist'); + if(mouthId > shapeNumber) { + if(debug) Serial.println("Error: mouth does not exist"); + return; } writeMouthGeneric(shapes[mouthId].data); } +*/ -void SimpleExpressionsClass::writeMouthGeneric(const unsigned int mouthArray[7][3]) { +void SimpleExpressionsClass::writeMouth(char mouthName[] ){ + int number = -1; + for(int i = 0; i < shapeNumber; i++){ + // perform on first encounter + Serial.print("aname: "); + Serial.println(shapes[i].name); + if(strcmp(shapes[i].name, mouthName) == 0) { + Serial.println("match"); + number = i; + break; + } + } + if(number != -1){ + writeMouthGeneric(shapes[number].data); + } else { + if(debug) Serial.println("Error: mouth name does not exist"); + } +} + +void SimpleExpressionsClass::printMouthShape(int number) { + 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])); + } + 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])); } diff --git a/SimpleExpressions.h b/SimpleExpressions.h index 7d91b65..eaa4781 100755 --- a/SimpleExpressions.h +++ b/SimpleExpressions.h @@ -16,13 +16,15 @@ class SimpleExpressionsClass void init(int mouthPin, int buzzerPin); - void writeMouth(unsigned int mouth); + void writeMouth(char mouthName[]); + void printMouthShape(int number); + void clearMouth(); void writeMouthRecolored(int mouth, uint32_t color); - void writeMouthGeneric(const unsigned int mouthArray[7][3]); + void writeMouthGeneric(const int mouthArray[7][3]); - void putAnimationMouth(unsigned long int anim, int index); + void putAnimationMouth(int anim, int index); //-- Sounds void _tone (float noteFrequency, long noteDuration, int silentDuration); @@ -38,8 +40,8 @@ class SimpleExpressionsClass int pinBuzzer; - unsigned long int getMouthShape(int number); - unsigned long int getAnimShape(int anim, int index); + long int getMouthShape(int number); + long int getAnimShape(int anim, int index); }; extern SimpleExpressionsClass SimpleExpressions; diff --git a/examples/mouth.ino b/examples/mouth.ino index 732a536..b1cd14b 100644 --- a/examples/mouth.ino +++ b/examples/mouth.ino @@ -1,11 +1,29 @@ #include void setup() { + // put your setup code here, to run once: + Serial.begin(115200); SimpleExpressions.init(13, 14); - SimpleExpressions.writeMouth(1); } void loop() { + SimpleExpressions.printMouthShape(0); + //SimpleExpressions.writeMouth("zeros"); + delay(500); + SimpleExpressions.printMouthShape(1); + //SimpleExpressions.writeMouth("happySmall"); + delay(500); + //SimpleExpressions.writeMouth("happyFull"); + SimpleExpressions.printMouthShape(2); + delay(500); + SimpleExpressions.printMouthShape(3); + //SimpleExpressions.writeMouth("zeros"); + delay(500); + //SimpleExpressions.writeMouth("sadSmall"); + SimpleExpressions.printMouthShape(4); + delay(500); + + }