mirror of
https://github.com/s00500/SimpleExpressions
synced 2024-09-27 21:41:48 +00:00
Compare commits
23 Commits
Author | SHA1 | Date | |
---|---|---|---|
419f873313 | |||
|
16b8a09161 | ||
5618498992 | |||
10c656448b | |||
8526e6d4a5 | |||
db7a00935f | |||
95a7024a71 | |||
|
0a23390b93 | ||
|
be3c222c62 | ||
6d19e4bd02 | |||
5574f6f732 | |||
d5cef241bf | |||
4b4f87a179 | |||
|
1ed2a6928d | ||
8cf9d4583a | |||
ea9fabe9a4 | |||
1898615bab | |||
|
3405cf52c9 | ||
|
e1f29d04f4 | ||
|
718ab33c32 | ||
|
8e0f1c4240 | ||
|
5e8dfc9920 | ||
9310f8213c |
@ -1,275 +0,0 @@
|
|||||||
#include "Arduino.h"
|
|
||||||
#include "SimpleExpressions.h"
|
|
||||||
|
|
||||||
#define ledc_channel 5
|
|
||||||
|
|
||||||
void SimpleExpressionsClass::init(int aMouthPin, int aBuzzerPin) {
|
|
||||||
mouth = Adafruit_NeoPixel(7, aMouthPin, NEO_GRB + NEO_KHZ800);
|
|
||||||
mouth.begin();
|
|
||||||
|
|
||||||
buzzerPin = aBuzzerPin;
|
|
||||||
|
|
||||||
#if defined(ESP32)
|
|
||||||
ledcSetup(ledc_channel, 2000, 8); // channel, max frequency, resolution
|
|
||||||
ledcAttachPin(aBuzzerPin, ledc_channel);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
clearMouth();
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////
|
|
||||||
//-- MOUTHS ----------------------------------------//
|
|
||||||
///////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
void SimpleExpressionsClass::writeMouth(char mouthName[], int r, int g, int b) {
|
|
||||||
int number = -1;
|
|
||||||
for(int i = 0; i < frameCount; i++){
|
|
||||||
if(strncmp(shapes[i].name, mouthName, 20) == 0) {
|
|
||||||
number = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(number != -1){
|
|
||||||
printMouth(number, r, g, b);
|
|
||||||
} else {
|
|
||||||
if(debug) Serial.println("Error: mouth name does not exist");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SimpleExpressionsClass::printMouth(int number, int r, int g, int b) {
|
|
||||||
for(uint16_t i = 0; i<7; i++) {
|
|
||||||
if(shapes[number].data[i]) mouth.setPixelColor(i, mouth.Color(r, g, b));
|
|
||||||
else mouth.setPixelColor(i, 0);
|
|
||||||
}
|
|
||||||
mouth.show();
|
|
||||||
delay(1);
|
|
||||||
clearPixels();
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
delay(1);
|
|
||||||
clearPixels();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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();
|
|
||||||
delay(1);
|
|
||||||
clearPixels();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SimpleExpressionsClass::writeMouthGeneric(const int mouthArray[7][3]) {
|
|
||||||
for(uint16_t i=0; i<7; i++) {
|
|
||||||
mouth.setPixelColor(i, mouth.Color(mouthArray[i][0], mouthArray[i][1], mouthArray[i][2]));
|
|
||||||
}
|
|
||||||
mouth.show();
|
|
||||||
delay(1);
|
|
||||||
clearPixels();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void SimpleExpressionsClass::clearMouth() {
|
|
||||||
for(int i = 0; i < 7; i++) {
|
|
||||||
mouth.setPixelColor(i, 0);
|
|
||||||
}
|
|
||||||
mouth.show();
|
|
||||||
delay(1);
|
|
||||||
clearPixels();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void SimpleExpressionsClass::clearPixels() { // avoid strange issues on ESP32 with ledc
|
|
||||||
for(int i = 0; i < 7; i++) {
|
|
||||||
mouth.setPixelColor(i, 0);
|
|
||||||
}
|
|
||||||
delay(1);
|
|
||||||
}
|
|
||||||
///////////////////////////////////////////////////////////////////
|
|
||||||
//-- SOUNDS -----------------------------------------------------//
|
|
||||||
///////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
|
|
||||||
void SimpleExpressionsClass::_tone (float noteFrequency, long noteDuration, int silentDuration){
|
|
||||||
if(silentDuration==0){silentDuration=1;}
|
|
||||||
|
|
||||||
#if defined(ESP32)
|
|
||||||
ledcWriteTone(ledc_channel, noteFrequency);
|
|
||||||
delay(noteDuration); // milliseconds
|
|
||||||
ledcWrite(ledc_channel, 0); // notone
|
|
||||||
#else
|
|
||||||
tone(buzzerPin, noteFrequency, noteDuration);
|
|
||||||
delay(noteDuration); // milliseconds
|
|
||||||
#endif
|
|
||||||
|
|
||||||
delay(silentDuration);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void SimpleExpressionsClass::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 SimpleExpressionsClass::playSound(int soundName){
|
|
||||||
switch(soundName){
|
|
||||||
|
|
||||||
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_BUTTON_PUSHED:
|
|
||||||
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_SUPER_HAPPY:
|
|
||||||
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;
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SimpleExpressionsClass SimpleExpressions;
|
|
@ -1,46 +0,0 @@
|
|||||||
#ifndef SimpleExpressions_h
|
|
||||||
#define SimpleExpressions_h
|
|
||||||
#include <Adafruit_NeoPixel.h>
|
|
||||||
#ifdef __AVR__
|
|
||||||
#include <avr/power.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "Shapes.h"
|
|
||||||
#include "Sounds.h"
|
|
||||||
|
|
||||||
#define debug true
|
|
||||||
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
void printMouth(int number);
|
|
||||||
void writeMouth(char mouthName[]);
|
|
||||||
|
|
||||||
void clearMouth();
|
|
||||||
|
|
||||||
void writeMouthGeneric(const int mouthArray[7][3]);
|
|
||||||
void writeMouthGeneric(const bool mouthArray[7], int r, int g, int b);
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
Adafruit_NeoPixel mouth;
|
|
||||||
void clearPixels();
|
|
||||||
int buzzerPin;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern SimpleExpressionsClass SimpleExpressions;
|
|
||||||
|
|
||||||
#endif
|
|
1
img/blocks/credits.txt
Normal file
1
img/blocks/credits.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
Created by Leopoldo Armesto (based on the icon from Antoine Dieulesaint from the Noun Project)
|
95
img/blocks/led_strip.svg
Normal file
95
img/blocks/led_strip.svg
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
width="32mm"
|
||||||
|
height="32mm"
|
||||||
|
viewBox="0 0 32 32"
|
||||||
|
version="1.1"
|
||||||
|
id="svg4534"
|
||||||
|
inkscape:version="0.92.1 r15371"
|
||||||
|
sodipodi:docname="led_strip.svg">
|
||||||
|
<defs
|
||||||
|
id="defs4528" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="0.35"
|
||||||
|
inkscape:cx="-292.85714"
|
||||||
|
inkscape:cy="560"
|
||||||
|
inkscape:document-units="mm"
|
||||||
|
inkscape:current-layer="layer1"
|
||||||
|
showgrid="false"
|
||||||
|
inkscape:window-width="1366"
|
||||||
|
inkscape:window-height="705"
|
||||||
|
inkscape:window-x="-8"
|
||||||
|
inkscape:window-y="-8"
|
||||||
|
inkscape:window-maximized="1" />
|
||||||
|
<metadata
|
||||||
|
id="metadata4531">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title></dc:title>
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<g
|
||||||
|
inkscape:label="Layer 1"
|
||||||
|
inkscape:groupmode="layer"
|
||||||
|
id="layer1"
|
||||||
|
transform="translate(0,-265)">
|
||||||
|
<g
|
||||||
|
id="g4510"
|
||||||
|
transform="matrix(-0.56126601,-0.56126601,0.56126601,-0.56126601,16.631231,337.25123)">
|
||||||
|
<rect
|
||||||
|
id="rect2"
|
||||||
|
height="85.000999"
|
||||||
|
width="1"
|
||||||
|
transform="matrix(0.7071,0.7071,-0.7071,0.7071,42.9292,-17.7819)"
|
||||||
|
y="0.42899999"
|
||||||
|
x="42.429001" />
|
||||||
|
<rect
|
||||||
|
id="rect4"
|
||||||
|
height="85"
|
||||||
|
width="1"
|
||||||
|
transform="matrix(0.7071,0.7071,-0.7071,0.7071,57.071,-23.6396)"
|
||||||
|
y="14.571"
|
||||||
|
x="56.570999" />
|
||||||
|
<path
|
||||||
|
id="path6"
|
||||||
|
d="m 76.252,26.047 4.95,-4.95 -0.531,-0.53 -4.949,4.95 -1.06,-1.06 2.475,-2.475 c 0.059,-0.059 0.097,-0.136 0.106,-0.219 l 0.382,-3.098 0.572,-0.572 -0.531,-0.53 -0.663,0.663 c -0.059,0.059 -0.097,0.136 -0.106,0.219 l -0.382,3.098 -2.384,2.383 -2.563,-2.563 c -0.188,-0.188 -0.52,-0.188 -0.707,0 l -7.07,7.071 c -0.195,0.195 -0.195,0.512 0,0.707 l 1.149,1.149 -2.078,2.077 c -0.06,0.059 -0.098,0.136 -0.107,0.219 l -0.382,3.098 -2.383,2.383 -2.563,-2.563 c -0.195,-0.195 -0.512,-0.195 -0.707,0 l -7.071,7.071 c -0.094,0.094 -0.146,0.221 -0.146,0.354 0,0.133 0.053,0.26 0.146,0.354 l 1.149,1.149 -2.077,2.078 c -0.059,0.059 -0.097,0.136 -0.107,0.219 l -0.382,3.098 -2.384,2.383 -2.563,-2.563 c -0.188,-0.188 -0.52,-0.188 -0.707,0 l -7.071,7.071 c -0.195,0.195 -0.195,0.512 0,0.707 l 1.149,1.149 -2.077,2.077 c -0.059,0.06 -0.097,0.137 -0.107,0.22 L 34.09,63.97 31.706,66.353 29.143,63.79 c -0.195,-0.195 -0.512,-0.195 -0.707,0 l -7.071,7.07 c -0.094,0.094 -0.146,0.221 -0.146,0.354 0,0.133 0.053,0.26 0.146,0.354 l 1.149,1.149 -2.078,2.078 c -0.059,0.059 -0.097,0.136 -0.107,0.219 l -0.381,3.098 -0.97,0.969 0.53,0.531 1.061,-1.061 c 0.059,-0.06 0.097,-0.137 0.107,-0.22 l 0.381,-3.098 1.986,-1.987 2.475,2.475 -4.95,4.949 0.53,0.531 4.95,-4.95 2.386,2.386 c 0.094,0.094 0.221,0.146 0.354,0.146 0.133,0 0.26,-0.053 0.354,-0.146 l 7.071,-7.071 c 0.094,-0.094 0.146,-0.221 0.146,-0.354 0,-0.133 -0.053,-0.26 -0.146,-0.354 l -2.386,-2.386 6.364,-6.364 2.386,2.387 c 0.094,0.094 0.221,0.146 0.354,0.146 0.133,0 0.26,-0.053 0.354,-0.146 l 7.071,-7.071 c 0.195,-0.195 0.195,-0.512 0,-0.707 l -2.387,-2.387 6.364,-6.364 2.387,2.387 c 0.098,0.098 0.226,0.146 0.354,0.146 0.128,0 0.256,-0.049 0.354,-0.146 l 7.071,-7.071 c 0.094,-0.094 0.146,-0.221 0.146,-0.354 0,-0.133 -0.053,-0.26 -0.146,-0.354 l -2.387,-2.386 6.364,-6.364 2.386,2.386 c 0.094,0.094 0.221,0.146 0.354,0.146 0.133,0 0.26,-0.053 0.354,-0.146 l 7.071,-7.071 c 0.094,-0.094 0.146,-0.221 0.146,-0.354 0,-0.133 -0.053,-0.26 -0.146,-0.354 z m -47.465,51.53 -6.364,-6.364 6.364,-6.363 6.364,6.363 z m 4.507,-9.634 -1.06,-1.06 2.475,-2.474 c 0.059,-0.06 0.097,-0.137 0.107,-0.22 l 0.382,-3.099 1.986,-1.986 2.474,2.474 z m 9.635,-4.507 -6.364,-6.364 6.364,-6.364 6.364,6.364 z m 4.507,-9.636 -1.06,-1.06 2.475,-2.475 c 0.059,-0.059 0.097,-0.136 0.107,-0.219 l 0.382,-3.098 1.986,-1.986 2.474,2.474 z m 9.635,-4.507 -6.364,-6.364 6.364,-6.364 6.364,6.364 z m 4.508,-9.635 -1.06,-1.06 2.475,-2.475 c 0.059,-0.059 0.097,-0.136 0.106,-0.219 l 0.382,-3.098 1.987,-1.986 2.474,2.475 z m 9.634,-4.507 -6.363,-6.364 6.363,-6.364 6.364,6.364 z"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
<path
|
||||||
|
id="path8"
|
||||||
|
d="m 71.184,32.191 c -0.901,0 -1.749,-0.351 -2.387,-0.989 -0.637,-0.637 -0.988,-1.485 -0.988,-2.386 0,-0.901 0.352,-1.749 0.988,-2.387 1.275,-1.274 3.498,-1.274 4.773,0 0.637,0.638 0.988,1.485 0.988,2.387 0,0.902 -0.352,1.749 -0.989,2.386 -0.636,0.638 -1.483,0.989 -2.385,0.989 z m 0,-6 c -0.701,0 -1.36,0.273 -1.856,0.769 -0.495,0.496 -0.769,1.155 -0.769,1.856 0,0.701 0.273,1.36 0.769,1.856 0.992,0.992 2.722,0.992 3.712,0 0.496,-0.496 0.77,-1.155 0.77,-1.856 0,-0.701 -0.273,-1.36 -0.77,-1.856 -0.496,-0.496 -1.155,-0.769 -1.856,-0.769 z"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
<path
|
||||||
|
id="path10"
|
||||||
|
d="m 57.071,46.304 c -0.901,0 -1.749,-0.351 -2.387,-0.988 -0.637,-0.637 -0.988,-1.485 -0.988,-2.386 0,-0.902 0.352,-1.75 0.989,-2.387 1.273,-1.274 3.498,-1.274 4.771,0 0.638,0.637 0.989,1.485 0.989,2.387 0,0.901 -0.352,1.749 -0.989,2.386 -0.636,0.637 -1.483,0.988 -2.385,0.988 z m 0,-6 c -0.701,0 -1.36,0.273 -1.855,0.769 -0.496,0.496 -0.77,1.155 -0.77,1.856 0,0.701 0.273,1.36 0.769,1.856 0.992,0.991 2.721,0.991 3.713,0 0.495,-0.496 0.769,-1.155 0.769,-1.856 0,-0.702 -0.273,-1.361 -0.769,-1.856 -0.496,-0.496 -1.156,-0.769 -1.857,-0.769 z"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
<path
|
||||||
|
id="path12"
|
||||||
|
d="m 42.929,60.446 c -0.902,0 -1.75,-0.352 -2.387,-0.989 -0.637,-0.637 -0.988,-1.484 -0.988,-2.386 0,-0.902 0.351,-1.749 0.988,-2.387 1.273,-1.273 3.498,-1.275 4.773,0.001 0.637,0.637 0.988,1.484 0.988,2.386 0,0.902 -0.351,1.749 -0.988,2.386 -0.637,0.638 -1.484,0.989 -2.386,0.989 z m 0,-6 c -0.702,0 -1.361,0.273 -1.856,0.769 -0.496,0.496 -0.769,1.155 -0.769,1.856 0,0.701 0.273,1.36 0.769,1.856 0.991,0.99 2.721,0.99 3.712,0 0.496,-0.496 0.769,-1.155 0.769,-1.856 0,-0.701 -0.273,-1.36 -0.769,-1.855 -0.495,-0.496 -1.155,-0.77 -1.856,-0.77 z"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
<path
|
||||||
|
id="path14"
|
||||||
|
d="m 28.787,74.588 c -0.901,0 -1.749,-0.351 -2.386,-0.987 -1.315,-1.316 -1.315,-3.458 0,-4.773 1.274,-1.275 3.498,-1.274 4.773,-0.001 1.315,1.316 1.315,3.458 0,4.773 -0.638,0.637 -1.486,0.988 -2.387,0.988 z m 0,-6 c -0.701,0 -1.36,0.273 -1.856,0.769 -1.023,1.024 -1.023,2.689 0,3.714 0.991,0.99 2.72,0.991 3.712,-0.001 1.023,-1.023 1.023,-2.688 0,-3.713 -0.496,-0.496 -1.155,-0.769 -1.856,-0.769 z"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 7.0 KiB |
242
img/blocks/round_led_strip.svg
Normal file
242
img/blocks/round_led_strip.svg
Normal file
@ -0,0 +1,242 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
width="52mm"
|
||||||
|
height="51mm"
|
||||||
|
viewBox="0 0 52 51"
|
||||||
|
version="1.1"
|
||||||
|
id="svg8"
|
||||||
|
inkscape:version="0.92.1 r15371"
|
||||||
|
sodipodi:docname="round_led_strip.svg">
|
||||||
|
<defs
|
||||||
|
id="defs2">
|
||||||
|
<marker
|
||||||
|
style="overflow:visible"
|
||||||
|
refY="0"
|
||||||
|
refX="0"
|
||||||
|
orient="auto"
|
||||||
|
id="DistanceX">
|
||||||
|
<path
|
||||||
|
id="path4487"
|
||||||
|
style="stroke:#000000;stroke-width:0.5"
|
||||||
|
d="M 3,-3 -3,3 M 0,-5 V 5"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
</marker>
|
||||||
|
<pattern
|
||||||
|
y="0"
|
||||||
|
x="0"
|
||||||
|
width="8"
|
||||||
|
patternUnits="userSpaceOnUse"
|
||||||
|
id="Hatch"
|
||||||
|
height="8">
|
||||||
|
<path
|
||||||
|
id="path4490"
|
||||||
|
stroke-width="0.25"
|
||||||
|
stroke="#000000"
|
||||||
|
linecap="square"
|
||||||
|
d="M8 4 l-4,4" />
|
||||||
|
<path
|
||||||
|
id="path4492"
|
||||||
|
stroke-width="0.25"
|
||||||
|
stroke="#000000"
|
||||||
|
linecap="square"
|
||||||
|
d="M6 2 l-4,4" />
|
||||||
|
<path
|
||||||
|
id="path4494"
|
||||||
|
stroke-width="0.25"
|
||||||
|
stroke="#000000"
|
||||||
|
linecap="square"
|
||||||
|
d="M4 0 l-4,4" />
|
||||||
|
</pattern>
|
||||||
|
<symbol
|
||||||
|
id="*Model_Space" />
|
||||||
|
<symbol
|
||||||
|
id="*Paper_Space" />
|
||||||
|
<symbol
|
||||||
|
id="*Paper_Space0" />
|
||||||
|
</defs>
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="1.4"
|
||||||
|
inkscape:cx="123.32321"
|
||||||
|
inkscape:cy="41.326652"
|
||||||
|
inkscape:document-units="mm"
|
||||||
|
inkscape:current-layer="layer1"
|
||||||
|
showgrid="false"
|
||||||
|
inkscape:window-width="1366"
|
||||||
|
inkscape:window-height="705"
|
||||||
|
inkscape:window-x="-8"
|
||||||
|
inkscape:window-y="-8"
|
||||||
|
inkscape:window-maximized="1" />
|
||||||
|
<metadata
|
||||||
|
id="metadata5">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title></dc:title>
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<g
|
||||||
|
inkscape:label="Layer 1"
|
||||||
|
inkscape:groupmode="layer"
|
||||||
|
id="layer1"
|
||||||
|
transform="translate(0,-246)">
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="M 11.211967,266.92368 H 1.2119672"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="path4502" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 23.042094,256.43333 -5,-8.66027"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="path4504" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 38.042094,261.43332 5,-8.66027"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="path4506" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 41.211967,276.92369 h 10"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="path4508" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 21.211967,276.92369 h 10"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="path4510" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 29.38184,287.41408 5,8.66026"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="path4512" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 14.38184,282.41409 -4.9999998,8.66023"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="path4514" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 1.2119672,266.92368 v 10.00001"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="path4516" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 18.042094,247.77306 -8.6602538,4.99999"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="path4518" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="M 43.042094,252.77305 34.38184,247.77306"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="path4520" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="M 51.211967,276.92369 V 266.92368"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="path4522" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="M 31.211967,276.92369 V 266.92368"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="path4524" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 34.38184,296.07434 8.660254,-5.00002"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="path4526" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 9.3818402,291.07432 8.6602538,5.00002"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="path4528" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 9.3818402,252.77305 4.9999998,8.66027"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="path4530" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 34.38184,247.77306 -5,8.66027"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="path4532" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 51.211967,266.92368 h -10"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="path4534" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 31.211967,266.92368 h -10"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="path4536" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 43.042094,291.07432 -5,-8.66023"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="path4538" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 18.042094,296.07434 5,-8.66026"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="path4540" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="M 1.2119672,276.92369 H 11.211967"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="path4542" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 14.38184,261.43332 8.660254,-4.99999"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="path4544" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 29.38184,256.43333 8.660254,4.99999"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="path4546" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 41.211967,266.92368 v 10.00001"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="path4548" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 21.211967,266.92368 v 10.00001"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="path4550" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="m 38.042094,282.41409 -8.660254,4.99999"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="path4552" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="M 23.042094,287.41408 14.38184,282.41409"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="path4554" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
d="M 11.211967,276.92369 V 266.92368"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none"
|
||||||
|
id="path4556" />
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 9.1 KiB |
17
lang/SimpleExpressions.json
Normal file
17
lang/SimpleExpressions.json
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"langs":
|
||||||
|
{
|
||||||
|
"en-GB":
|
||||||
|
{
|
||||||
|
"keys":
|
||||||
|
{
|
||||||
|
"LANG_CATEGORY_SOUND": "Sound",
|
||||||
|
"LANG_SUBCATEGORY_BUZZER": "Buzzer",
|
||||||
|
"LANG_PIEZO_BUZZER": "Buzzer",
|
||||||
|
"LANG_PIEZO_BUZZER_PIN": "PIN",
|
||||||
|
"LANG_SIMPLEEXPRESSIONS_SHOW_MOUTH": "7-RGB LEDs",
|
||||||
|
"LANG_PIEZO_BUZZER_PREDEF_SOUNDS_TOOLTIP": "Plays some basic sounds based on SimpleExpressions library"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
name=SimpleExpressions
|
name=SimpleExpressions
|
||||||
version=1.0.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
|
||||||
@ -7,3 +7,4 @@ paragraph=A simple library to create cool mouths and funny sounds using a 7 led
|
|||||||
category=Signal Input/Output
|
category=Signal Input/Output
|
||||||
url=https://github.com/s00500/SimpleExpressions
|
url=https://github.com/s00500/SimpleExpressions
|
||||||
architectures=*
|
architectures=*
|
||||||
|
depends=Adafruit NeoPixel
|
||||||
|
@ -1,46 +1,127 @@
|
|||||||
|
Facilino.LANG_COLOUR_SCREEN = '#ACCE42';
|
||||||
|
Facilino.LANG_COLOUR_SCREEN_LEDSTRIP = '#8EAC32';
|
||||||
|
|
||||||
|
Facilino.hexToRgb = function(hex) {
|
||||||
|
// Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
|
||||||
|
var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
|
||||||
|
hex = hex.replace(shorthandRegex, function(m, r, g, b) {
|
||||||
|
return r + r + g + g + b + b;
|
||||||
|
});
|
||||||
|
|
||||||
|
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
||||||
|
return result ? {
|
||||||
|
r: parseInt(result[1], 16),
|
||||||
|
g: parseInt(result[2], 16),
|
||||||
|
b: parseInt(result[3], 16)
|
||||||
|
} : null;
|
||||||
|
};
|
||||||
|
|
||||||
Blockly.Blocks['show_mouth'] = {
|
Blockly.Blocks['show_mouth'] = {
|
||||||
category: 'SimpleExpressions',
|
category: Facilino.locales.getKey('LANG_CATEGORY_SCREEN'),
|
||||||
colour: '#fbb117',
|
subcategory: Facilino.locales.getKey('LANG_SUBCATERGORY_WS2812'),
|
||||||
|
category_colour: Facilino.LANG_COLOUR_SCREEN,
|
||||||
|
colour: Facilino.LANG_COLOUR_SCREEN_LEDSTRIP,
|
||||||
helpUrl: Facilino.getHelpUrl('show_mouth'),
|
helpUrl: Facilino.getHelpUrl('show_mouth'),
|
||||||
tags: [],
|
tags: [],
|
||||||
examples: [],
|
examples: [],
|
||||||
init: function() {
|
init: function() {
|
||||||
this.appendDummyInput()
|
this.appendDummyInput('').appendField("WS2812 7-Ring").appendField(new Blockly.FieldImage('img/blocks/led_strip.svg', 40 * options.zoom, 40 * options.zoom));
|
||||||
.appendField("showMouth");
|
this.appendValueInput('PIN').appendField(Facilino.locales.getKey('LANG_SIMPLEEXPRESSIONS_PIN')).setAlign(Blockly.ALIGN_RIGHT).setCheck(Number);
|
||||||
this.appendValueInput("Color")
|
this.appendDummyInput('').appendField('Expression').appendField(new Blockly.FieldDropdown([
|
||||||
.setCheck(null)
|
['Zeros', 'zeros'],
|
||||||
.appendField("Color");
|
['Happy Small', 'happySmall'],
|
||||||
this.setColour("#fbb117");
|
['Happy Full', 'happyFull'],
|
||||||
|
['Sad Small', 'sadSmall'],
|
||||||
|
['Sad Full', 'sadFull'],
|
||||||
|
['Neutral', 'neutral'],
|
||||||
|
['Circle', 'circle'],
|
||||||
|
['Center', 'center'],
|
||||||
|
['Hook', 'hook'],
|
||||||
|
['Upsidedown Hook', 'upsidedownhook'],
|
||||||
|
['Kooh', 'kooh'],
|
||||||
|
['Upsidedown Kooh', 'upsidedownkooh'],
|
||||||
|
['Cross', 'cross'],
|
||||||
|
['Rect', 'rect'],
|
||||||
|
['Left Arrow', 'leftarrow'],
|
||||||
|
['Right Arrow', 'rightarrow'],
|
||||||
|
['Left Half', 'lefthalf'],
|
||||||
|
['Right Half', 'righthalf']
|
||||||
|
]), 'EXPRESSION').setAlign(Blockly.ALIGN_RIGHT);
|
||||||
|
var colour = new Blockly.FieldColour('#000000');
|
||||||
|
colour.setColours(['#000000', '#808080', '#C0C0C0', '#FFFFFF', '#800000', '#FF0000', '#808000', '#FFFF00', '#008000', '#00FF00', '#008080', '#00FFFF', '#000080', '#0000FF', '#800080', '#FF00FF']).setColumns(4);
|
||||||
|
this.appendDummyInput('').appendField('Color').appendField(colour, 'COLOR').setAlign(Blockly.ALIGN_RIGHT);
|
||||||
|
this.setPreviousStatement(true, 'code');
|
||||||
|
this.setNextStatement(true, 'code');
|
||||||
|
this.setColour(Facilino.LANG_COLOUR_SCREEN_LEDSTRIP);
|
||||||
this.setTooltip("");
|
this.setTooltip("");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
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_expression = this.getFieldValue('EXPRESSION');
|
||||||
var code='SimpleExpressions.showMouth("'+'mouth_name'+'", ' + color + ')' ;
|
var input_color = this.getFieldValue('COLOR');
|
||||||
code+= '\n';
|
var input_pin = Blockly.Arduino.valueToCode(this, 'PIN', Blockly.Arduino.ORDER_ATOMIC) || '';
|
||||||
|
Blockly.Arduino.definitions_['define_simpleexpressions_h'] = '#include <SimpleExpressions.h>';
|
||||||
|
Blockly.Arduino.setups_['setup_simpleexpressions_mouth'] = 'SimpleExpressions.initMouth(' + input_pin + ');\n';
|
||||||
|
var color_rgb = Facilino.hexToRgb(input_color);
|
||||||
|
var code = 'SimpleExpressions.writeMouth("' + input_expression + '",' + color_rgb.r + ',' + color_rgb.g + ',' + color_rgb.b + ');\n';
|
||||||
|
code += '\n';
|
||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
|
|
||||||
Blockly.Blocks['play_sound'] = {
|
Blockly.Arduino.dyor_piezo_buzzer_predef_sounds = function() {
|
||||||
category: 'SimpleExpressions',
|
var dropdown_pin = Blockly.Arduino.valueToCode(this, 'PIN', Blockly.Arduino.ORDER_ATOMIC) || '';
|
||||||
colour: '#fbb117',
|
var code = '';
|
||||||
helpUrl: Facilino.getHelpUrl('play_sound'),
|
Blockly.Arduino.definitions_['define_simpleexpressions_h'] = '#include <SimpleExpressions.h>';
|
||||||
tags: [],
|
Blockly.Arduino.setups_['setup_simpleexpressions_buzzer'] = 'SimpleExpressions.initBuzzer(' + dropdown_pin + ');\n';
|
||||||
examples: [],
|
code = 'SimpleExpressions.playSound(' + this.getFieldValue('OPTION') + ');\n';
|
||||||
|
return code;
|
||||||
|
};
|
||||||
|
|
||||||
|
Blockly.Blocks.dyor_piezo_buzzer_predef_sounds = {
|
||||||
|
category: Facilino.locales.getKey('LANG_CATEGORY_SOUND'),
|
||||||
|
subcategory: Facilino.locales.getKey('LANG_SUBCATEGORY_BUZZER'),
|
||||||
|
tags: ['buzzer', 'sound'],
|
||||||
|
helpUrl: Facilino.getHelpUrl('dyor_piezo_buzzer_predef_sounds'),
|
||||||
|
examples: [''],
|
||||||
|
category_colour: Facilino.LANG_COLOUR_SOUND,
|
||||||
|
colour: Facilino.LANG_COLOUR_SOUND_BUZZER,
|
||||||
|
//dyor_piezo_buzzer initialization
|
||||||
init: function() {
|
init: function() {
|
||||||
this.appendDummyInput()
|
this.setColour(Facilino.LANG_COLOUR_SOUND_BUZZER);
|
||||||
.appendField("play Sound");
|
this.appendDummyInput('')
|
||||||
this.setColour("#fbb117");
|
.appendField(Facilino.locales.getKey('LANG_PIEZO_BUZZER'))
|
||||||
this.setTooltip("");
|
.appendField(new Blockly.FieldImage('img/blocks/buzzer.svg', 52 * options.zoom, 35 * options.zoom));
|
||||||
|
this.appendValueInput('PIN')
|
||||||
|
.appendField(Facilino.locales.getKey('LANG_PIEZO_BUZZER_PIN')).appendField(new Blockly.FieldImage("img/blocks/pwm_signal.svg", 24 * options.zoom, 24 * options.zoom))
|
||||||
|
.setCheck(Number)
|
||||||
|
.setAlign(Blockly.ALIGN_RIGHT);
|
||||||
|
this.appendDummyInput('').appendField(new Blockly.FieldImage('img/blocks/speaker.svg', 24 * options.zoom, 24 * options.zoom))
|
||||||
|
.appendField(new Blockly.FieldDropdown([
|
||||||
|
['CONNECTION', '0'],
|
||||||
|
['DISCONNECTION', '1'],
|
||||||
|
['BUTTON PUSHED', '2'],
|
||||||
|
['MODE 1', '3'],
|
||||||
|
['MODE 2', '4'],
|
||||||
|
['MODE 3', '5'],
|
||||||
|
['SURPRISE', '6'],
|
||||||
|
['OHOOH', '7'],
|
||||||
|
['OHOOH2', '8'],
|
||||||
|
['CUDDLY', '9'],
|
||||||
|
['SLEEPING', '10'],
|
||||||
|
['HAPPY', '11'],
|
||||||
|
['SUPER_HAPPY', '12'],
|
||||||
|
['HAPPY_SHORT', '13'],
|
||||||
|
['SAD', '14'],
|
||||||
|
['CONFUSED', '15'],
|
||||||
|
['FART1', '16'],
|
||||||
|
['FART2', '17'],
|
||||||
|
['FART3', '18'],
|
||||||
|
['PIRATES', '19']
|
||||||
|
]), 'OPTION').setAlign(Blockly.ALIGN_RIGHT);
|
||||||
|
this.setInputsInline(false);
|
||||||
|
this.setPreviousStatement(true, 'code');
|
||||||
|
this.setNextStatement(true, 'code');
|
||||||
|
this.setTooltip(Facilino.locales.getKey('LANG_PIEZO_BUZZER_PREDEF_SOUNDS_TOOLTIP'));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Blockly.Arduino['play_sound'] = function(block) {
|
|
||||||
var input_color = Blockly.Arduino.valueToCode(block, 'Color', Blockly.Arduino.ORDER_ATOMIC);
|
|
||||||
var code='';
|
|
||||||
code+= '\n';
|
|
||||||
return code;
|
|
||||||
};
|
|
||||||
|
295
src/SimpleExpressions.cpp
Executable file
295
src/SimpleExpressions.cpp
Executable file
@ -0,0 +1,295 @@
|
|||||||
|
#include "Arduino.h"
|
||||||
|
#include "SimpleExpressions.h"
|
||||||
|
|
||||||
|
#define ledc_channel 5
|
||||||
|
|
||||||
|
void SimpleExpressionsClass::init(int aMouthPin, int aBuzzerPin) {
|
||||||
|
initMouth(aMouthPin);
|
||||||
|
initBuzzer(aBuzzerPin);
|
||||||
|
clearMouth();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SimpleExpressionsClass::initMouth(int aMouthPin) {
|
||||||
|
mouth = Adafruit_NeoPixel(7, aMouthPin, NEO_GRB + NEO_KHZ800);
|
||||||
|
mouth.begin();
|
||||||
|
clearMouth();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimpleExpressionsClass::initBuzzer(int aBuzzerPin) {
|
||||||
|
buzzerPin = aBuzzerPin;
|
||||||
|
|
||||||
|
#if defined(ESP32)
|
||||||
|
ledcSetup(ledc_channel, 2000, 8); // channel, max frequency, resolution
|
||||||
|
ledcAttachPin(aBuzzerPin, ledc_channel);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////
|
||||||
|
//-- MOUTHS ----------------------------------------//
|
||||||
|
///////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void SimpleExpressionsClass::writeMouth(const char mouthName[], int r, int g, int b) {
|
||||||
|
int number = -1;
|
||||||
|
for(int i = 0; i < frameCount; i++) {
|
||||||
|
if(strncmp(shapes[i].name, mouthName, 20) == 0) {
|
||||||
|
number = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(number != -1) {
|
||||||
|
printMouth(number, r, g, b);
|
||||||
|
} else {
|
||||||
|
if(debug) Serial.println("Error: mouth name does not exist");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimpleExpressionsClass::printMouth(int number, int r, int g, int b) {
|
||||||
|
for(uint16_t i = 0; i<7; i++) {
|
||||||
|
if(shapes[number].data[i]) mouth.setPixelColor(i, mouth.Color(r, g, b));
|
||||||
|
else mouth.setPixelColor(i, 0);
|
||||||
|
}
|
||||||
|
showMouth();
|
||||||
|
delay(1);
|
||||||
|
clearPixels();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimpleExpressionsClass::writeMouth(const 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]));
|
||||||
|
}
|
||||||
|
showMouth();
|
||||||
|
delay(1);
|
||||||
|
clearPixels();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
showMouth();
|
||||||
|
delay(1);
|
||||||
|
clearPixels();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimpleExpressionsClass::writeMouthGeneric(const int mouthArray[7][3]) {
|
||||||
|
for(uint16_t i=0; i<7; i++) {
|
||||||
|
mouth.setPixelColor(i, mouth.Color(mouthArray[i][0], mouthArray[i][1], mouthArray[i][2]));
|
||||||
|
}
|
||||||
|
showMouth();
|
||||||
|
delay(1);
|
||||||
|
clearPixels();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SimpleExpressionsClass::clearMouth() {
|
||||||
|
for(int i = 0; i < 7; i++) {
|
||||||
|
mouth.setPixelColor(i, 0);
|
||||||
|
}
|
||||||
|
showMouth();
|
||||||
|
delay(1);
|
||||||
|
clearPixels();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SimpleExpressionsClass::clearPixels() { // avoid strange issues on ESP32 with ledc
|
||||||
|
for(int i = 0; i < 7; i++) {
|
||||||
|
mouth.setPixelColor(i, 0);
|
||||||
|
}
|
||||||
|
delay(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimpleExpressionsClass::showMouth() {
|
||||||
|
#if defined(ESP32)
|
||||||
|
portDISABLE_INTERRUPTS();
|
||||||
|
mouth.show();
|
||||||
|
delay(1);
|
||||||
|
portENABLE_INTERRUPTS();
|
||||||
|
clearPixels();
|
||||||
|
#else
|
||||||
|
mouth.show();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////
|
||||||
|
//-- SOUNDS -----------------------------------------------------//
|
||||||
|
///////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
void SimpleExpressionsClass::_tone (float noteFrequency, long noteDuration, int silentDuration){
|
||||||
|
if(silentDuration==0) {silentDuration=1;}
|
||||||
|
|
||||||
|
#if defined(ESP32)
|
||||||
|
ledcWriteTone(ledc_channel, noteFrequency);
|
||||||
|
delay(noteDuration); // milliseconds
|
||||||
|
ledcWrite(ledc_channel, 0); // notone
|
||||||
|
#else
|
||||||
|
tone(buzzerPin, noteFrequency, noteDuration);
|
||||||
|
delay(noteDuration); // milliseconds
|
||||||
|
#endif
|
||||||
|
|
||||||
|
delay(silentDuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SimpleExpressionsClass::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 SimpleExpressionsClass::playSound(int soundName){
|
||||||
|
switch(soundName) {
|
||||||
|
|
||||||
|
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_BUTTON_PUSHED:
|
||||||
|
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_SUPER_HAPPY:
|
||||||
|
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;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SimpleExpressionsClass SimpleExpressions;
|
49
src/SimpleExpressions.h
Executable file
49
src/SimpleExpressions.h
Executable file
@ -0,0 +1,49 @@
|
|||||||
|
#ifndef SimpleExpressions_h
|
||||||
|
#define SimpleExpressions_h
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
#ifdef __AVR__
|
||||||
|
#include <avr/power.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "Shapes.h"
|
||||||
|
#include "Sounds.h"
|
||||||
|
|
||||||
|
#define debug true
|
||||||
|
|
||||||
|
|
||||||
|
class SimpleExpressionsClass
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// General
|
||||||
|
void init(int mouthPin, int buzzerPin);
|
||||||
|
void initMouth(int mouthPin);
|
||||||
|
void initBuzzer(int buzzerPin);
|
||||||
|
|
||||||
|
// Mouths
|
||||||
|
void printMouth(int number, int r, int g, int b);
|
||||||
|
void writeMouth(const char mouthName[], int r, int g, int b);
|
||||||
|
|
||||||
|
void printMouth(int number);
|
||||||
|
void writeMouth(const char mouthName[]);
|
||||||
|
|
||||||
|
void clearMouth();
|
||||||
|
void showMouth();
|
||||||
|
|
||||||
|
void writeMouthGeneric(const int mouthArray[7][3]);
|
||||||
|
void writeMouthGeneric(const bool mouthArray[7], int r, int g, int b);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
Adafruit_NeoPixel mouth;
|
||||||
|
void clearPixels();
|
||||||
|
int buzzerPin;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern SimpleExpressionsClass SimpleExpressions;
|
||||||
|
|
||||||
|
#endif
|
@ -134,7 +134,7 @@
|
|||||||
|
|
||||||
const int songspeed = 1;
|
const int songspeed = 1;
|
||||||
|
|
||||||
const PROGMEM int notes[] = { //Note of the song, 0 is a rest/pulse
|
const PROGMEM double notes[] = { //Note of the song, 0 is a rest/pulse
|
||||||
NOTE_E4, NOTE_G4, NOTE_A4, NOTE_A4, 0,
|
NOTE_E4, NOTE_G4, NOTE_A4, NOTE_A4, 0,
|
||||||
NOTE_A4, NOTE_B4, NOTE_C5, NOTE_C5, 0,
|
NOTE_A4, NOTE_B4, NOTE_C5, NOTE_C5, 0,
|
||||||
NOTE_C5, NOTE_D5, NOTE_B4, NOTE_B4, 0,
|
NOTE_C5, NOTE_D5, NOTE_B4, NOTE_B4, 0,
|
Loading…
Reference in New Issue
Block a user