mirror of
https://github.com/s00500/SimpleExpressions
synced 2024-11-21 12:50:54 +00:00
Improving ESP32 LED Handeling, versionbump
This commit is contained in:
parent
10c656448b
commit
5618498992
@ -1,5 +1,5 @@
|
|||||||
name=SimpleExpressions
|
name=SimpleExpressions
|
||||||
version=1.1.0
|
version=1.1.1
|
||||||
author=Lukas Bachschwell
|
author=Lukas Bachschwell
|
||||||
maintainer=Lukas Bachschwell <lukas@lbsfilm.at>
|
maintainer=Lukas Bachschwell <lukas@lbsfilm.at>
|
||||||
sentence=Make you Robots cute and noisy
|
sentence=Make you Robots cute and noisy
|
||||||
|
@ -31,13 +31,13 @@ void SimpleExpressionsClass::initBuzzer(int aBuzzerPin) {
|
|||||||
|
|
||||||
void SimpleExpressionsClass::writeMouth(const char mouthName[], int r, int g, int b) {
|
void SimpleExpressionsClass::writeMouth(const char mouthName[], int r, int g, int b) {
|
||||||
int number = -1;
|
int number = -1;
|
||||||
for(int i = 0; i < frameCount; i++){
|
for(int i = 0; i < frameCount; i++) {
|
||||||
if(strncmp(shapes[i].name, mouthName, 20) == 0) {
|
if(strncmp(shapes[i].name, mouthName, 20) == 0) {
|
||||||
number = i;
|
number = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(number != -1){
|
if(number != -1) {
|
||||||
printMouth(number, r, g, b);
|
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");
|
||||||
@ -49,20 +49,20 @@ void SimpleExpressionsClass::printMouth(int number, int r, int g, int b) {
|
|||||||
if(shapes[number].data[i]) mouth.setPixelColor(i, mouth.Color(r, g, b));
|
if(shapes[number].data[i]) mouth.setPixelColor(i, mouth.Color(r, g, b));
|
||||||
else mouth.setPixelColor(i, 0);
|
else mouth.setPixelColor(i, 0);
|
||||||
}
|
}
|
||||||
mouth.show();
|
showMouth();
|
||||||
delay(1);
|
delay(1);
|
||||||
clearPixels();
|
clearPixels();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleExpressionsClass::writeMouth(const char mouthName[] ) {
|
void SimpleExpressionsClass::writeMouth(const char mouthName[] ) {
|
||||||
int number = -1;
|
int number = -1;
|
||||||
for(int i = 0; i < colorFrameCount; i++){
|
for(int i = 0; i < colorFrameCount; i++) {
|
||||||
if(strncmp(shapes[i].name, mouthName, 20) == 0) {
|
if(strncmp(shapes[i].name, mouthName, 20) == 0) {
|
||||||
number = i;
|
number = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(number != -1){
|
if(number != -1) {
|
||||||
printMouth(number);
|
printMouth(number);
|
||||||
} else {
|
} else {
|
||||||
if(debug) Serial.println("Error: mouth name does not exist");
|
if(debug) Serial.println("Error: mouth name does not exist");
|
||||||
@ -73,7 +73,7 @@ void SimpleExpressionsClass::printMouth(int number) {
|
|||||||
for(uint16_t i = 0; i<7; i++) {
|
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.setPixelColor(i, mouth.Color(colorShapes[number].data[i][0], colorShapes[number].data[i][1], colorShapes[number].data[i][2]));
|
||||||
}
|
}
|
||||||
mouth.show();
|
showMouth();
|
||||||
delay(1);
|
delay(1);
|
||||||
clearPixels();
|
clearPixels();
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ void SimpleExpressionsClass::writeMouthGeneric(const bool mouthArray[7], int r,
|
|||||||
if(mouthArray[i]) mouth.setPixelColor(i, mouth.Color(r, g, b));
|
if(mouthArray[i]) mouth.setPixelColor(i, mouth.Color(r, g, b));
|
||||||
else mouth.setPixelColor(i, 0);
|
else mouth.setPixelColor(i, 0);
|
||||||
}
|
}
|
||||||
mouth.show();
|
showMouth();
|
||||||
delay(1);
|
delay(1);
|
||||||
clearPixels();
|
clearPixels();
|
||||||
}
|
}
|
||||||
@ -93,7 +93,7 @@ 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]));
|
||||||
}
|
}
|
||||||
mouth.show();
|
showMouth();
|
||||||
delay(1);
|
delay(1);
|
||||||
clearPixels();
|
clearPixels();
|
||||||
}
|
}
|
||||||
@ -103,7 +103,7 @@ void SimpleExpressionsClass::clearMouth() {
|
|||||||
for(int i = 0; i < 7; i++) {
|
for(int i = 0; i < 7; i++) {
|
||||||
mouth.setPixelColor(i, 0);
|
mouth.setPixelColor(i, 0);
|
||||||
}
|
}
|
||||||
mouth.show();
|
showMouth();
|
||||||
delay(1);
|
delay(1);
|
||||||
clearPixels();
|
clearPixels();
|
||||||
}
|
}
|
||||||
@ -115,13 +115,26 @@ void SimpleExpressionsClass::clearPixels() { // avoid strange issues on ESP32 wi
|
|||||||
}
|
}
|
||||||
delay(1);
|
delay(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SimpleExpressionsClass::showMouth() {
|
||||||
|
#if defined(ESP32)
|
||||||
|
portDISABLE_INTERRUPTS();
|
||||||
|
mouth.show();
|
||||||
|
delay(1);
|
||||||
|
portENABLE_INTERRUPTS();
|
||||||
|
clearPixels();
|
||||||
|
#else
|
||||||
|
mouth.show();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////
|
||||||
//-- SOUNDS -----------------------------------------------------//
|
//-- SOUNDS -----------------------------------------------------//
|
||||||
///////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
void SimpleExpressionsClass::_tone (float noteFrequency, long noteDuration, int silentDuration){
|
void SimpleExpressionsClass::_tone (float noteFrequency, long noteDuration, int silentDuration){
|
||||||
if(silentDuration==0){silentDuration=1;}
|
if(silentDuration==0) {silentDuration=1;}
|
||||||
|
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
ledcWriteTone(ledc_channel, noteFrequency);
|
ledcWriteTone(ledc_channel, noteFrequency);
|
||||||
@ -142,7 +155,7 @@ void SimpleExpressionsClass::bendTones (float initFrequency, float finalFrequenc
|
|||||||
// bendTones (880, 2093, 1.02, 18, 1);
|
// bendTones (880, 2093, 1.02, 18, 1);
|
||||||
// bendTones (note_A5, note_C7, 1.02, 18, 0);
|
// bendTones (note_A5, note_C7, 1.02, 18, 0);
|
||||||
|
|
||||||
if(silentDuration==0){silentDuration=1;}
|
if(silentDuration==0) {silentDuration=1;}
|
||||||
|
|
||||||
if(initFrequency < finalFrequency)
|
if(initFrequency < finalFrequency)
|
||||||
{
|
{
|
||||||
@ -160,7 +173,7 @@ void SimpleExpressionsClass::bendTones (float initFrequency, float finalFrequenc
|
|||||||
|
|
||||||
|
|
||||||
void SimpleExpressionsClass::playSound(int soundName){
|
void SimpleExpressionsClass::playSound(int soundName){
|
||||||
switch(soundName){
|
switch(soundName) {
|
||||||
|
|
||||||
case S_CONNECTION:
|
case S_CONNECTION:
|
||||||
_tone(NOTE_E5,50,30);
|
_tone(NOTE_E5,50,30);
|
||||||
|
@ -13,34 +13,35 @@
|
|||||||
|
|
||||||
class SimpleExpressionsClass
|
class SimpleExpressionsClass
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// General
|
// General
|
||||||
void init(int mouthPin, int buzzerPin);
|
void init(int mouthPin, int buzzerPin);
|
||||||
void initMouth(int mouthPin);
|
void initMouth(int mouthPin);
|
||||||
void initBuzzer(int buzzerPin);
|
void initBuzzer(int buzzerPin);
|
||||||
|
|
||||||
// Mouths
|
// Mouths
|
||||||
void printMouth(int number, int r, int g, int b);
|
void printMouth(int number, int r, int g, int b);
|
||||||
void writeMouth(const char mouthName[], int r, int g, int b);
|
void writeMouth(const char mouthName[], int r, int g, int b);
|
||||||
|
|
||||||
void printMouth(int number);
|
void printMouth(int number);
|
||||||
void writeMouth(const char mouthName[]);
|
void writeMouth(const char mouthName[]);
|
||||||
|
|
||||||
void clearMouth();
|
void clearMouth();
|
||||||
|
void showMouth();
|
||||||
|
|
||||||
void writeMouthGeneric(const int mouthArray[7][3]);
|
void writeMouthGeneric(const int mouthArray[7][3]);
|
||||||
void writeMouthGeneric(const bool mouthArray[7], int r, int g, int b);
|
void writeMouthGeneric(const bool mouthArray[7], int r, int g, int b);
|
||||||
|
|
||||||
// Sounds
|
// Sounds
|
||||||
void _tone (float noteFrequency, long noteDuration, int silentDuration);
|
void _tone (float noteFrequency, long noteDuration, int silentDuration);
|
||||||
void bendTones (float initFrequency, float finalFrequency, float prop, long noteDuration, int silentDuration);
|
void bendTones (float initFrequency, float finalFrequency, float prop, long noteDuration, int silentDuration);
|
||||||
void playSound(int soundName);
|
void playSound(int soundName);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Adafruit_NeoPixel mouth;
|
Adafruit_NeoPixel mouth;
|
||||||
void clearPixels();
|
void clearPixels();
|
||||||
int buzzerPin;
|
int buzzerPin;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern SimpleExpressionsClass SimpleExpressions;
|
extern SimpleExpressionsClass SimpleExpressions;
|
||||||
|
Loading…
Reference in New Issue
Block a user