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:
parent
1bb01d6dd2
commit
2c4b9eef03
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user