Initial Commit

This commit is contained in:
Lukas Bachschwell 2017-11-20 14:59:19 +01:00
commit 1bbba08bcc
4 changed files with 389 additions and 0 deletions

0
README.md Normal file
View File

85
Shapes.h Executable file
View File

@ -0,0 +1,85 @@
#ifndef Shapes_h
#define Shapes_h
//***********************************************************************************
//*********************************MOUTHS DEFINES************************************
//***********************************************************************************
#define zero_code 0b00001100010010010010010010001100
#define one_code 0b00000100001100000100000100001110
#define two_code 0b00001100010010000100001000011110
#define three_code 0b00001100010010000100010010001100
#define four_code 0b00010010010010011110000010000010
#define five_code 0b00011110010000011100000010011100
#define six_code 0b00000100001000011100010010001100
#define seven_code 0b00011110000010000100001000010000
#define eight_code 0b00001100010010001100010010001100
#define nine_code 0b00001100010010001110000010001110
#define smile_code 0b00000000100001010010001100000000
#define happyOpen_code 0b00000000111111010010001100000000
#define happyClosed_code 0b00000000111111011110000000000000
#define heart_code 0b00010010101101100001010010001100
#define bigSurprise_code 0b00001100010010100001010010001100
#define smallSurprise_code 0b00000000000000001100001100000000
#define tongueOut_code 0b00111111001001001001000110000000
#define vamp1_code 0b00111111101101101101010010000000
#define vamp2_code 0b00111111101101010010000000000000
#define lineMouth_code 0b00000000000000111111000000000000
#define confused_code 0b00000000001000010101100010000000
#define diagonal_code 0b00100000010000001000000100000010
#define sad_code 0b00000000001100010010100001000000
#define sadOpen_code 0b00000000001100010010111111000000
#define sadClosed_code 0b00000000001100011110110011000000
#define okMouth_code 0b00000001000010010100001000000000
#define xMouth_code 0b00100001010010001100010010100001
#define interrogation_code 0b00001100010010000100000100000100
#define thunder_code 0b00000100001000011100001000010000
#define culito_code 0b00000000100001101101010010000000
#define angry_code 0b00000000011110100001100001000000
//Mouths sorted by numbers, and after, by happy to sad mouths
#define zero 0
#define one 1
#define two 2
#define three 3
#define four 4
#define five 5
#define six 6
#define seven 7
#define eight 8
#define nine 9
#define smile 10
#define happyOpen 11
#define happyClosed 12
#define heart 13
#define bigSurprise 14
#define smallSurprise 15
#define tongueOut 16
#define vamp1 17
#define vamp2 18
#define lineMouth 19
#define confused 20
#define diagonal 21
#define sad 22
#define sadOpen 23
#define sadClosed 24
#define okMouth 25
#define xMouth 26
#define interrogation 27
#define thunder 28
#define culito 29
#define angry 30
#endif

261
SimpleExpressions.cpp Executable file
View File

@ -0,0 +1,261 @@
#include "Arduino.h"
#include "SimpleExpressions.h"
void SimpleExpressions::init(int mouthPin, int buzzerPin) {
mouth = Adafruit_NeoPixel(7, mouthPin, NEO_GRB + NEO_KHZ800);
pinBuzzer = buzzerPin;
mouth.begin();
mouth.show();
}
///////////////////////////////////////////////////////////////////
//-- MOUTHS & ANIMATIONS ----------------------------------------//
///////////////////////////////////////////////////////////////////
unsigned long int SimpleExpressions::getMouthShape(int number){
unsigned long int types []={zero_code,one_code,two_code,three_code,four_code,five_code,six_code,seven_code,eight_code,
nine_code,smile_code,happyOpen_code,happyClosed_code,heart_code,bigSurprise_code,smallSurprise_code,tongueOut_code,
vamp1_code,vamp2_code,lineMouth_code,confused_code,diagonal_code,sad_code,sadOpen_code,sadClosed_code,
okMouth_code, xMouth_code,interrogation_code,thunder_code,culito_code,angry_code};
return types[number];
}
unsigned long int SimpleExpressions::getAnimShape(int anim, int index){
unsigned long int littleUuh_code[]={
0b00000000000000001100001100000000,
0b00000000000000000110000110000000,
0b00000000000000000011000011000000,
0b00000000000000000110000110000000,
0b00000000000000001100001100000000,
0b00000000000000011000011000000000,
0b00000000000000110000110000000000,
0b00000000000000011000011000000000
};
unsigned long int dreamMouth_code[]={
0b00000000000000000000110000110000,
0b00000000000000010000101000010000,
0b00000000011000100100100100011000,
0b00000000000000010000101000010000
};
unsigned long int adivinawi_code[]={
0b00100001000000000000000000100001,
0b00010010100001000000100001010010,
0b00001100010010100001010010001100,
0b00000000001100010010001100000000,
0b00000000000000001100000000000000,
0b00000000000000000000000000000000
};
unsigned long int wave_code[]={
0b00001100010010100001000000000000,
0b00000110001001010000100000000000,
0b00000011000100001000010000100000,
0b00000001000010000100001000110000,
0b00000000000001000010100100011000,
0b00000000000000100001010010001100,
0b00000000100000010000001001000110,
0b00100000010000001000000100000011,
0b00110000001000000100000010000001,
0b00011000100100000010000001000000
};
switch (anim){
case littleUuh:
return littleUuh_code[index];
break;
case dreamMouth:
return dreamMouth_code[index];
break;
case adivinawi:
return adivinawi_code[index];
break;
case wave:
return wave_code[index];
break;
}
}
void SimpleExpressions::putAnimationMouth(unsigned long int aniMouth, int index){
ledmatrix.writeFull(getAnimShape(aniMouth,index));
}
void SimpleExpressions::putMouth(unsigned long int mouth, bool predefined){
if (predefined){
ledmatrix.writeFull(getMouthShape(mouth));
}
else{
ledmatrix.writeFull(mouth);
}
}
void SimpleExpressions::clearMouth(){
ledmatrix.clearMatrix();
}
///////////////////////////////////////////////////////////////////
//-- SOUNDS -----------------------------------------------------//
///////////////////////////////////////////////////////////////////
void SimpleExpressions::_tone (float noteFrequency, long noteDuration, int silentDuration){
// tone(10,261,500);
// delay(500);
if(silentDuration==0){silentDuration=1;}
tone(SimpleExpressions::pinBuzzer, noteFrequency, noteDuration);
delay(noteDuration); //milliseconds to microseconds
//noTone(PIN_Buzzer);
delay(silentDuration);
}
void SimpleE::bendTones (float initFrequency, float finalFrequency, float prop, long noteDuration, int silentDuration){
//Examples:
// bendTones (880, 2093, 1.02, 18, 1);
// bendTones (note_A5, note_C7, 1.02, 18, 0);
if(silentDuration==0){silentDuration=1;}
if(initFrequency < finalFrequency)
{
for (int i=initFrequency; i<finalFrequency; i=i*prop) {
_tone(i, noteDuration, silentDuration);
}
} else{
for (int i=initFrequency; i>finalFrequency; i=i/prop) {
_tone(i, noteDuration, silentDuration);
}
}
}
void SimpleExpressions::sing(int songName){
switch(songName){
case S_connection:
_tone(note_E5,50,30);
_tone(note_E6,55,25);
_tone(note_A6,60,10);
break;
case S_disconnection:
_tone(note_E5,50,30);
_tone(note_A6,55,25);
_tone(note_E6,50,10);
break;
case S_buttonPushed:
bendTones (note_E6, note_G6, 1.03, 20, 2);
delay(30);
bendTones (note_E6, note_D7, 1.04, 10, 2);
break;
case S_mode1:
bendTones (note_E6, note_A6, 1.02, 30, 10); //1318.51 to 1760
break;
case S_mode2:
bendTones (note_G6, note_D7, 1.03, 30, 10); //1567.98 to 2349.32
break;
case S_mode3:
_tone(note_E6,50,100); //D6
_tone(note_G6,50,80); //E6
_tone(note_D7,300,0); //G6
break;
case S_surprise:
bendTones(800, 2150, 1.02, 10, 1);
bendTones(2149, 800, 1.03, 7, 1);
break;
case S_OhOoh:
bendTones(880, 2000, 1.04, 8, 3); //A5 = 880
delay(200);
for (int i=880; i<2000; i=i*1.04) {
_tone(note_B5,5,10);
}
break;
case S_OhOoh2:
bendTones(1880, 3000, 1.03, 8, 3);
delay(200);
for (int i=1880; i<3000; i=i*1.03) {
_tone(note_C6,10,10);
}
break;
case S_cuddly:
bendTones(700, 900, 1.03, 16, 4);
bendTones(899, 650, 1.01, 18, 7);
break;
case S_sleeping:
bendTones(100, 500, 1.04, 10, 10);
delay(500);
bendTones(400, 100, 1.04, 10, 1);
break;
case S_happy:
bendTones(1500, 2500, 1.05, 20, 8);
bendTones(2499, 1500, 1.05, 25, 8);
break;
case S_superHappy:
bendTones(2000, 6000, 1.05, 8, 3);
delay(50);
bendTones(5999, 2000, 1.05, 13, 2);
break;
case S_happy_short:
bendTones(1500, 2000, 1.05, 15, 8);
delay(100);
bendTones(1900, 2500, 1.05, 10, 8);
break;
case S_sad:
bendTones(880, 669, 1.02, 20, 200);
break;
case S_confused:
bendTones(1000, 1700, 1.03, 8, 2);
bendTones(1699, 500, 1.04, 8, 3);
bendTones(1000, 1700, 1.05, 9, 10);
break;
case S_fart1:
bendTones(1600, 3000, 1.02, 2, 15);
break;
case S_fart2:
bendTones(2000, 6000, 1.02, 2, 20);
break;
case S_fart3:
bendTones(1600, 4000, 1.02, 2, 20);
bendTones(4000, 3000, 1.02, 2, 20);
break;
}
}

43
SimpleExpressions.h Executable file
View File

@ -0,0 +1,43 @@
#ifndef SimpleMouth_h
#define SimpleMouth_h
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#include "Shapes.h"
class SimpleExpressions
{
public:
void init(int mouthPin, int buzzerPin);
void putMouth(unsigned long int mouth, bool predefined = true);
void putAnimationMouth(unsigned long int anim, int index);
void clearMouth();
//-- Sounds
void _tone (float noteFrequency, long noteDuration, int silentDuration);
void bendTones (float initFrequency, float finalFrequency, float prop, long noteDuration, int silentDuration);
void sing(int songName);
//-- Gestures
void playGesture(int gesture);
private:
Adafruit_NeoPixel mouth;
int pinBuzzer;
int pinMouth;
unsigned long int getMouthShape(int number);
unsigned long int getAnimShape(int anim, int index);
void _execute(int A[4], int O[4], int T, double phase_diff[4], float steps);
};
#endif