Skip to content

Commit 676ffab

Browse files
fixed pwm source conflict
1 parent 3a45c01 commit 676ffab

File tree

4 files changed

+43
-21
lines changed

4 files changed

+43
-21
lines changed

examples/Twin_CodeLab/Twin_CodeLab.ino

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Twin_CodeLab v2.4.2
2+
Twin_CodeLab v2.4.3
33
44
Bu yazılım Twin CodeLab Web (https://code.twinscience.com/) ya da mobil uygulamaları ile blok kodlama yapabilme imkanı sunan yazılımdır.
55
@@ -9,7 +9,7 @@
99
1010
https://github.com/twin-science-robotics/hw_twin_aiot_module_arduino_library
1111
12-
10 Eylül 2025
12+
24 Eylül 2025
1313
Twin Science & Robotics
1414
1515
*/
@@ -39,11 +39,11 @@ void setupTwin_F() {
3939

4040

4141

42-
pinMode(D6_motor_pin, OUTPUT); // D6
42+
pinMode(D6_output_pin, OUTPUT); // D6
4343

44-
pinMode(D9_motor_pin, OUTPUT); // D6
44+
pinMode(D9_output_pin, OUTPUT); // D6
4545

46-
pinMode(D10_motor_pin, OUTPUT); // D6
46+
pinMode(D10_output_pin, OUTPUT); // D6
4747

4848
pinMode(S1pin, OUTPUT);
4949
pinMode(S2pin, OUTPUT);

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Twin_AIoT
2-
version=1.0.6
2+
version=1.0.7
33
author=TwinScience
44
55
sentence=A library containing example codes for Twin AIoT module.

src/CommandHandler.cpp

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "esp32-hal-ledc.h"
12
#include "CommandHandler.h"
23

34
Servo servo6;
@@ -138,6 +139,10 @@ void CommandHandler::initTwin_F() {
138139
if (servo9.attached()) servo9.detach();
139140
if (servo10.attached()) servo10.detach();
140141

142+
ledcDetach(D6_output_pin);
143+
ledcDetach(D9_output_pin);
144+
ledcDetach(D10_output_pin);
145+
141146
if (dc_coding_at_pin_06_ptr)
142147
{
143148
delete dc_coding_at_pin_06_ptr;
@@ -249,14 +254,22 @@ void CommandHandler::digitalRead_F() {
249254

250255
void CommandHandler::analogWrite_F(){
251256
uint8_t pin = getActualPin(bleChannel.received.message_data[0], DIGITAL);
252-
pinMode(pin, OUTPUT);
253257
uint16_t value = bleChannel.received.message_data[1];
254258
//Serial.println(value);
255-
259+
int channel;
260+
256261
value = map(value,0,255,0,4095) + 1 ;
257262
if(value > 4095) value = 4095;
258263

259-
ledcAttach(pin, freq, resolution);
264+
switch(pin) {
265+
case D6_output_pin: channel = PWM_CHANNEL_1; break;
266+
case D9_output_pin: channel = PWM_CHANNEL_2; break;
267+
case D10_output_pin: channel = PWM_CHANNEL_3; break;
268+
}
269+
270+
pinMode(pin, OUTPUT);
271+
ledcDetach(pin);
272+
ledcAttachChannel(pin, freq, resolution, channel);
260273
ledcWrite(pin, value);
261274

262275
bleChannel.sent.message_length = 1;
@@ -300,10 +313,11 @@ void CommandHandler::playNote_F(){
300313
uint16_t note = bleChannel.received.message_data[1] + (bleChannel.received.message_data[2] << 8);
301314
uint16_t duration = bleChannel.received.message_data[3] + (bleChannel.received.message_data[4] << 8);
302315

303-
ledcAttach(pin,2700,8);
316+
ledcAttachChannel(pin,2700,8,TONE_CHANNEL);
304317
ledcWriteTone(pin, note);
305318
delay(duration);
306319
ledcWriteTone(pin, 0);
320+
ledcDetach(pin);
307321

308322
bleChannel.sent.message_length = 1;
309323
uint8_t response_data[1] = {1};
@@ -435,7 +449,7 @@ void CommandHandler::singleDC_F(){
435449
if (!dc_coding_at_pin_06_ptr)
436450
{
437451
delete dc_coding_at_pin_06_ptr;
438-
dc_coding_at_pin_06_ptr = new TwinDCMotor(1, D6_motor_pin);
452+
dc_coding_at_pin_06_ptr = new TwinDCMotor(1, D6_output_pin);
439453
}
440454
//Serial.println(motor_dir);
441455
//Serial.println(motor_speed);
@@ -449,7 +463,7 @@ void CommandHandler::singleDC_F(){
449463
if (!dc_coding_at_pin_09_ptr)
450464
{
451465
delete dc_coding_at_pin_09_ptr;
452-
dc_coding_at_pin_09_ptr = new TwinDCMotor(1, D9_motor_pin);
466+
dc_coding_at_pin_09_ptr = new TwinDCMotor(1, D9_output_pin);
453467
}
454468

455469
dc_coding_at_pin_09_ptr->setDirAndSpeedCoding(0, motor_dir, motor_speed);
@@ -460,7 +474,7 @@ void CommandHandler::singleDC_F(){
460474
if (!dc_coding_at_pin_0A_ptr)
461475
{
462476
delete dc_coding_at_pin_0A_ptr;
463-
dc_coding_at_pin_0A_ptr = new TwinDCMotor(1, D10_motor_pin);
477+
dc_coding_at_pin_0A_ptr = new TwinDCMotor(1, D10_output_pin);
464478
}
465479
//Serial.println(motor_dir);
466480
//Serial.println(motor_speed);
@@ -564,11 +578,11 @@ uint8_t CommandHandler::getActualPin(uint8_t logicalPin, bool signal_type) {
564578
switch (logicalPin) {
565579

566580
case 6:
567-
if(signal_type == DIGITAL) return D6_motor_pin;
581+
if(signal_type == DIGITAL) return D6_output_pin;
568582
else if(signal_type == ANALOG) return AN_IN_4;
569583

570-
case 9: return D9_motor_pin;
571-
case 10: return D10_motor_pin;
584+
case 9: return D9_output_pin;
585+
case 10: return D10_output_pin;
572586

573587
//input pins
574588
case 4: return D_IN_4;

src/Constants.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
extern CRGB leds[NUM_LEDS];
1515

16-
// Firmware version 2.4.1
16+
// Firmware version 2.4.2
1717
#define FIRMWARE_VERSION_MAJOR 2
1818
#define FIRMWARE_VERSION_MINOR 4
1919

@@ -27,9 +27,17 @@ extern CRGB leds[NUM_LEDS];
2727

2828
#define QUEUE_LENGTH 256
2929

30-
#define D6_motor_pin 35
31-
#define D9_motor_pin 36
32-
#define D10_motor_pin 10
30+
#define D6_output_pin 35
31+
#define D9_output_pin 36
32+
#define D10_output_pin 10
33+
34+
#define SERVO_CHANNEL_6 0
35+
#define SERVO_CHANNEL_9 1
36+
#define SERVO_CHANNEL_10 2
37+
#define TONE_CHANNEL 3
38+
#define PWM_CHANNEL_1 4
39+
#define PWM_CHANNEL_2 5
40+
#define PWM_CHANNEL_3 6
3341

3442
#define D_IN_4 8
3543
#define D_IN_8 11
@@ -64,7 +72,7 @@ const uint8_t packet_size = 20; // header_length + data_length
6472
const int freq = 490;
6573
const int resolution = 12;
6674

67-
const char outputpins[3] = {D6_motor_pin, D9_motor_pin, D10_motor_pin};
75+
const char outputpins[3] = {D6_output_pin, D9_output_pin, D10_output_pin};
6876

6977

7078
// Message IDs

0 commit comments

Comments
 (0)