1
0
mirror of https://github.com/s00500/SimpleExpressions synced 2024-12-22 04:10:49 +00:00

Proper multi platform support

This commit is contained in:
Lukas Bachschwell 2017-11-27 12:35:38 +01:00
parent 1bb01d6dd2
commit 2c4b9eef03
2 changed files with 19 additions and 7 deletions

View File

@ -3,12 +3,17 @@
#define ledc_channel 5
void SimpleExpressionsClass::init(int mouthPin, int buzzerPin) {
mouth = Adafruit_NeoPixel(7, mouthPin, NEO_GRB + NEO_KHZ800);
void SimpleExpressionsClass::init(int aMouthPin, int aBuzzerPin) {
mouth = Adafruit_NeoPixel(7, aMouthPin, NEO_GRB + NEO_KHZ800);
mouth.begin();
ledcSetup(ledc_channel, 2000, 8); // channel, max frequency, resolution
ledcAttachPin(buzzerPin, ledc_channel);
buzzerPin = aBuzzerPin;
#if defined(ESP32)
ledcSetup(ledc_channel, 2000, 8); // channel, max frequency, resolution
ledcAttachPin(aBuzzerPin, ledc_channel);
#endif
clearMouth();
}
@ -118,9 +123,15 @@ void SimpleExpressionsClass::clearPixels() { // avoid strange issues on ESP32 wi
void SimpleExpressionsClass::_tone (float noteFrequency, long noteDuration, int silentDuration){
if(silentDuration==0){silentDuration=1;}
ledcWriteTone(ledc_channel, noteFrequency);
delay(noteDuration); // milliseconds
ledcWrite(ledc_channel, 0); // notone
#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);
}

View File

@ -43,6 +43,7 @@ class SimpleExpressionsClass
private:
Adafruit_NeoPixel mouth;
void clearPixels();
int buzzerPin;
};
extern SimpleExpressionsClass SimpleExpressions;