1
0
mirror of https://github.com/s00500/SimpleExpressions synced 2024-11-22 04:20:54 +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 #define ledc_channel 5
void SimpleExpressionsClass::init(int mouthPin, int buzzerPin) { void SimpleExpressionsClass::init(int aMouthPin, int aBuzzerPin) {
mouth = Adafruit_NeoPixel(7, mouthPin, NEO_GRB + NEO_KHZ800); mouth = Adafruit_NeoPixel(7, aMouthPin, NEO_GRB + NEO_KHZ800);
mouth.begin(); mouth.begin();
ledcSetup(ledc_channel, 2000, 8); // channel, max frequency, resolution buzzerPin = aBuzzerPin;
ledcAttachPin(buzzerPin, ledc_channel);
#if defined(ESP32)
ledcSetup(ledc_channel, 2000, 8); // channel, max frequency, resolution
ledcAttachPin(aBuzzerPin, ledc_channel);
#endif
clearMouth(); clearMouth();
} }
@ -118,9 +123,15 @@ void SimpleExpressionsClass::clearPixels() { // avoid strange issues on ESP32 wi
void SimpleExpressionsClass::_tone (float noteFrequency, long noteDuration, int silentDuration){ void SimpleExpressionsClass::_tone (float noteFrequency, long noteDuration, int silentDuration){
if(silentDuration==0){silentDuration=1;} if(silentDuration==0){silentDuration=1;}
ledcWriteTone(ledc_channel, noteFrequency); #if defined(ESP32)
delay(noteDuration); // milliseconds ledcWriteTone(ledc_channel, noteFrequency);
ledcWrite(ledc_channel, 0); // notone delay(noteDuration); // milliseconds
ledcWrite(ledc_channel, 0); // notone
#else
tone(buzzerPin, noteFrequency, noteDuration);
delay(noteDuration); // milliseconds
#endif
delay(silentDuration); delay(silentDuration);
} }

View File

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