From ad855f6a97e66ecdc2e6c153c64b9cb863f6714e Mon Sep 17 00:00:00 2001 From: Lukas Bachschwell Date: Fri, 1 Dec 2017 12:45:46 +0100 Subject: [PATCH] CLEANUP and adding Pirates --- SimpleExpressions.cpp | 15 ++--- SimpleExpressions.h | 11 +--- Sounds.h | 112 +++++++++++++++++++++++++++++++++++++ examples/mouth.ino | 8 --- keywords.txt | 41 +++++++------- library.json | 16 ------ simpleExpression_blocks.js | 2 +- 7 files changed, 145 insertions(+), 60 deletions(-) delete mode 100644 library.json diff --git a/SimpleExpressions.cpp b/SimpleExpressions.cpp index a2525f6..0b13ebe 100755 --- a/SimpleExpressions.cpp +++ b/SimpleExpressions.cpp @@ -22,13 +22,6 @@ void SimpleExpressionsClass::init(int aMouthPin, int aBuzzerPin) { //-- MOUTHS ----------------------------------------// /////////////////////////////////////////////////////////////////// -/* -void SimpleExpressionsClass::putAnimationMouth(int aniMouth, int index){ - -} -*/ - - void SimpleExpressionsClass::writeMouth(char mouthName[], int r, int g, int b) { int number = -1; for(int i = 0; i < frameCount; i++){ @@ -268,6 +261,14 @@ void SimpleExpressionsClass::playSound(int soundName){ bendTones(4000, 3000, 1.02, 2, 20); break; + case PIRATES: + // This is funny but very experimental and probably take long haha =P + for (int i = 0; i < 203; i++) { //203 is the total number of music notes in the song + int wait = duration[i] * songspeed; + _tone( notes[i], wait, 0); //tone(pin,frequency,duration) + } + break; + } } diff --git a/SimpleExpressions.h b/SimpleExpressions.h index 3c45074..0b7fd6c 100755 --- a/SimpleExpressions.h +++ b/SimpleExpressions.h @@ -14,9 +14,10 @@ class SimpleExpressionsClass { public: - + // General void init(int mouthPin, int buzzerPin); + // Mouths void printMouth(int number, int r, int g, int b); void writeMouth(char mouthName[], int r, int g, int b); @@ -28,17 +29,11 @@ class SimpleExpressionsClass void writeMouthGeneric(const int mouthArray[7][3]); void writeMouthGeneric(const bool mouthArray[7], int r, int g, int b); - - //void putAnimationMouth(int anim, int index); - - //-- Sounds + // Sounds void _tone (float noteFrequency, long noteDuration, int silentDuration); void bendTones (float initFrequency, float finalFrequency, float prop, long noteDuration, int silentDuration); void playSound(int soundName); - //-- Gestures - //void playGesture(int gesture); - private: Adafruit_NeoPixel mouth; diff --git a/Sounds.h b/Sounds.h index 9ea0e13..6ed709a 100644 --- a/Sounds.h +++ b/Sounds.h @@ -129,5 +129,117 @@ #define S_FART1 16 #define S_FART2 17 #define S_FART3 18 +#define PIRATES 19 + + +const int songspeed = 1; + +const PROGMEM int notes[] = { //Note of the song, 0 is a rest/pulse + NOTE_E4, NOTE_G4, NOTE_A4, NOTE_A4, 0, + NOTE_A4, NOTE_B4, NOTE_C5, NOTE_C5, 0, + NOTE_C5, NOTE_D5, NOTE_B4, NOTE_B4, 0, + NOTE_A4, NOTE_G4, NOTE_A4, 0, + + NOTE_E4, NOTE_G4, NOTE_A4, NOTE_A4, 0, + NOTE_A4, NOTE_B4, NOTE_C5, NOTE_C5, 0, + NOTE_C5, NOTE_D5, NOTE_B4, NOTE_B4, 0, + NOTE_A4, NOTE_G4, NOTE_A4, 0, + + NOTE_E4, NOTE_G4, NOTE_A4, NOTE_A4, 0, + NOTE_A4, NOTE_C5, NOTE_D5, NOTE_D5, 0, + NOTE_D5, NOTE_E5, NOTE_F5, NOTE_F5, 0, + NOTE_E5, NOTE_D5, NOTE_E5, NOTE_A4, 0, + + NOTE_A4, NOTE_B4, NOTE_C5, NOTE_C5, 0, + NOTE_D5, NOTE_E5, NOTE_A4, 0, + NOTE_A4, NOTE_C5, NOTE_B4, NOTE_B4, 0, + NOTE_C5, NOTE_A4, NOTE_B4, 0, + + NOTE_A4, NOTE_A4, + //Repeat of first part + NOTE_A4, NOTE_B4, NOTE_C5, NOTE_C5, 0, + NOTE_C5, NOTE_D5, NOTE_B4, NOTE_B4, 0, + NOTE_A4, NOTE_G4, NOTE_A4, 0, + + NOTE_E4, NOTE_G4, NOTE_A4, NOTE_A4, 0, + NOTE_A4, NOTE_B4, NOTE_C5, NOTE_C5, 0, + NOTE_C5, NOTE_D5, NOTE_B4, NOTE_B4, 0, + NOTE_A4, NOTE_G4, NOTE_A4, 0, + + NOTE_E4, NOTE_G4, NOTE_A4, NOTE_A4, 0, + NOTE_A4, NOTE_C5, NOTE_D5, NOTE_D5, 0, + NOTE_D5, NOTE_E5, NOTE_F5, NOTE_F5, 0, + NOTE_E5, NOTE_D5, NOTE_E5, NOTE_A4, 0, + + NOTE_A4, NOTE_B4, NOTE_C5, NOTE_C5, 0, + NOTE_D5, NOTE_E5, NOTE_A4, 0, + NOTE_A4, NOTE_C5, NOTE_B4, NOTE_B4, 0, + NOTE_C5, NOTE_A4, NOTE_B4, 0, + //End of Repeat + + NOTE_E5, 0, 0, NOTE_F5, 0, 0, + NOTE_E5, NOTE_E5, 0, NOTE_G5, 0, NOTE_E5, NOTE_D5, 0, 0, + NOTE_D5, 0, 0, NOTE_C5, 0, 0, + NOTE_B4, NOTE_C5, 0, NOTE_B4, 0, NOTE_A4, + + NOTE_E5, 0, 0, NOTE_F5, 0, 0, + NOTE_E5, NOTE_E5, 0, NOTE_G5, 0, NOTE_E5, NOTE_D5, 0, 0, + NOTE_D5, 0, 0, NOTE_C5, 0, 0, + NOTE_B4, NOTE_C5, 0, NOTE_B4, 0, NOTE_A4 +}; +//***************************************** +const PROGMEM int duration[] = { //duration of each note (in ms) Quarter Note is set to 250 ms + 125, 125, 250, 125, 125, + 125, 125, 250, 125, 125, + 125, 125, 250, 125, 125, + 125, 125, 375, 125, + + 125, 125, 250, 125, 125, + 125, 125, 250, 125, 125, + 125, 125, 250, 125, 125, + 125, 125, 375, 125, + + 125, 125, 250, 125, 125, + 125, 125, 250, 125, 125, + 125, 125, 250, 125, 125, + 125, 125, 125, 250, 125, + + 125, 125, 250, 125, 125, + 250, 125, 250, 125, + 125, 125, 250, 125, 125, + 125, 125, 375, 375, + + 250, 125, + //Rpeat of First Part + 125, 125, 250, 125, 125, + 125, 125, 250, 125, 125, + 125, 125, 375, 125, + + 125, 125, 250, 125, 125, + 125, 125, 250, 125, 125, + 125, 125, 250, 125, 125, + 125, 125, 375, 125, + + 125, 125, 250, 125, 125, + 125, 125, 250, 125, 125, + 125, 125, 250, 125, 125, + 125, 125, 125, 250, 125, + + 125, 125, 250, 125, 125, + 250, 125, 250, 125, + 125, 125, 250, 125, 125, + 125, 125, 375, 375, + //End of Repeat + + 250, 125, 375, 250, 125, 375, + 125, 125, 125, 125, 125, 125, 125, 125, 375, + 250, 125, 375, 250, 125, 375, + 125, 125, 125, 125, 125, 500, + + 250, 125, 375, 250, 125, 375, + 125, 125, 125, 125, 125, 125, 125, 125, 375, + 250, 125, 375, 250, 125, 375, + 125, 125, 125, 125, 125, 500 +}; #endif diff --git a/examples/mouth.ino b/examples/mouth.ino index a1cf3ab..2b58eb8 100644 --- a/examples/mouth.ino +++ b/examples/mouth.ino @@ -1,28 +1,21 @@ #include void setup() { - // put your setup code here, to run once: Serial.begin(115200); delay(2000); SimpleExpressions.init(13, 17); - SimpleExpressions.clearMouth(); for (int i = 0; i < 18; i++) { Serial.println(i); SimpleExpressions.printMouth(i, 30, 0, 0); SimpleExpressions.playSound(i); - delay(1000); } - - } void loop() { - // for (int i = 0; i < 18; i++) { SimpleExpressions.writeMouth("cross", 30, 0, 0); - //Serial.println(i); delay(1000); SimpleExpressions.writeMouth("hook", 0, 30, 0); delay(1000); @@ -30,5 +23,4 @@ void loop() { delay(1000); SimpleExpressions.writeMouth("rightarrow", 0, 15, 30); delay(1000); - //} } diff --git a/keywords.txt b/keywords.txt index 1e5f3bf..2a19819 100644 --- a/keywords.txt +++ b/keywords.txt @@ -1,5 +1,5 @@ ####################################### -# Syntax Coloring Map For ExampleLibrary +# Syntax Coloring Map For SimpleExpressions ####################################### ####################################### @@ -25,22 +25,23 @@ _tone KEYWORD2 # Constants (LITERAL1) ####################################### -S_CONNECTION -S_DISCONNECTION -S_BUTTON_PUSHED -S_MODE1 -S_MODE2 -S_MODE3 -S_SURPRISE -S_OHOOH -S_OHOOH2 -S_CUDDLY -S_SLEEPING -S_HAPPY -S_SUPER_HAPPY -S_HAPPY_SHORT -S_SAD -S_CONFUSED -S_FART1 -S_FART2 -S_FART3 +S_CONNECTION LITERAL1 +S_DISCONNECTION LITERAL1 +S_BUTTON_PUSHED LITERAL1 +S_MODE1 LITERAL1 +S_MODE2 LITERAL1 +S_MODE3 LITERAL1 +S_SURPRISE LITERAL1 +S_OHOOH LITERAL1 +S_OHOOH2 LITERAL1 +S_CUDDLY LITERAL1 +S_SLEEPING LITERAL1 +S_HAPPY LITERAL1 +S_SUPER_HAPPY LITERAL1 +S_HAPPY_SHORT LITERAL1 +S_SAD LITERAL1 +S_CONFUSED LITERAL1 +S_FART1 LITERAL1 +S_FART2 LITERAL1 +S_FART3 LITERAL1 +PIRATES LITERAL1 diff --git a/library.json b/library.json deleted file mode 100644 index a8f6194..0000000 --- a/library.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name": "SimpleExpressions", - "keywords": "Expressions, esp32, esp8266, arduino, avr, robot, cute, ws2812, leds, emotions, sounds, buzzer, beeper", - "description": "Make your robots cute and noisy", - "repository": - { - "type": "git", - "url": "https://github.com/s00500/SimpleExpressions.git" - }, - "frameworks": "arduino", - "platforms": - [ - "espressif", - "arduino" - ] -} diff --git a/simpleExpression_blocks.js b/simpleExpression_blocks.js index a4b3188..91a1cdd 100644 --- a/simpleExpression_blocks.js +++ b/simpleExpression_blocks.js @@ -18,7 +18,7 @@ Blockly.Blocks['show_mouth'] = { Blockly.Arduino['show_mouth'] = function(block) { var input_color = Blockly.Arduino.valueToCode(block, 'Color', Blockly.Arduino.ORDER_ATOMIC); - var code='SimpleExpressions.showMouth("+'mouth_name'+", '+color+')'; + var code='SimpleExpressions.showMouth("'+'mouth_name'+'", ' + color + ')' ; code+= '\n'; return code; };