mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
analogWrite is not implemented on the ESP32
See: https://github.com/espressif/arduino-esp32/issues/4
This commit is contained in:
parent
cf1b69513f
commit
bfac192732
1 changed files with 66 additions and 50 deletions
|
@ -22,6 +22,10 @@ uint8_t b, b1;
|
|||
#define LED1_RED 3
|
||||
#define BUTTON1 2
|
||||
|
||||
#ifdef ESP32
|
||||
#define LED1_RED_CHANNEL 0
|
||||
#endif
|
||||
|
||||
void init_buttons()
|
||||
{
|
||||
pinMode(BUTTON1, INPUT);
|
||||
|
@ -34,7 +38,12 @@ void init_leds()
|
|||
{
|
||||
digitalWrite(LED1_RED, 0);
|
||||
|
||||
#ifdef ESP32
|
||||
ledcAttachPin(LED1_RED, LED1_RED_CHANNEL); // Assign LED pin to channel 0
|
||||
ledcSetup(LED1_RED_CHANNEL, 12000, 8); // 12 kHz PWM, 8-bit resolution
|
||||
#else
|
||||
pinMode(LED1_RED, OUTPUT);
|
||||
#endif
|
||||
}
|
||||
|
||||
void setup()
|
||||
|
@ -50,7 +59,6 @@ void setup()
|
|||
while (1); //halt
|
||||
}//if (Usb.Init() == -1...
|
||||
|
||||
|
||||
init_leds();
|
||||
init_buttons();
|
||||
b1 = digitalRead(BUTTON1);
|
||||
|
@ -63,7 +71,11 @@ void loop()
|
|||
Usb.Task();
|
||||
|
||||
if ( adk.isReady() == false ) {
|
||||
#ifdef ESP32
|
||||
ledcWrite(LED1_RED_CHANNEL, 255);
|
||||
#else
|
||||
analogWrite(LED1_RED, 255);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
uint16_t len = sizeof(msg);
|
||||
|
@ -78,7 +90,11 @@ void loop()
|
|||
if (msg[0] == 0x2) {
|
||||
switch ( msg[1] ) {
|
||||
case 0:
|
||||
#ifdef ESP32
|
||||
ledcWrite(LED1_RED_CHANNEL, 255 - msg[2]);
|
||||
#else
|
||||
analogWrite(LED1_RED, 255 - msg[2]);
|
||||
#endif
|
||||
break;
|
||||
}//switch( msg[1]...
|
||||
}//if (msg[0] == 0x2...
|
||||
|
|
Loading…
Reference in a new issue