1
0
mirror of https://github.com/s00500/SimpleExpressions synced 2024-12-29 11:15:47 +00:00

Still memory issues

This commit is contained in:
Lukas Bachschwell 2017-11-22 13:50:16 +01:00
parent f8795b892e
commit e3d6ae422b
4 changed files with 104 additions and 17 deletions

View File

@ -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

View File

@ -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]));
}

View File

@ -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;

View File

@ -1,11 +1,29 @@
#include <SimpleExpressions.h>
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);
}