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

CLEANUP and adding Pirates

This commit is contained in:
Lukas Bachschwell 2017-12-01 12:45:46 +01:00
parent 18e9c87d8e
commit ad855f6a97
7 changed files with 145 additions and 60 deletions

View File

@ -22,13 +22,6 @@ void SimpleExpressionsClass::init(int aMouthPin, int aBuzzerPin) {
//-- MOUTHS ----------------------------------------// //-- MOUTHS ----------------------------------------//
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
/*
void SimpleExpressionsClass::putAnimationMouth(int aniMouth, int index){
}
*/
void SimpleExpressionsClass::writeMouth(char mouthName[], int r, int g, int b) { void SimpleExpressionsClass::writeMouth(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++){
@ -268,6 +261,14 @@ void SimpleExpressionsClass::playSound(int soundName){
bendTones(4000, 3000, 1.02, 2, 20); bendTones(4000, 3000, 1.02, 2, 20);
break; 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;
} }
} }

View File

@ -14,9 +14,10 @@
class SimpleExpressionsClass class SimpleExpressionsClass
{ {
public: public:
// General
void init(int mouthPin, int buzzerPin); void init(int mouthPin, int buzzerPin);
// Mouths
void printMouth(int number, int r, int g, int b); void printMouth(int number, int r, int g, int b);
void writeMouth(char mouthName[], 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 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
//void putAnimationMouth(int anim, int index);
//-- 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);
//-- Gestures
//void playGesture(int gesture);
private: private:
Adafruit_NeoPixel mouth; Adafruit_NeoPixel mouth;

112
Sounds.h
View File

@ -129,5 +129,117 @@
#define S_FART1 16 #define S_FART1 16
#define S_FART2 17 #define S_FART2 17
#define S_FART3 18 #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 #endif

View File

@ -1,28 +1,21 @@
#include <SimpleExpressions.h> #include <SimpleExpressions.h>
void setup() { void setup() {
// put your setup code here, to run once:
Serial.begin(115200); Serial.begin(115200);
delay(2000); delay(2000);
SimpleExpressions.init(13, 17); SimpleExpressions.init(13, 17);
SimpleExpressions.clearMouth(); SimpleExpressions.clearMouth();
for (int i = 0; i < 18; i++) { for (int i = 0; i < 18; i++) {
Serial.println(i); Serial.println(i);
SimpleExpressions.printMouth(i, 30, 0, 0); SimpleExpressions.printMouth(i, 30, 0, 0);
SimpleExpressions.playSound(i); SimpleExpressions.playSound(i);
delay(1000); delay(1000);
} }
} }
void loop() { void loop() {
// for (int i = 0; i < 18; i++) {
SimpleExpressions.writeMouth("cross", 30, 0, 0); SimpleExpressions.writeMouth("cross", 30, 0, 0);
//Serial.println(i);
delay(1000); delay(1000);
SimpleExpressions.writeMouth("hook", 0, 30, 0); SimpleExpressions.writeMouth("hook", 0, 30, 0);
delay(1000); delay(1000);
@ -30,5 +23,4 @@ void loop() {
delay(1000); delay(1000);
SimpleExpressions.writeMouth("rightarrow", 0, 15, 30); SimpleExpressions.writeMouth("rightarrow", 0, 15, 30);
delay(1000); delay(1000);
//}
} }

View File

@ -1,5 +1,5 @@
####################################### #######################################
# Syntax Coloring Map For ExampleLibrary # Syntax Coloring Map For SimpleExpressions
####################################### #######################################
####################################### #######################################
@ -25,22 +25,23 @@ _tone KEYWORD2
# Constants (LITERAL1) # Constants (LITERAL1)
####################################### #######################################
S_CONNECTION S_CONNECTION LITERAL1
S_DISCONNECTION S_DISCONNECTION LITERAL1
S_BUTTON_PUSHED S_BUTTON_PUSHED LITERAL1
S_MODE1 S_MODE1 LITERAL1
S_MODE2 S_MODE2 LITERAL1
S_MODE3 S_MODE3 LITERAL1
S_SURPRISE S_SURPRISE LITERAL1
S_OHOOH S_OHOOH LITERAL1
S_OHOOH2 S_OHOOH2 LITERAL1
S_CUDDLY S_CUDDLY LITERAL1
S_SLEEPING S_SLEEPING LITERAL1
S_HAPPY S_HAPPY LITERAL1
S_SUPER_HAPPY S_SUPER_HAPPY LITERAL1
S_HAPPY_SHORT S_HAPPY_SHORT LITERAL1
S_SAD S_SAD LITERAL1
S_CONFUSED S_CONFUSED LITERAL1
S_FART1 S_FART1 LITERAL1
S_FART2 S_FART2 LITERAL1
S_FART3 S_FART3 LITERAL1
PIRATES LITERAL1

View File

@ -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"
]
}

View File

@ -18,7 +18,7 @@ Blockly.Blocks['show_mouth'] = {
Blockly.Arduino['show_mouth'] = function(block) { Blockly.Arduino['show_mouth'] = function(block) {
var input_color = Blockly.Arduino.valueToCode(block, 'Color', Blockly.Arduino.ORDER_ATOMIC); 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'; code+= '\n';
return code; return code;
}; };