1
0
mirror of https://github.com/s00500/SimpleExpressions synced 2024-11-23 11:00:54 +00:00

Adding Shape instead of full color

This commit is contained in:
Lukas Bachschwell 2017-11-23 12:28:47 +01:00
parent 2c1608672a
commit d16566b824
4 changed files with 142 additions and 92 deletions

134
Shapes.h
View File

@ -4,75 +4,117 @@
struct Frame struct Frame
{ {
char name[20]; char name[20];
int data[7][3]; bool data[7];
} }
typedef Frame; typedef Frame;
struct MulticolorFrame
{
char name[20];
int data[7][3];
}
typedef MulticolorFrame;
//*********************************************************************************** //***********************************************************************************
//*********************************MOUTHS DEFINES************************************ //*********************************MOUTHS DEFINES************************************
//*********************************************************************************** //***********************************************************************************
#define shapeNumber 5 // add the current shape count here #define frameCount 18
// and don't make names longer than 20! #define colorFrameCount 1
// TODO: calculate me
const Frame shapes[] = { const Frame shapes[] = {
{ {
"zeros", "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", "happySmall",
{ {0, 0, 1, 1, 0, 0, 0}
{0,0,0},
{0,0,0},
{0,150,0},
{0,150,0},
{0,0,0},
{0,0,0},
{0,0,0}
}
}, },
{ {
"happyFull", "happyFull",
{ {0, 1, 1, 1, 1, 0, 0}
{0,0,0},
{0,150,0},
{0,150,0},
{0,150,0},
{0,150,0},
{0,0,0},
{0,0,0}
}
}, },
{ {
"sadSmall", "sadSmall",
{ {0, 0, 0, 0, 0, 1, 1}
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 150,0},
{0, 150,0}
}
}, },
{ {
"sadFull", "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}, {50,0,0},
{0,150,0}, {0,50,0},
{0,0,0}, {0,0,50},
{0,0,0}, {50,0,0},
{0,150,0}, {0,50,0},
{0,150,0}, {0,0,50},
{0,150,0} {50,0,0}
} }
} }
}; };

View File

@ -20,63 +20,71 @@ void SimpleExpressionsClass::init(int mouthPin, int buzzerPin) {
//-- MOUTHS ----------------------------------------// //-- MOUTHS ----------------------------------------//
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
/*
long int SimpleExpressionsClass::getAnimShape(int anim, int index){
}
void SimpleExpressionsClass::putAnimationMouth(int aniMouth, 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; int number = -1;
for(int i = 0; i < shapeNumber; i++){ for(int i = 0; i < frameCount; i++){
// perform on first encounter
//Serial.print("aname: ");
if(strncmp(shapes[i].name, mouthName, 20) == 0) { if(strncmp(shapes[i].name, mouthName, 20) == 0) {
//Serial.print("####################match ");
//Serial.println(shapes[i].name);
number = i; number = i;
break; break;
} }
} }
if(number != -1){ if(number != -1){
printMouthShape(number); printMouth(number, r, g, b);
} else { } else {
if(debug) Serial.println("Error: mouth name does not exist"); 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++) { 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(); 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]) { void SimpleExpressionsClass::writeMouthGeneric(const int mouthArray[7][3]) {
for(uint16_t i=0; i<7; i++) { for(uint16_t i=0; i<7; i++) {
mouth.setPixelColor(i, mouth.Color(mouthArray[i][0], mouthArray[i][1], mouthArray[i][2])); 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(); mouth.show();
} }

View File

@ -16,15 +16,18 @@ class SimpleExpressionsClass
void init(int mouthPin, int buzzerPin); 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 writeMouth(char mouthName[]);
void printMouthShape(int number); void printMouth(int number);
void clearMouth(); 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 writeMouthGeneric(const int mouthArray[7][3]);
void putAnimationMouth(int anim, int index); //void putAnimationMouth(int anim, int index);
//-- Sounds //-- Sounds
void _tone (float noteFrequency, long noteDuration, int silentDuration); void _tone (float noteFrequency, long noteDuration, int silentDuration);
@ -32,7 +35,7 @@ class SimpleExpressionsClass
void sing(int songName); void sing(int songName);
//-- Gestures //-- Gestures
void playGesture(int gesture); //void playGesture(int gesture);
private: private:

View File

@ -9,18 +9,15 @@ void setup() {
} }
void loop() { void loop() {
// for (int i = 0; i < 18; i++) {
SimpleExpressions.writeMouth("zeros"); SimpleExpressions.writeMouth("cross", 30, 0, 0);
delay(500); //Serial.println(i);
SimpleExpressions.printMouthShape(1); delay(1000);
delay(500); SimpleExpressions.writeMouth("hook", 0, 30, 0);
SimpleExpressions.writeMouth("happyFull"); delay(1000);
delay(500); SimpleExpressions.writeMouth("leftarrow", 0, 15, 30);
SimpleExpressions.writeMouth("zeros"); delay(1000);
delay(500); SimpleExpressions.writeMouth("rightarrow", 0, 15, 30);
SimpleExpressions.writeMouth("sadFull"); delay(1000);
delay(500); //}
SimpleExpressions.writeMouth("sadSmall");
delay(500);
} }